in reply to Implicit split to @_

If you want to do it like that for whatever reason you may have (rather than using length as others have suggested) you will need to use a temporary array:

my $sa = do { my @tmp = split //, $vartable{$a} };
The do block is there just to reduce the scope of the temporary array - you can do away with it if you want to predeclare the array.

Of course I would recommend that you do this with length

/J\

Replies are listed 'Best First'.
Re^2: Implicit split to @_
by ysth (Canon) on Apr 14, 2005 at 22:30 UTC
    my $sa = () = split //, $vartable{$a}, -1 also does the trick. (Update: added necessary -1.)

      Er are you sure:

      perl -e 'my $sa = () = split //,"foo"; print $sa'
      vs
      perl -e 'my $sa = do {my @tmp = split //,"foo"}; print $sa'
      split() is outwitting us here - it sees the empty list and optimizes accordingly.

      /J\

        perl -e 'my $sa = () = split //,"foo",-1; print $sa'