develooper Front page | perl.beginners | Postings from December 2002

Re: Strange "print" syntax

Thread Previous
From:
Wiggins d'Anconia
Date:
December 9, 2002 17:43
Subject:
Re: Strange "print" syntax
Message ID:
3DF5198A.90205@danconia.org
 From perldoc -f print

"Note that if you’re storing FILEHANDLES in an array or other
expression, you will have to use a block returning its value
instead":

     print { $files[$i] } "stuff\n";
     print { $OK ? STDOUT : STDERR } "stuff\n";

http://danconia.org

Rajendra Babu, Praveen wrote:
> Hi All !!!
>     
>      The below code works fine:
> 
>       $FH = $file_IDS[$z];
>       print $FH "$splt_line[$loctn[$i]],";
>       print $FH "$splt_line[$loctn[$i+1]]\n";
>       $z++;
> 
> But when I remove the temporary variable $FH and use the $file_IDS[$z]
> directly in the print
> statement, gives a syntax error !    i.e. the below code fails:
> 
>       print $file_IDS[$z] "$splt_line[$loctn[$i]],";
>       print $file_IDS[$z] "$splt_line[$loctn[$i+1]]\n";
>       $z++;
> 
>    Can someone throw light on the above differences ? I believe both of the
> above code referring to
> the first argument to "print" is only scalar ??
> 
> TIA,
> Praveen
> 
> IMPORTANT-
> (1) The contents of this email and its attachments are confidential and 
> intended only for the individual or entity named above. Any unauthorised
> use of the contents is expressly prohibited.  If you receive this email 
> in error, please contact us, then delete the email.
> (2) ACNielsen collects personal information to provide and market our 
> services. For more information about use, disclosure and access see our 
> privacy policy at <www.acnielsen.com.au> or contact us on privacyofficer@acnielsen.com.au
> 


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About