Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Is this normal

by JavaFan (Canon)
on Jan 06, 2012 at 15:20 UTC ( #946612=note: print w/replies, xml ) Need Help??


in reply to Is this normal

You're making two mistakes:
  1. You're calling the match in list context, so an empty list is returned, reducing the number of passed parameters.
  2. Even when called in scalar context, a non-match does not return 0. It returns the empty string (most Perl build-ins that return either a true or a false value, return 1 or "")

Replies are listed 'Best First'.
Re^2: Is this normal
by dave_the_m (Monsignor) on Jan 06, 2012 at 23:30 UTC
    a non-match does not return 0. It returns the empty string
    Strictly speaking, it returns PL_sv_no, which has both a numerical value of 0 and a string value of "":
    $ perl5140 -MDevel::Peek -e 'Dump scalar(/x/)' SV = PVNV(0x275ee10) at 0xa26500 REFCNT = 2147483647 FLAGS = (IOK,NOK,POK,READONLY,pIOK,pNOK,pPOK) IV = 0 NV = 0 PV = 0x275ee00 ""\0 CUR = 0 LEN = 16

    Dave.

      You are correct. However, the OP is printing out the values, so the string value will be taken.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2019-08-17 20:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If you were the first to set foot on the Moon, what would be your epigram?






    Results (134 votes). Check out past polls.

    Notices?