in reply to Split Operation

I was going to suggest
my @array = eval '(' . $test . ')';
just for amusement, but it doesn't work. I think that I will probably never understand string eval properly.

Replies are listed 'Best First'.
Re^2: Split Operation
by falsedan (Initiate) on Aug 03, 2009 at 12:29 UTC
    This fails:
    my $test = "[a,b],c,'d',[e,[f,g,h,[i,j],k,l],m,n],o,p"; my @array = eval ( $test );
    This succeeds:
    my $test = "[a,b,],c,'d',[e,[f,g,h,[i,j,],k,l,],m,n,],o,p"; my @array = eval ( $test );
    Don't forget no strict 'subs'; or else all those unquoted single characters will be treated as barewords!
      The only difference that I can see is that the second code has (apparently spurious) commas at the end of every arrayref—is that correct? Why is it necessary?

      Of course you're right that what I wrote is far from strict-safe—thanks! Making it so would probably be harder than just giving the kind of solution the OP wanted, though. :-)

      use strict; my $test="[a,b],c,'d',[e,[f,g,h,[i,j],k,l],m,n],o,p"; $test =~ s/([a-zA-Z])/"$1"/g; my @array = eval ( $test );