in reply to Re^3: Perl: Directoriesand files
in thread Perl: Directoriesand files

Yes, I understand what you mean. Now is there a way I can read all the files in one code, instead of opening one by one? Thanks for the assistance

Replies are listed 'Best First'.
Re^5: Perl: Directoriesand files
by jethro (Monsignor) on Mar 30, 2011 at 11:22 UTC

    Yes there is:

    my @content; foreach ('','.1','.2','.3','.4') { open(my $fh,'<',$string.$_) or die "Could not open $string.$_ : $!\n +"; push @content, scalar <$fh>; } if ($content[0] == $x){ print @content; $x++; }

    UPDATE: removed bug. UPDATE2: removed another bug found by anon monk

      Context matters :) use
      scalar <$fh>; scalar readline $fh;
      to read a SINGLE line from each file