ID=1 First=John Last=Doe AGE=42
ID=2 First=Jane Last=Doe AGE=35
ID=3 First=Jack Last=Doe AGE=17
ID=4 First=Jill Last=Doe AGE=15
####
#!/usr/bin/perl
use Data::Dumper;
use strict;
use warnings;
getPeople();
sub getPeople {
my ( $id, $first, $last, $age );
my $file = 'list.txt';
my $people;
my $cntr;
open( LIST, "< $file" ) or die "Can't open $file : $!";
#my @lines = split /\n/, $str;
#foreach my $line (@lines) {
while (my $row = ) {
$cntr++;
my ($id, $first, $last, $age ) = split( /\s/, $row );
$id = (split( /=/, $id ))[1];
$first = (split( /=/, $first ))[1];
$last = (split( /=/, $last ))[1];
$age = (split( /=/, $age ))[1];
$people = { "$cntr" => {
'id' => "$id",
'first' => "$first",
'last' => "$last",
'age' => "$age"
}
};
}
print Dumper $people;
close LIST;
}
##
##
$VAR1 = {
'4' => {
'first' => 'Jill',
'last' => 'Doe',
'id' => '4',
'age' => '15'
}
};
####
$VAR1 = {
'4' => {
'first' => 'Jill',
'last' => 'Doe',
'id' => '4',
'age' => '15'
}
'3' => {
'first' => 'Jack',
'last' => 'Doe',
'id' => '3',
'age' => '17'
}
'2' => {
'first' => 'Jane',
'last' => 'Doe',
'id' => '2',
'age' => '35'
}
'1' => {
'first' => 'John',
'last' => 'Doe',
'id' => '1',
'age' => '42'
}
};