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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.