Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: String split problem

by ZlR (Chaplain)
on Apr 06, 2010 at 14:42 UTC ( #833051=note: print w/replies, xml ) Need Help??

in reply to String split problem

Here's how i do that :
my $str =" [India] Captain1 = Dhoni Batsman1 = Sachin Bowler1 = Zaheer [Aussie] Captain = Ponting Batsman = Clarke Bowler = Warne [Aussie] Captain = Hussey Batsman = Waugh Bowler = Mcgrath"; my @l = split "\n", $str ; my $key ; my %rez ; for my $it (@l) { next if $it =~ m /^$/ ; if ($it =~ m/^\[(.*)\]/) { $key = $1 } else { my @t = split "=", $it ; $rez{$key}{ $t[0] } = $t[1] } } use Data::Dumper ; print Dumper \%rez ;
It's really basic and straightforward but a least you immediately know what's going on.

edit : did not see that the aussie section was duped, you could always if define $rez{$key} etc ...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://833051]
[atcroft]: Lady_Aleena: I found the L<name|section> syntax, which describes linking to a perl manual page, and L<text|url> to link to a web page. The reason I asked was because I was on looking at a module,
[atcroft]: and it referred to several other modules, but the links went to I found that a bit of a surprise, and it got me wondering if there was a "standard" way to link to other modules in the documentation on CPAN.

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2017-05-27 03:50 GMT
Find Nodes?
    Voting Booth?