http://qs1969.pair.com?node_id=440571

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.