Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Parsing data into an Array of Hashes

by Wonko the sane (Deacon)
on Sep 18, 2003 at 12:57 UTC ( #292375=note: print w/ replies, xml ) Need Help??


in reply to Parsing data into an Array of Hashes

This is one way to do it.

#!/usr/local/bin/perl5.6.0 -w use strict; use Data::Dumper; my @records; while ( my $entry = <DATA> ) { my %rec = map { /(\S+)\s*=\s*([^\n\r]+)$/ } split( /,/, $entry ); push( @records, \%rec ); } print Dumper( \@records ); __DATA__ Field1= a value,Field2= another value, Field3= yet another value Field1= a value,Field2= another value, Field3= yet another value Field1= a value,Field2= another value, Field3= yet another value

Best Regards,
Wonko


Comment on Re: Parsing data into an Array of Hashes
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2015-07-04 10:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (59 votes), past polls