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

Re: no grep match returns undefined?

by kvale (Monsignor)
on Sep 05, 2002 at 16:18 UTC ( [id://195428]=note: print w/replies, xml ) Need Help??


in reply to no grep match returns undefined?

grep returns an array of matched elements. So if there are no matches, then the first array element is undefined. A better way would be
my @vndr_keys = grep { $args->{desc} =~ m/$_/i } keys %vendors; if (@vndr_keys) { #do something } else { #do something else }
-Mark

Replies are listed 'Best First'.
Re: Re: no grep match returns undefined?
by davorg (Chancellor) on Sep 05, 2002 at 16:22 UTC
    grep returns an array of matched elements

    Actually it returns a list of matched elements.

    The difference can be important.

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-03-28 18:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found