Re: Binding array to pattern



In <4erq9dF1ge4orU1@xxxxxxxxxxxxxx>, on 06/09/2006
at 01:30 AM, Gunnar Hjalmarsson <noreply@xxxxxxxxx> said:

Shmuel (Seymour J.) Metz wrote:
I'd like to bind an array to a pattern.

Why?

I want to test for a match anywhere in the array.

This is more readable IMO:
foreach my $element ( @anarray ) {
while ( $element =~ /PATTERN/g ) {
...
}
}

I had simplified my code because I was primarily concerned with the
endless loop rather than style. What I actually wound up with[1] was

foreach (sort keys %{$host_info{$host}{Email}}) {
push @Contacts, @{$host_info{$host}{Email}{$_}};
my $scalarContacts="@{$host_info{$host}{Email}{$_}}";
push @abuseContacts, @{$host_info{$host}{Email}{$_}}
if (/abuse/ or $scalarContacts =~ /abuse/);
}

and I'd rather avoid replicating the push statement. Given that, is
there a better style?

Thanks.

[1] The code is quck and dirty and at some point I intend to
do some massive cleanup, but it's still a work in progress.

--
Shmuel (Seymour J.) Metz, SysProg and JOAT <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action. I reserve the
right to publicly post or ridicule any abusive E-mail. Reply to
domain Patriot dot net user shmuel+news to contact me. Do not
reply to spamtrap@xxxxxxxxxxxxxxxxxx

.



Relevant Pages

  • Re: Picking Element from Array one by one
    ... >> I am getting some values from loop and i store all that value in array ... >> using push function. ... no correllation. ... Please Rita, get it together woman. ...
    (comp.lang.perl.misc)
  • Re: The prodigal son returns...more easy Homework Help...
    ... Looking at your output, you're obviously "running off the end" of the "lower" array, and printing one number from the "higher" array. ... to push and pop 16 bit values as long as the stack remain aligned ... There may be other places where you want to change from 16-bit registers to 32-bit registers, ... It "sounds logical" that 16-bit calculations would be faster and "easier for the CPU". ...
    (alt.lang.asm)
  • Please help with convoluted script
    ... I have a script which is supposed to query a database and compile data for every ... push @months, $month; ... # Build the array which will hold the dates for the previous week ... # so we can output the proper string later. ...
    (perl.beginners)
  • Re: Address of a specific element: an Array containing Array References ...
    ... the push creates another copy. ... array *ELEMENT* instead. ... wouldn't automatically dereference. ... by pushing aliases rather than references. ...
    (comp.lang.perl.misc)
  • Re: Autovivification by foreach
    ... FS> push @a,$_ for @$ref; ... there is no exception anymore. ... Perl creates the array on the fly. ...
    (comp.lang.perl.misc)

Loading