in reply to Comparing an array with a regex array of strings?
The Following code creates a hash with first column(Person*) as outer key and other values as inner hash, now you can easily go over the outer key and match the Person and get the values.
use strict; use warnings; use Data::Dumper; my %temp=(); my %main_struc=(); my $match='Person2'; while (my $line = <DATA>) { chomp $line; my @fields = split ("," , $line,2); my @temp=split(',',$fields[1]); foreach my $data (@temp){ my($key,$value)=split('=',$data); $key =~ s/^\s+//; $key =~ s/\s+$//; $main_struc{$fields[0]}{$key}=$value } } print Dumper \%main_struc; print "@{$main_struc{$match}}{'Name','Age','Gender'}"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Comparing an array with a regex array of strings?
by johngg (Canon) on Dec 17, 2015 at 15:24 UTC | |
|
Re^2: Comparing an array with a regex array of strings?
by Ppeoc (Beadle) on Dec 19, 2015 at 19:24 UTC |