Can't use "open my" with pipe

E

Eric

This works:

open SOURCE 'gunzip -c test.rdf.gz|' or die $!;
my $source = \*SOURCE;

This doesn't ("No such file or directory"):

open my $source, '<', 'gunzip -c test.rdf.gz|' or die $!;

Can latter syntax be made to work, if modified?

(Rationale: Fits into one line...)
 
A

A. Sinan Unur

(e-mail address removed) (Eric) wrote in @posting.google.com:
This works:

open SOURCE 'gunzip -c test.rdf.gz|' or die $!;
my $source = \*SOURCE;

This doesn't ("No such file or directory"):

It does work. Tells you that the file you specified does not exist.
open my $source, '<', 'gunzip -c test.rdf.gz|' or die $!;

Can latter syntax be made to work, if modified?

(Rationale: Fits into one line...)

open(my $source, '-|', 'gunzip -c test.rdf.gz') or die $!;
while(<$source>) {
print;
}

or

open(my $source, 'gunzip -c test.rdf.gz|') or die $!;
while(<$source>) {
print;
}

perldoc -f open

Sinan.
 
E

Eric J. Roode

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

(e-mail address removed) (Eric) wrote in @posting.google.com:
This works:

open SOURCE 'gunzip -c test.rdf.gz|' or die $!;
my $source = \*SOURCE;

open my $source, 'gunzip -c test.rdf.gz|' or die $!;


This doesn't ("No such file or directory"):

open my $source, '<', 'gunzip -c test.rdf.gz|' or die $!;

You're trying to read from a file called 'gunzip -c test.....'
When using the three-argument form of open, the middle argument indicates
how you want the file (or pipe) to be opened, not any special character in
the filename string.

- --
Eric
$_ = reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPzLn/WPeouIeTNHoEQIVpgCg6TLuIJC3fkyT9LSX5aKi8TYogrQAoMhA
HQIbc52UHmwZGcxaRZK+WYXf
=YsEF
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,121
Messages
2,570,714
Members
47,282
Latest member
hopkins1988

Latest Threads

Top