CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
Array Question

 



legobuff
Deleted

Sep 26, 2000, 10:49 PM

Post #1 of 2 (1056 views)
Array Question Can't Post

Is it possible to something like the following with an array (this doesnt work but should explain what I am trying to do... also the point here is I want a one line'er just like the scalar code posted after this ).

@numbers_to_skip = qw(0000001 0000003);
@r0 = ("00", "0000001");
@r1 = ("01", "0000002");
@r2 = ("02", "0000003");
@rows = (\@r0, \@r1, \@r2);

foreach $row (@rows) {
my ($iRowId, $sNumber) = @{$row}[0,1];
next if $sNumber in @numbers_to_skip;
print "USING NUMBER:\t" . $sNumber . "\n";
}

or am i stuck using a scalar like this?

$numbers_to_skip = "0000001 0000003";
@r0 = ("00", "0000001");
@r1 = ("01", "0000002");
@r2 = ("02", "0000003");
@rows = (\@r0, \@r1, \@r2);

foreach $row (@rows) {
my ($iRowId, $sNumber) = @{$row}[0,1];
next if $numbers_to_skip =~ $sNumber;
print "USING NUMBER:\t" . $sNumber . "\n";
}
?


japhy
Enthusiast / Moderator

Sep 27, 2000, 11:49 AM

Post #2 of 2 (1056 views)
Re: Array Question [In reply to] Can't Post

Any time you hear yourself saying "does a list contain an element" or "is this element in this list", you should be using a hash, not an array.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


my %skip_these;
@skip_these{qw( foo bar )} = ();
@values = qw( hello foo world hi bar earth );
for (@values) {
print unless exists $skip_these{$_};
}
</pre><HR></BLOCKQUOTE>

------------------
Jeff "japhy" Pinyan -- accomplished author, consultant, hacker, and teacher


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives