Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Compare all array values without a loop

by radiantmatrix (Parson)
on Oct 19, 2004 at 14:35 UTC ( [id://400546]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    $foobar='D';
    $sep = chr(1);
    ...
    if (($sep.join($sep,@array).$sep) =~ m/$sep$foobar$sep/) {
       print "Found a $foobar in \@array!";
    }
    
  2. or download this
    $foobar='D';
    %hash = ( 'A' => undef, 'B' => undef, 'C' => undef, 'D' => undef );
    print "Found a $foobar in \%hash" if exists $hash{$foobar};
    
  3. or download this
    @array = ('A','B','C','D');
    for (@array) {
    ...
    if (exists $hash{$foo}) {
       print "There was a $foo in the array\n";
    }
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://400546]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-19 23:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found