On Nov 29, 4:33 am, bourne.ident...@hotmail.com (Manish Jain) wrote: > [...] > print(hndw, $nextline); #problem here > > } > > But perl refuses to take a comma between hndw and $nextline, and consequently > I have to rewrite it as : print hndw $nextline; >
That's because 'print' is a list operator and will gobble up all items in parenthesis as list items. Perl disambiguates the optional filehandle by insisting that no comma follow it. Otherwise, there's a conflation of the filehandle with the list that follows it. Perl doesn't know if you intend a string 'STDERR' or the the STDERR filehandle and so dies with with the fatal, but helpful, error: perl -wle "print(STDERR,'this is an error')" No comma allowed after filehandle at -e line 1. But, perl will still do the right thing if there really is a list: perl -wle "$str='string';print($str, ' bar baz')" string bar baz And the following is ok because you omitted that pesky comma and perl : perl -wle "print(STDOUT 'this is not an error')" this is not an error > But this is much less intuitive to me as a C programmer. Perl's syntactical > rules in general leave a lot to be desired : the syntax actually is overly > flexible and can confound people familiar with structured code. This > particular case of print is an example of something that should work by logic > but does not. Not if you understand what perl's list operator does. For further info, see: perldoc perlop and read about the list operator. -- Charles DeRykus -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/