in reply to WHILE and DEFINED problem

Aside, I've tried to re-write your code in a way I like it (which is slightly different than other ppl...
open (IN,"<" . "c:/tmp.txt") or die "Doh: $!"; # Use ()'s, and added o +r die... sometimes that comes in hand when debugging. while(<IN>){ # $_ is set to each line for each file. my $line = $_; # Take raw form of line $line =~ chomp $line; # chomp the line. if (length($line)){ # does line have non zero length? (Sorta what y +ou're doing.) print "$line\n"; } } close IN; # Clean up.
$.02


----
Zak - the office

Replies are listed 'Best First'.
Re: Re: WHILE and DEFINED problem
by demerphq (Chancellor) on Mar 06, 2004 at 20:50 UTC

    Well, actually this all wrong. chomp certainly doesnt belong on the right side of a =~ operator. The way to write this is to use the idiom that dragonchild outlined:

    while (<$in>) { chomp(my $line=$_); next unless length $line; print; } __END__ # please excuse this stuff here, just doing some pmdev testing with th +is node :-) # it will be removed soon. # No indent # single space # two spaces # three spaces # four spaces # No indent # single space # two spaces # three spaces # four spaces

    :-)


    ---
    demerphq

      First they ignore you, then they laugh at you, then they fight you, then you win.
      -- Gandhi