in reply to Have a multiple file in directory and want to manipulate in each files in incremental order. All the file have same value.

This code will not compile, it appears to be missing significant sections, ie, the beginnings of the two blocks you are ending with unmatched }. Please post working code.

my @lines = $file

will store the file name in the array. I suspect you actually want to read the lines out of the file into @lines.

foreach my $file (readdir DIR) { next unless -f $file; open my $in_fh, '<', $file; my @lines = <$in_fh>; close $in_fh; # call subroutine here }

You will probably want to call a subroutine where indicated to process @lines and write your output file, since your array will cease to exist once the foreach loop is finished.

Updated per below

1 Peter 4:10
  • Comment on Re: Have a multiple file in directory and want to manipulate in each files in incremental order. All the file have same value.
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Have a multiple file in directory and want to manipulate in each files in incremental order. All the file have same value.
by hexcoder (Curate) on Dec 23, 2014 at 16:38 UTC
    It should read
    foreach my $file (readdir DIR)
    instead of
    foreach my @file (readdir DIR)
    Note the $ instead of the @.