G
Graham
Is it possible to slice a list of hashes?
I read in data into the @data array as follows:
while ( $i < $numLev )
{
$line = <$fh>; # Take
next line
$line =~ s/^\s+|\s+$//g; # Strip
whitespace
$line =~ s/,/ /g; #
Replace commas
@prf = ( @prf, (split /\s+/, $line) ); # Get the data
$i = $#prf + 1; # Update
total
}
@data = (@data, {"id"=>$id, "units"=>$units,
"data"=>[@prf]});
}
I want to find all the indices of atm where $id = "foo" or "bar" and
extract them into a new data array called data2.
Alas, at this point I cannot even slice into @data and select the "id"
fields.
print $atm[(0..2)]; # Gives: HASH(0x121064)
print @atm[(0..2)]; # Gives:
HASH(0x121064)HASH(0x11a0e0)HASH(0x112ce8)
print @atm[(0..2)]{"id"}; # Gives: compilation error.
print $atm[(0..2)]{"id"}; # Gives: string id tag for index 2
Thanks.
I read in data into the @data array as follows:
while ( $i < $numLev )
{
$line = <$fh>; # Take
next line
$line =~ s/^\s+|\s+$//g; # Strip
whitespace
$line =~ s/,/ /g; #
Replace commas
@prf = ( @prf, (split /\s+/, $line) ); # Get the data
$i = $#prf + 1; # Update
total
}
@data = (@data, {"id"=>$id, "units"=>$units,
"data"=>[@prf]});
}
I want to find all the indices of atm where $id = "foo" or "bar" and
extract them into a new data array called data2.
Alas, at this point I cannot even slice into @data and select the "id"
fields.
print $atm[(0..2)]; # Gives: HASH(0x121064)
print @atm[(0..2)]; # Gives:
HASH(0x121064)HASH(0x11a0e0)HASH(0x112ce8)
print @atm[(0..2)]{"id"}; # Gives: compilation error.
print $atm[(0..2)]{"id"}; # Gives: string id tag for index 2
Thanks.