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 ?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.