print FILEHANDLE is valid syntax ? 
Author Message
 print FILEHANDLE is valid syntax ?

The Perl documentation describes the:

print FILEHANDLE LIST
print

forms of the print function, but they
do not describe the:

print FILEHANDLE

syntax, which writes $_ to FILEHANDLE.
This seems to work fine with both Perl 5.005 and
ActiveState's build 522 of Perl on NT.

However, as it's not mentioned formally anywhere,
I'm wondering if it's a bug, not a feature, and is
likely to disappear at some future date. I'd like
to know for sure as I'm documenting it for a course.

Anyone know what the story is here ?

Steve Collyer.



Sun, 20 Oct 2002 03:00:00 GMT  
 print FILEHANDLE is valid syntax ?

Quote:

> Sent: Wednesday, May 03, 2000 03:00

> Subject: print FILEHANDLE is valid syntax ?

> The Perl documentation describes the:

> print FILEHANDLE LIST
> print

> forms of the print function, but they
> do not describe the:

> print FILEHANDLE

> syntax, which writes $_ to FILEHANDLE.
> This seems to work fine with both Perl 5.005 and
> ActiveState's build 522 of Perl on NT.

> However, as it's not mentioned formally anywhere,
> I'm wondering if it's a bug, not a feature, and is
> likely to disappear at some future date. I'd like
> to know for sure as I'm documenting it for a course.

> Anyone know what the story is here ?

I think there is an oversight in the documentation of the print()
function.

  If FILEHANDLE is omitted, prints by default to standard output (or to
  the last selected output channel--see select). If LIST is also
omitted,
  prints $_ to the currently selected output channel.

I would change the last sentence to read:

  If LIST is omitted, prints $_  to the currently selected output
channel
  if FILEHANDLE is also omitted, otherwise to FILEHANDLE.

Maybe you should file a documentation bug report.  If this behavior were
ever to change, tons of code would begin to fail.  So it will never
change.

--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/



Mon, 21 Oct 2002 03:00:00 GMT  
 print FILEHANDLE is valid syntax ?
[A complimentary Cc of this posting was sent to Stephen Collyer


Quote:
> but they do not describe the:
> print FILEHANDLE
> syntax, which writes $_ to FILEHANDLE.

No it does not, at least does not always:

  perl -wle 'print 12'
  12

As you see, it did not try to print $_ to filehandle \*12.

Quote:
> However, as it's not mentioned formally anywhere, I'm wondering if
> it's a bug, not a feature, and is likely to disappear at some future
> date.

I would say that it can be an "accidental feature", like //ee.  Given
that few reasonable people would use this, I would guess that it may
easily go away with a next edit of the lexer.

Ilya



Mon, 21 Oct 2002 03:00:00 GMT  
 print FILEHANDLE is valid syntax ?

Quote:

> Given
> that few reasonable people would use this, I would guess that it may
> easily go away with a next edit of the lexer.

OTOH, reasonable people may disagree.  I think it's a perfectly fine
feature, with predictable behavior.  

--
John Porter



Tue, 22 Oct 2002 03:00:00 GMT  
 print FILEHANDLE is valid syntax ?
....snip...

: I would say that it can be an "accidental feature", like //ee.  Given

How is //ee "accidental" ?  It is documented in perlop.pod, and has been
available for at least a few years.

It's behaviour is straight forward - i.e. it's hard to claim anyone can be
misunderstanding this capability.



Tue, 22 Oct 2002 03:00:00 GMT  
 print FILEHANDLE is valid syntax ?

Quote:
> : I would say that it can be an "accidental feature", like //ee.  Given
> How is //ee "accidental" ?  It is documented in perlop.pod, and has been
> available for at least a few years.

> It's behaviour is straight forward - i.e. it's hard to claim anyone can be
> misunderstanding this capability.

It was never intended to work, but one day it was discovered to work by
accident. Of course, it was kept around because it turned out to be
useful. If it hadn't been kept, we'd call it a bug. :-)

--
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



Tue, 22 Oct 2002 03:00:00 GMT  
 print FILEHANDLE is valid syntax ?

Quote:

> ....snip...

> : I would say that it can be an "accidental feature", like //ee.  Given

> How is //ee "accidental" ?  

In the sense of being an accident.  :)

Seriously, /ee was not a designed feature.  Someone pointed out that
the code that Larry had written for /e happened to be executed twice
if you put two e's, and that this was actually useful.  But it wasn't
put there on purpose; it was just an unexpected artifact of the way it
happened to be implemented.

In short, it was an accident.

Quote:
> It's behaviour is straight forward - i.e. it's hard to claim anyone can be
> misunderstanding this capability.

Perhaps, but that has nothing to do with it being an accident.


Tue, 22 Oct 2002 03:00:00 GMT  
 print FILEHANDLE is valid syntax ?
[A complimentary Cc of this posting was sent to Larry Rosler


Quote:
> I would change the last sentence to read:

>   If LIST is omitted, prints $_  to the currently selected output
> channel
>   if FILEHANDLE is also omitted, otherwise to FILEHANDLE.

As I explained in another message, this is not enough.

  print $var;

What is it?  print LIST or print FILEHANDLE?  What about

  print foo;

?  Is it print {\*foo}?  Or print foo()?  Or print "foo"?

I do not think a lot of people use such an ambiguous syntax, even if
(by lexing accident) it work.

Ilya



Tue, 22 Oct 2002 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Sybase connection problems

2. 7.0 help

3. print to a FileHandle : Syntax question

4. print to filehandle when filehandle is a $var

5. Pascal tutor

6. Function syntax with prototyping, filehandles and arrays

7. Clarification wanted on FileHandle syntax

8. Bug in syntax of filehandle on open call?

9. Print OUT korn shell syntax in Perl script?

10. Print and SendMail Syntax

11. Oracle and TDateTime

12. C to PAS?

 

 
Powered by phpBB® Forum Software