Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://388312]
[james28909]: how can i write a while loop on one line (in a script) something like print "this\n" && print "that" && <DATA> && print the other\n" && next if /this matches/ while <DATA>?
[james28909]: i have tried with && and and and have tried to rearrange the functions as well to no avail
[shmem]: use parens to group expressions
[shmem]: you can't use next in a statement modifier
[shmem]: next requires a BLOCK

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2018-05-20 18:42 GMT
Find Nodes?
    Voting Booth?