P
Petyr David
I have a hash - the key is a filename, the value is a hash. That hash
has 2 values: the file's modification time and a reference to an array.
The array contains lines of text from the fille. I've been playing
around and with this thing for a while and can't figure out how to
access the elemnts of the array. Please review this code first:
# @file_list is an array contain output in this fashion
#
# filename: some pattern which might include a colon
# This works fine
my %file_hash;
my $file_list_cnt = @file_list;
foreach $fil_pat(@file_list){
$fil_pat =~ s/:/XXX/;
@file_and__pattern = split /XXX/, $fil_pat;
$fil_name = $file_and__pattern[0];
@file_stat_info = stat($fil_name);
$mod_time = $file_stat_info[10];
$pattern = $file_and__pattern[1];
if(! $file_hash{$fil_name}){
$file_hash{$fil_name} = {
mod_time => $mod_time,
finds => []
};
}
push (@{$file_hash{$fil_name} => finds} , $pattern);
}
# THIS PART ALSO WORKS FINE:
foreach $file_name ( sort { $file_hash{$b}->{'mod_time'} <=>
$file_hash{$a}->{'mod_time'} } keys %file_hash){
print "<li> " . "<a href=\"/zzz/mirror/" . $file_name . "\">" .
$file_name . "</a><br>";
}
# What I now want to do: for every file name I want to then print each
line in the array named finds.
has 2 values: the file's modification time and a reference to an array.
The array contains lines of text from the fille. I've been playing
around and with this thing for a while and can't figure out how to
access the elemnts of the array. Please review this code first:
# @file_list is an array contain output in this fashion
#
# filename: some pattern which might include a colon
# This works fine
my %file_hash;
my $file_list_cnt = @file_list;
foreach $fil_pat(@file_list){
$fil_pat =~ s/:/XXX/;
@file_and__pattern = split /XXX/, $fil_pat;
$fil_name = $file_and__pattern[0];
@file_stat_info = stat($fil_name);
$mod_time = $file_stat_info[10];
$pattern = $file_and__pattern[1];
if(! $file_hash{$fil_name}){
$file_hash{$fil_name} = {
mod_time => $mod_time,
finds => []
};
}
push (@{$file_hash{$fil_name} => finds} , $pattern);
}
# THIS PART ALSO WORKS FINE:
foreach $file_name ( sort { $file_hash{$b}->{'mod_time'} <=>
$file_hash{$a}->{'mod_time'} } keys %file_hash){
print "<li> " . "<a href=\"/zzz/mirror/" . $file_name . "\">" .
$file_name . "</a><br>";
}
# What I now want to do: for every file name I want to then print each
line in the array named finds.