Odd open but no warning

C

Colin Campbell

Recently I had to look at a perl script which was misbehaving. When I looked
at it the code was pretty horrific, among other horrors was the following

open FH, "|$external_program|";
print FH "command";
$response = <FH>;

What surprised me was that this compiled without even a warning.
I wondered if there was ever a use for such an apparently mistaken
construction?

Any views?
(Other than someone should buy the author the llama book for Xmas)
Colin
 
C

Colin Campbell

See the docs for open() and IPC::Open2, which explain a bit about this.
Not really the question I was trying to ask. (I'd already replaced it
with Open2 while cursing its author). But, the answer is that you only
get the warning when running with warnings, not by doing a compile with
warnings. (Hangs head in shame as he should of tried that before
posting).
Colin
 
B

Bob Walton

Colin said:
Not really the question I was trying to ask. (I'd already replaced it
with Open2 while cursing its author). But, the answer is that you only
get the warning when running with warnings, not by doing a compile with
warnings. (Hangs head in shame as he should of tried that before
posting).
Colin

Well, one of the things I was trying to say is that at compile time, all
the compiler checks for is a syntactically valid string for the second
argument of open(). Any string will suffice for compilation purposes.
It is only when execution is attempted that the string is evaluated and
the open is actually attempted to see if it works or not. Any garbagy
string will compile:

perl -wc -e 'open X,"|||~!@#$%^&*()_+|||" or die;print X "a"'

will nicely output

-e syntax OK
 

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

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top