From
http://mail.augustmail.com/~tadmc/clpmisc.shtml
Ask perl to help you
You can ask perl itself to help you find common programming
mistakes by doing two things: enable warnings (perldoc warnings)
and enable ``strict''ures (perldoc strict).
That wouldn't help you with this problem, but it will in the future
with other problems.
Picking a better Subject would help, too. "Repost Search" doesn't
actually say much about your question.
It's interesting that 'perldoc -q strict' doesn't find anything. The
use of strictures and warnings is such common advice here in clpm
that you'd think it would be in the FAQ as "Why should I 'use
strict' and 'use warnings'?" Sure, you can look at 'perldoc strict'
and 'perldoc warnings', but those docs are pretty heavy-duty for a
beginner -- and a beginning Perl hacker probably needs them more than
experienced folk.
while( <FILEHANDLE> or <FILEHANDLETWO>)
Reads a line from FILEHANDLE, stores it in $_, then reads a line
from FILEHANDLETWO and stores it in $_, overwriting the line from
FILEHANDLE.
{
$mesAlertes = <FILEHANDLE>;
$mesAlertesDeux = <FILEHANDLETWO>;
If you are at the end of either file, you'll get an error from one
of these lines.
$final = ($mesAlertes, $mesAlertesDeux);
I don't think that does what you seem to think it does. You're using
the comma operator in a scalar context, which will put the value of
$mesAlertesDeux into $final. See 'perldoc perlop' and look for
"Comma Operator". (If it makes you feel better, I made the same
mistake in one of my first posts here and was promptly corrected.)
print $final;
}
Want to make a search in two files, and print data on screen. But
if the files have the same data, the data will be display once. My
code don't work. why?
BTW, i'm a newbie, so thanks to be patient
If I understand you correctly, something like this may be what you
want.
[untested]
while(1) {
last if eof(FILEHANDLE) or eof(FILEHANDLETWO);
my $mesAlertes = <FILEHANDLE>;
my $mesAlertesDeux = <FILEHANDLETWO>;
if ($mesAlertes eq $mesAlertesDeux) {
print $mesAlertes;
}
else {
chomp $mesAlertes;
print "*** $mesAlertes *** $mesAlertesDeux";
}
}
This will stop printing when it reaches the end of the file with the
fewest lines.