in reply to Re: Idiomatic Split to Scalar Conversion
in thread Idiomatic Split to Scalar Conversion
> # But why doesn't this work? > my $foo = () = split /,/, $bar;
Because split is DWIM-happy (or DWYTIM -- Do What You Think I Mean), and it's told the length of the array it is assigning into so it can stop looking after it fills your array.
my $foo = () = split(/,/, $bar, -1) almost works, but it doesn't strip trailing undefs like it would in list context without the third param (try it with "a,b,,").
If you don't mind wiping out @_, then just be explicit about it:
my $foo = @_ = split /,/, $bar
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Idiomatic Split to Scalar Conversion
by particle (Vicar) on Apr 30, 2002 at 04:29 UTC |