Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: while loop over filehandle

by spartacus9 (Beadle)
on Sep 23, 2002 at 05:09 UTC ( [id://200010]=note: print w/replies, xml ) Need Help??


in reply to while loop over filehandle

instead of using the regex to remove the \r and \n, try:
chomp($user);
that will remove any newline characters from the string if they exist.

i'm not sure what your "next if !$user" line is doing. since you're already inside a while loop, that logic should already be taken care of without having to check the $user variable again.

Replies are listed 'Best First'.
Re: Re: while loop over filehandle
by diotalevi (Canon) on Sep 23, 2002 at 13:50 UTC

    Just an additional note on that - while your regex is better written as chomp($user) you can make an improvement by using a character class instead of alternation:

    You wrote $user =~ s/(\r|\n)//.

    You *meant* $user =~ s/(\r|\n)$// since that newline should only occur at the end of the string.

    That group is capturing but it doesn't need to $user =~ s/(?:\r|\n)$//. Don't use capturing where it's not needed.

    In fact - grouping is wasteful for single character alternation. Use a character class instead $user =~ s/[\r\n]$//.

    And even better use chomp() chomp($user).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2024-04-18 09:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found