http://www.perlmonks.org?node_id=820900

pavanmach has asked for the wisdom of the Perl Monks concerning the following question:

my program is as under:
#!/usr/bin/perl my ($file1,$file2); open(FILE1,"<$ARGV[0]"); open(FILE2,"<$ARGV[1]"); while(<FILE1>) { chomp($_); $file1 = $_; $file1=~s/\s+//; #print "$file1 \n"; while(<FILE2>) { print "<$file1> \n"; } }
now the two files are as under: file1.txt
haai hru welcome hello thats gr8 select * from emp; file2.txt haai hru welcome hello thats gr8 select * from emp; select * from dual;
In the above program i have two while statements. I am trying to print file1 variable in first while which is successful and the output is as under:
haai hru welcome hello thatsgr8 select* from emp;
while i am tring to print the same $file1 in second while statement statement the output is :
<> <> <> <> <> <>
I am not able to access the variable ($file1) in second while loop. Why so? How can i overcome the problem ?