Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: error message in the end of the array looping?

by ioannis (Prior)
on May 31, 2006 at 09:19 UTC ( #552728=note: print w/replies, xml ) Need Help??


in reply to error message in the end of the array looping?

Use the first() function from List:Util .

print +(first { $_ eq 'correct_value' } @arr) || 'not found';

  • Comment on Re: error message in the end of the array looping?

Replies are listed 'Best First'.
Re^2: error message in the end of the array looping?
by dank (Initiate) on Jun 01, 2006 at 07:02 UTC

    Alternatively, if you can get your hands on it, List::MoreUtils has a bunch of small, but useful subroutines.
    -----------------------------

    use List::MoreUtils qw(any); ... print "Success" if any { $_ eq "correct_value" } @hash{@array};

    -----------------------------
    Notes:
    1 - note the use of a hash slice; it takes some getting used to, having a @ instead of a % in front.
    2 - please use something more meaningful than %hash or @array as var names in your actual code :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://552728]
help
Chatterbox?
[MidLifeXis]: And it also has the 0.14 version of the tarball in its manifest.
[LanX]: avoiding unreadable brackets
[MidLifeXis]: Although the previous one could be a b0rken PATH, I would need to dig for that.
[thezip]: I've got to go to meetings now. If anyone has further comments regarding Spreadsheet::XLSX deployment to Strawberry Perl 5.24.1, please /msg me -- thanks!
LanX has to go ... plans to crash with a car into a group of pythonistas while screaming "LARRY IS THE GREATEST"
LanX ... darn ... where is my car?
[choroba]: Haven't you crashed into a boar recently?

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2017-03-23 17:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (291 votes). Check out past polls.