Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: undef vs empty string '' from split

by chrism01 (Friar)
on Jun 21, 2007 at 01:18 UTC ( #622438=note: print w/ replies, xml ) Need Help??


in reply to Re: undef vs empty string '' from split
in thread undef vs empty string '' from split

I haven't tried your more exotic version, but if you remove the limit cnt from my simple code, you still get the empty string...
Actually, that's the first thing I tried after it didn't 'work', given that my data only has var=val (if there is a val to get)


Comment on Re^2: undef vs empty string '' from split
Replies are listed 'Best First'.
Re^3: undef vs empty string '' from split
by Joost (Canon) on Jun 21, 2007 at 01:39 UTC
    Hmm.. You mean like this:
    #!perl -w use strict; $_ = 'event_handler='; my ($var1, $var2) = split( /=/); if( !defined($var2) ) { print "undefined\n"; } else { print "'$var1' '$var2'\n"; }
    output:
    'event_handler' ''
    that does seem to be inconsistent with the docs. And what's even more confusing is that:

    #!perl -w use strict; $_ = 'event_handler='; my @arr = split(/=/); my ($var1, $var2) = @arr; if( !defined($var2) ) { print "undefined\n"; } else { print "'$var1' '$var2'\n"; }
    output:
    undefined
    Confirms the docs.

    updated: added output for perl 5.8.8 / linux

      split says:

      When assigning to a list, if LIMIT is omitted, or zero, Perl supplies a LIMIT one larger than the number of variables in the list,

      So while @arr = split gets a LIMIT of 0 (and stripping of trailing null fields), ($x, $y) = split gets a LIMIT of 3 (and no such stripping).

      Another special case — potentially (as you, um, realized) surprising — but at least documented.

      print "Just another Perl ${\(trickster and hacker)},"
      The Sidhekin proves Sidhe did it!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (15)
As of 2015-07-28 17:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (258 votes), past polls