Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Push values into a hash

by Maresia (Beadle)
on Jul 25, 2016 at 17:19 UTC ( [id://1168481]=note: print w/replies, xml ) Need Help??


in reply to Push values into a hash

Could this help?
#!/usr/bin/perl use strict; use warnings; use Data::Dump 'pp'; use Data::Dumper; use JSON; my @AoH; #Array of hash references foreach my $line (<DATA>) { chomp($line); my ($names, $add, $phone, $email) = split/,/, $line; push @AoH, { name => $names, address => $add, phone => $phone, ema +il => $email } ; } my $json = encode_json \@AoH; print Dumper $json; __DATA__ Joe, Main Street, 346 20274, test1@test.com Mary, Central Road, 02615128, test2@test.com Lou, Cannal St, 612262297692848, test3@test.com Carl, Sout St, 3268022049187, test4@test.com =result # Valid JSON [ { "email": " test1@test.com", "name": "Joe", "address": " Main Street", "phone": " 346 20274" }, { "email": " test2@test.com", "name": "Mary", "address": " Central Road", "phone": " 02615128" }, { "email": " test3@test.com", "name": "Lou", "address": " Cannal St", "phone": " 612262297692848" }, { "email": " test4@test.com", "name": "Carl", "address": " Sout St", "phone": " 3268022049187" } ] =cut

Replies are listed 'Best First'.
Re^2: Push values into a hash
by Anonymous Monk on Jul 25, 2016 at 18:15 UTC
    Thank you, it worked!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-19 21:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found