Full marks for using warnings, strict, checking the results of opening your files and posting what you have so far. Assuming that you want to check each line in classified1_sports.dat for the string "unclassified" in lower case then print to good.dat if it is there or bad.dat if it is not then a few minor changes to your code and you are rocking:
#!/usr/bin/perl use warnings; use strict; # open 3 filehandles open Classified, "c:/begperl/classified1_sports.dat" or die "Error mes +sage here: $!\n"; open Good, ">c:/begperl/good.dat" or die "Error message here: $!\n"; open Bad, ">c:/begperl/bad.dat" or die "Error message here: $!\n"; # read the classified1_sprots.dat file a line at a time while (<Classified>){ my $line = $_; # we get the line in $_ if ( $line =~ m/unclassified/ ) { # use a match regex to check for + string print Good $line; # print $line to filehandle Good } else { print Bad $line; # print $line to filehandle Bad } } # close our files when finished with them close Classified; close Good; close Bad;
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
In reply to Re: if statement
by tachyon
in thread if statement
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |