My home directory contains these files:-
08-1.txt
08-2.txt
09-1.txt
09-2.txt
####
i have an array
@files = ("08","09");
##
##
foreach $file (@files)
{
$file =~ s/\s*$//;
@command = `ls -l|grep $file`;
print @command;
system("/usr/bin/perl hash.pl $file");
}
##
##
Content of hash.pl
#!/usr/local/bin/perl
my %data;
my $header = <>; # first line
while(<>) {
my($key) = split /\s+/;
$data{$key} = $_;
}
print $header;
foreach my $key (sort keys %data) {
print $data{$key};
}
##
##
value of @command array after the first iteration of @files
is
$command[0]=08-1.txt
$command[1]=08-2.txt
but for the second iteration of @files value of @command array :-
$command[0]=09-1.txt
09-2.txt
$command[1]=empty.
why this is happening?
i want the value to be
$command[0]=09-1.txt
$command[1]=09-2.txt
can anyone please help?