D
Dave from Dublin
Hi,
I am quite new to Perl. I have several sets of data and within each
individual file news stories are seperated using ========.
My goal is to recreate each file without this divider. Eventually I
will look to iterate through the whole directory but for now I just
want to print all lines but the divider into a new file for one file
(1.ref)
But it's not working, all lines are being printed. Can anyone tell me
what's wrong (see code below), NOTE the ELSE is just a test
Thanks,
David
#!/usr/bin/perl
open(FILEREAD, "< 1.ref");
open(FILEWRITE, "> 1a.ref");
while (<FILEREAD>){
chop ( $line );
if ($line !=~ /====/ ){
print FILEWRITE;
}
else{
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
}
}
close FILEWRITE;
close FILEREAD;
I am quite new to Perl. I have several sets of data and within each
individual file news stories are seperated using ========.
My goal is to recreate each file without this divider. Eventually I
will look to iterate through the whole directory but for now I just
want to print all lines but the divider into a new file for one file
(1.ref)
But it's not working, all lines are being printed. Can anyone tell me
what's wrong (see code below), NOTE the ELSE is just a test
Thanks,
David
#!/usr/bin/perl
open(FILEREAD, "< 1.ref");
open(FILEWRITE, "> 1a.ref");
while (<FILEREAD>){
chop ( $line );
if ($line !=~ /====/ ){
print FILEWRITE;
}
else{
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
}
}
close FILEWRITE;
close FILEREAD;