-1

How would one be able to do this? I know you have to use <>.I already tried giving it a shot,but it might just because I am on Windows.

Michelle Moya
  • 29
  • 1
  • 2

2 Answers2

4
# run as:
#       perl my_script1.pl file1 file2
my ($file1, $file2) = @ARGV;
open my $fh1, '<', $file1;
open my $fh2, '<', $file2;
while (<$fh1>) {
    ... do something with $_ from $file1 ...
}
while (<$fh2>) {
    ... do something with $_ from $file2 ...
}
close $fh1;
close $fh2;
mob
  • 117,087
  • 18
  • 149
  • 283
0

You didn't state whether you need to treat the files differently or not. If not, then you can just use <> without needing to call open explicitly.

while (<>) {
  # Process $_
}

will work fine. When it gets to the end of the first file, <> will continue on with reading the second file. And so on until it runs out of files to read.

Dave Sherohman
  • 45,363
  • 14
  • 64
  • 102