Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Unix and Windows CRLF vs LF

by Burak (Chaplain)
on May 13, 2009 at 06:02 UTC ( [id://763675]=note: print w/replies, xml ) Need Help??


in reply to Unix and Windows CRLF vs LF

Using foreach on the FH is not efficient. Use while instead. And perl will automatically convert the line ending AFAIK. Try to use chomp:
while ( my $line = <FILE> ) { chomp $line; # remove new line #Random code }

Replies are listed 'Best First'.
Re^2: Unix and Windows CRLF vs LF
by targetsmart (Curate) on May 13, 2009 at 07:11 UTC
    to add more value to Burak's post
    chomp $line; # remove new line

    from chomp
    This safer version of "chop" removes any trailing string that corresponds to the current value of $/ (also known as $INPUT_RECORD_SEPARATOR in the English module).


    Vivek
    -- In accordance with the prarabdha of each, the One whose function it is to ordain makes each to act. What will not happen will never happen, whatever effort one may put forth. And what will happen will not fail to happen, however much one may seek to prevent it. This is certain. The part of wisdom therefore is to stay quiet.
Re^2: Unix and Windows CRLF vs LF
by SavannahLion (Pilgrim) on May 13, 2009 at 06:19 UTC
    Ooops!! I meant to write While, rather than for each. I don't think for each in my code even works properly as it is written. I will update and make note.

    On a side note, why is For Each less efficient than While? Aren't they the same in this context?

    ----
    Thanks for your patience.

      foreach will make a list out of the file's contents and then will iterate, so it will read the whole file into memory. while has a small footprint since it goes through the contents line by line plus it terminates when the the condition will evaluate to false;with foreach you go through everything in the list

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-20 01:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found