Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: WHILE and DEFINED problem

by zakzebrowski (Curate)
on Mar 05, 2004 at 19:15 UTC ( #334331=note: print w/replies, xml ) Need Help??


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


Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2020-07-08 11:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?