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

Need clarification on the print function

by drock (Beadle)
on Mar 17, 2005 at 22:48 UTC ( [id://440571]=perlquestion: print w/replies, xml ) Need Help??

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

perldoc -f print ok in perldoc print it states: If FILEHANDLE is a variable and the next token is a term, it may me intrepreted as an operator unless you interpose a "+" . so in the code :
while (<FOO>) { ....code ...code print +(split)[2], $, ; }
FOO is my filehandle and it is considered a variable meaning $_ right? so the next token a term, would be what? print split or 2 ??? a term meaning a unary term? and what exactly does interpose mean? thanks derek

Edit by BazB: retitle from "print".

Replies are listed 'Best First'.
Re: Need clarification on the print function
by trammell (Priest) on Mar 17, 2005 at 23:09 UTC
    The text you're quoting:
      (NOTE: If FILEHANDLE is a variable and the next token
      is a term, it may be misinterpreted as an operator
      unless you interpose a "+" or put parentheses around
      the arguments.)
    
    applies to the print FILEHANDLE LIST form of print. More relevant for your print statement is:
      Also be careful not to follow the print keyword with
      a left parenthesis unless you want the corresponding
      right parenthesis to terminate the arguments to the
      print--interpose a "+" or put parentheses around all
      the arguments.
    
    Without the "+", you would have
    print(split)[2], $, ;
    which is a syntax error.
Re: Need clarification on the print function
by gam3 (Curate) on Mar 18, 2005 at 00:41 UTC
    print((split)[2], $,); # Might be more clear.
    A picture is worth a thousand words, but takes 200K.

Log In?
Username:
Password:

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

    No recent polls found