in reply to split and uninitialized variables
ORmy ($x, $y, $z) = ('', '', ''); ($x, $y, $z) = split(',', $_);
to ensure the variables are initialised.my ($x, $y, $z) = map { $_ || '' } split(',', $_);
Update: Oops! I really need a new brain.
use strict; use warnings; $_ = "a,0,b"; my ($x, $y, $z) = split(',', $_); foreach ($x, $y, $z) { $_ = '' unless defined($_) } print "x = $x\ny = $y\nz = $z\n"; __END__ x = a y = 0 z = b
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: split and uninitialized variables
by ikegami (Patriarch) on Sep 03, 2004 at 15:31 UTC | |
by Roy Johnson (Monsignor) on Sep 03, 2004 at 16:09 UTC | |
Re^2: split and uninitialized variables
by Fletch (Bishop) on Sep 03, 2004 at 15:33 UTC | |
Re^2: split and uninitialized variables
by antirice (Priest) on Sep 03, 2004 at 15:33 UTC |
In Section
Seekers of Perl Wisdom