Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[perl #19131] open: Can't use an undefined value as filehandle reference

0 views
Skip to first unread message

Hans Ginzel

unread,
Dec 14, 2002, 8:14:24 AM12/14/02
to bugs-bi...@netlabs.develooper.com
# New Ticket Created by Hans Ginzel
# Please include the string: [perl #19131]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=19131 >


Hello,

I use debian/pool/main/p/perl/*5.6.1-8.2_i386.deb packages with
precompiled perl for Debian GNU/Linux.

There is in the man page perldoc -f open

open FILEHANDLE,MODE,LIST

but examples there are only for at most 3-arguments and nothing is
written about next params.

I have tried an perl "two-liner"

@files = qw/file1.txt file2.txt/;
open LS, "-|", "ls", "-l", @files or die $!;

and get
Can't use an undefined value as filehandle reference at...

What are the other parameters for? Which value was undefined?

Is there a shell parsing by writting:

open LS, "-|", "ls -l " . join(' ', @files) or die $!;
?

I thing it is unefective to join the files, because perl/shell must do a
word-splitting by executing the command.

There also is

The following triples are more or less equivalent:

open(FOO, "|tr '[a-z]' '[A-Z]'");
open(FOO, '|-', "tr '[a-z]' '[A-Z]'");
open(FOO, '|-') || exec 'tr', '[a-z]', '[A-Z]';

Can you descirbe detaily the more or less equivalence?

Thanks and best regards
Hans

--
http://www.parrotcode.org/
http://practicalperl.com/slides/L02/slide_000.html
http://www.linuxjournal.com/article.php?sid=6488


Slaven Rezic

unread,
Dec 15, 2002, 2:58:01 PM12/15/02
to perl5-...@perl.org, bugs-bi...@netlabs.develooper.com
Hans Ginzel (via RT) <perlbug-...@perl.org> writes:

> # New Ticket Created by Hans Ginzel
> # Please include the string: [perl #19131]
> # in the subject line of all future correspondence about this issue.
> # <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=19131 >
>
>
> Hello,
>
> I use debian/pool/main/p/perl/*5.6.1-8.2_i386.deb packages with
> precompiled perl for Debian GNU/Linux.
>
> There is in the man page perldoc -f open
>
> open FILEHANDLE,MODE,LIST
>
> but examples there are only for at most 3-arguments and nothing is
> written about next params.

This is fixed in perl 5.8.0 with an additional paragraph:

| In the three-or-more argument form of pipe opens,
| if LIST is specified (extra arguments after the
| command name) then LIST becomes arguments to the
| command invoked if the platform supports it. The
| meaning of "open" with more than three arguments
| for non-pipe modes is not yet specified. Experi­
| mental "layers" may give extra LIST arguments
| meaning.



> I have tried an perl "two-liner"
>
> @files = qw/file1.txt file2.txt/;
> open LS, "-|", "ls", "-l", @files or die $!;
>
> and get
> Can't use an undefined value as filehandle reference at...
>
> What are the other parameters for? Which value was undefined?

This also works only with 5.8.0, not with 5.6.1. This is also
described in perldelta.pod of 5.8.0:

| · If your platform supports fork(), you can use the list
| form of "open" for pipes. For example:
|
| open KID_PS, "-|", "ps", "aux" or die $!;
|
| forks the ps(1) command (without spawning a shell, as
| there are more than three arguments to open()), and
| reads its standard output via the "KID_PS" filehandle.
| See perlipc.
|

>
> Is there a shell parsing by writting:
>
> open LS, "-|", "ls -l " . join(' ', @files) or die $!;
> ?
>
> I thing it is unefective to join the files, because perl/shell must do a
> word-splitting by executing the command.
>
> There also is
>
> The following triples are more or less equivalent:
>
> open(FOO, "|tr '[a-z]' '[A-Z]'");
> open(FOO, '|-', "tr '[a-z]' '[A-Z]'");
> open(FOO, '|-') || exec 'tr', '[a-z]', '[A-Z]';
>
> Can you descirbe detaily the more or less equivalence?
>
> Thanks and best regards
> Hans
>

Regards,
Slaven

--
Slaven Rezic - slaven...@berlin.de

tksm - Perl/Tk program for searching and replacing in multiple files
http://ptktools.sourceforge.net/#tksm

0 new messages