Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re^2: split and uninitialized variables

by antirice (Priest)
on Sep 03, 2004 at 15:33 UTC ( #388312=note: print w/ replies, xml ) Need Help??

in reply to Re: split and uninitialized variables
in thread split and uninitialized variables

Both methods have problems:

> perl -wl my ($x,$y,$z) = ('','',''); ($x,$y,$z) = split(',','a,b'); print "$x $y $z"; __END__ Use of uninitialized value in concatenation (.) or string at - line 3. a b > perl -wl my ($x, $y, $z) = map { $_ || '' } split(',', 'a,0,b'); print "$x $y $z"; __END__ a b

The second one is easily fixed with:

perl -wl my ($x, $y, $z) = map defined $_ ? $_ : '', (split(',', 'a,0,b'))[0..2 +]; print "$x $y $z"; __END__ a 0 b

Update: Doh! Thanks !1 (silly lurker).

The first rule of Perl club is - use Perl
ith rule of Perl club is - follow rule i - 1 for i > 1

Comment on Re^2: split and uninitialized variables
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2015-11-27 14:34 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (729 votes), past polls