Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: Uninitialized Value

by vinoth.ree (Monsignor)
on May 18, 2015 at 17:30 UTC ( [id://1127039]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Uninitialized Value
in thread Uninitialized Value

Is there a way for the code to ignore the whitespace or any type of null in the data file?

while (<FILE>) { if ($_ =~ /^$/) { print "it's blank\n"; next; #process next line } else { print "it's NOT blank\n"; } }

if($_ =~ /^$/) can also be written as if(/^$/)


All is well. I learn by answering your questions...

Replies are listed 'Best First'.
Re^4: Uninitialized Value
by marinersk (Priest) on May 18, 2015 at 19:13 UTC

    if ($_ =~ /^$/)

    This code does not detect whitepace (a line of all spaces, for example) as requested.

    Perhaps this would work better:

    if ($_ =~ /^\s*$/)

Re^4: Uninitialized Value
by Not_a_Number (Prior) on May 18, 2015 at 20:07 UTC

    ...also, the next is unnecessary.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (None)
    As of 2024-04-25 03:56 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found