Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: convert array of hash into formatted one

by choroba (Cardinal)
on Aug 05, 2015 at 17:00 UTC ( [id://1137549]=note: print w/replies, xml ) Need Help??


in reply to convert array of hash into formatted one

Just iterate over the array with for, use the dereference operator -> to access the inner hash'es values.
#!/usr/bin/perl use warnings; use strict; my @arr = ( { case => 'case1', id => '001', name => 'raja', degree => 'bcom' }, # ... ); my $case = q(); for my $hash (@arr) { if ($hash->{case} ne $case) { print ucfirst $hash->{case}, ":\n"; $case = $hash->{case}; } print "$hash->{id}) $hash->{name}, $hash->{degree}\n"; }

You have to be sure that the cases are continuous in the data structure. If they aren't, you'll have to sort the array.

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: convert array of hash into formatted one
by Anonymous Monk on Aug 06, 2015 at 03:48 UTC
    Hi All,
    Thanks all for your prompt response. Now i got an idea how to do this.
    Thanks again.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-04-16 23:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found