Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

•Re: no grep match returns undefined?

by merlyn (Sage)
on Sep 05, 2002 at 17:04 UTC ( [id://195445]=note: print w/replies, xml ) Need Help??


in reply to no grep match returns undefined?

When grep can't find anything, it returns an empty list in a list context, or 0 in a scalar context. Since the next operation is a list slice, the list slice is providing list context to grep, and thus gets an empty list. You're then taking the 0'th element of an empty list, which is defined to be undef, because whenever you access "beyond the end of the array", you get undef. This is not a "special case" for grep.

Really, it's a matter of understanding each step, and is desk-checkable before running. Don't throw code together. Build it.

-- Randal L. Schwartz, Perl hacker

  • Comment on •Re: no grep match returns undefined?

Log In?
Username:
Password:

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

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

    No recent polls found