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

Reading lines from a file

by trewq (Initiate)
on Aug 06, 2009 at 05:30 UTC ( [id://786313]=perlquestion: print w/replies, xml ) Need Help??

trewq has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks,

When you read lines from a file you use, for example, <FILE>.
Until what character does the perl read the line?
I mean, what is the "end of the line" mark? Does it add this mark to the beginning of the second line read?

Thanks

Replies are listed 'Best First'.
Re: Reading lines from a file
by ELISHEVA (Prior) on Aug 06, 2009 at 05:50 UTC

    Welcome to PerlMonks!

    That depends on what value you assign to the variable $/. By default, it is set to the new line character (\n) but it can be set to any character or even a string with many characters. See perlvar.

    Every time you read a line, Perl reads upto and including the end of line mark set in $/. To remove the end of line mark from a line you just read in, you use chomp. You may also find this link in the perl documentation helpful: How-can-I-read-in-an-entire-file-all-at-once?.

    In the future you may want to consider asking simple questions about the meaning of terms in the chatter box (look for it on the sidebar on the right). In the chatterbox we can quickly go back and forth to clear up any misunderstandings. Another comment: I strongly encourage you to follow those documentation links. Perl documentation can be hard to read when you are first beginning, but the more you do it, the easier it gets. The more you expose yourself to programming jargon, the faster you will progress.

    Best, beth

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://786313]
Approved by wfsp
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: (5)
As of 2024-04-26 09:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found