Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Split Operation

by JadeNB (Chaplain)
on Aug 03, 2009 at 05:16 UTC ( [id://785343]=note: print w/replies, xml ) Need Help??


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 );

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://785343]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-23 21:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found