Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: if statement

by tachyon (Chancellor)
on May 08, 2002 at 05:55 UTC ( [id://164925]=note: print w/replies, xml ) Need Help??


in reply to if statement

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://164925]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-26 05:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found