Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: better way to convert a string into an array and an hash

by ambrus (Abbot)
on Oct 05, 2004 at 17:14 UTC ( [id://396675]=note: print w/replies, xml ) Need Help??


in reply to better way to convert a string into an array and an hash

My guess is:

my $string = "1:1,2:1,3:2,500:2,505:1"; my %hash = $string=~/([-.\w]*):([-.\w]*),/g; my @array = $string=~/([-.\w]*):/g; use Data::Dumper; print Dumper \@array, \%hash;

Update: that's wrong of course. Here's the corrected one:

my $string = "1:1,2:1,3:2,500:2,505:1"; my %hash = $string=~/([-.\w]*):([-.\w]*)/g; @array = $string=~/([-.\w]*):/g; use Data::Dumper; print Dumper \@array, \%hash;
Sorry.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-03-28 23:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found