note
antirice
<p>Both methods have problems:</p>
<code>
> 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
</code>
<p>The second one is easily fixed with:</p>
<code>
perl -wl
my ($x, $y, $z) = map defined $_ ? $_ : '', (split(',', 'a,0,b'))[0..2];
print "$x $y $z";
__END__
a 0 b
</code>
<p>Update: Doh! Thanks [!1] (silly lurker).</p>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-227499">
<p align="right">[antirice] <br><i>The first rule of Perl club is - use Perl<br>The </i>i<i>th rule of Perl club is - follow rule </i>i<i> - 1 for </i>i<i> > 1</i></p>
</div></div>
388295
388301