Muthukumar wrote:
On 11/29/05, Mazhar <[EMAIL PROTECTED]> wrote:
Sorry i am passing the OPEN as
Open (FILE1,"<one Fuile");
Open (FILE,"<Second File");
Still the string is ot matching. Help me please
Use like this:
No, like this:
use strict;
use warnings;
Always do that, especially when posting code to this list.
open FD, "< file1";
open FD1, "< file2";
Is it even open?
open my $file1_fh, '<', 'file1' or die "file1 open failed: $!";
open my $file2_fh, '<', 'file2' or die "file2 open failed: $!";
while (<FD>)
{
$line1=chomp($_); # chomp() Needed
No no no, $Line1 is now a number:
perldoc -f chomp
"It returns the total number of characters removed from all its
arguments."
while (<FD1>)
{
$line = chomp($_); # chomp() Needed
again, nope...
if ($line =~ /.*$line1.*/) # (.*)Not needed
{
print "Got the String\n";
}
}
}
Revert on having more queries.
This will open both files and check each line of file2 against each line
of file1 (and it alerts you to any problems, is easier to read, best
pratice safe (hopefully ;p), ect etc):
#!/usr/bin/perl
use strict;
use warnings;
open my $file1_fh, '<', 'file1' or die "file1 open failed: $!";
open my $file2_fh, '<', 'file2' or die "file2 open failed: $!";
while(<$file1_fh) {
my $line = $_;
chomp $line;
while(<$file2_fh>) {
my $match_against = $_;
chomp $match_against;
print "Got the string\n" if $line =~ m{$match_against}xms;
}
}
close $file1_fh;
close $file2_fh;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>