Results 1 to 3 of 3

Thread: error in my perl code

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 1999
    Location
    London, England
    Posts
    213

    error in my perl code

    I have the following code:

    while (<INFILE> ) {
    print OUTFILE;
    }

    The above code reads every line in my INFILE and writes it to the OUTFILE and works fine, but when I change it to the following it doesn't write anything to my OUTFILE ?

    while (<INFILE> ) {
    if ($_ eq "yes") {
    print "$_";
    print OUTFILE;
    }
    }

    I only want to write those records to my outfile where the record ($_) = yes.

  2. #2
    Hyperactive Member progressive's Avatar
    Join Date
    Sep 2001
    Location
    Manchester, UK
    Posts
    404
    to print to the outfile you need to do this!

    Code:
    print OUTFILE $_;

  3. #3
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    Actually the following lines should be equivalent:
    Code:
    print OUTFILE $_;
    print OUTFILE;
    This being Perl, if you wanted to write a file to std out:
    Code:
    while (<INFILE> ) { 
    print; 
    }
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width