Re: <> tag in perl



To go with Paul's answer:

from http://cslibrary.stanford.edu/108/EssentialPerl.html
(great little refresher course or intro on the essentials)

STDIN, STDOUT, and STDERR are standard filehandles that are
automatically opened before the program runs.

Surrounding a file handle with <> is an expression that returns one
line from the file including the "\n" character, so <STDIN> returns one
line from standard input.

The <> operator returns undef when there is no more input.

The "chop" operator removes the last character from a string, so it can
be used just after an input operation to remove the trailing "\n". The
"chomp" operator is similar, but only removes the character if it is
the end-of-line character.

$line = <STDIN>; ## read one line from the STDIN file handle
chomp($line); ## remove the trailing "\n" if present

$line2 = <FILE2>; ## read one line from the FILE2 file handle
## which must be have been opened previously

Since the input operator returns undef at the end of the file, the
standard pattern to read all the lines in a file is...

# read every line of a file

while ($line = <STDIN>) {
## do something with $line
}

.



Relevant Pages

  • Re: All programs are undefined
    ... new-line character is implementation-defined. ... a terminating new-line character on the last line, ... in the standard does it say, or even imply, this? ... implementation added a trailing new-line itself, ...
    (comp.lang.c)
  • Transponder Protocol Open Standard rec.pets-2005a
    ... But anybody can write an open standard, ... transponders readable by the standard is not intended to be identical ... as 20 character readings under this standard unless the reader designer ... If an excerpt string shows four or fewer transitions ...
    (rec.pets)
  • Re: Herbert Schildt, author of The Complete C++ Reference (NOT C Unleashed) rehabilitated on wikiped
    ... well as on Amazon and wikipedia, on Schildt, Heathfield et al. did try ... Annotated Annotated C Standard" at http://www.lysator.liu.se/c/schildt.html, ... auditing EACH AND EVERY LINE for character width dependent operations ... standard (something that is not mentioned in the annotations), ...
    (comp.programming)
  • Re: Segfault City
    ... Those who ignore the standard library condemn themselves to rewriting it. ... programmers have to use a dictated and not fully standard compiler. ... I'm saying that to rely on character ordering that is not guaranteed ...
    (comp.lang.c)
  • Re: Trigraphs forever
    ... Visual C versions 6.0 and later emit "warning C4010: single-line comment ... "Trigraphs are not popular and many compilers implement them incorrectly. ... Discussing the current C standard is not a waste of time. ... "2 Except within a character constant, a string literal, or a comment, the ...
    (comp.std.c)