How do we open certain number of files in for loop. In my case I have couple of files with name scd_1_2.dat here, the number 1 goes till 5 and 2 goes till 14, I am trying to open recursively but getting some error.
Expand|Select|Wrap|Line Numbers
- #!/usr/bin/perl
- use strict;
- use warnings;
- for (my $i=1;$i<=5;$i++)
- {
- for (my $j=2;$j<=14;$j++)
- {
- open(A, "scd_$i_$j.dat") or die "Check the file";
- open(B,">step$i_$j.out");
- while (<A>)
- {
- my $line = $_; chomp $line;
- my @temp = split (/\s+/,$line);
- my $carbon = $temp[2];
- print B "$carbon\n";
- }
- }
- }
Global symbol "$i_" requires explicit package name at perl.pl line 12.
Global symbol "$i_" requires explicit package name at perl.pl line 13.
Execution of perl.pl aborted due to compilation errors.
I tried to concatenate the $i and $j using "." but still not able to open file.
Any help will be appreciated.
Thanks
Kumar