in reply to convert array of hash into formatted one
#!/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 |