Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Odd open but no warning

Reply
Thread Tools

Odd open but no warning

 
 
Colin Campbell
Guest
Posts: n/a
 
      07-08-2003
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

 
Reply With Quote
 
 
 
 
Colin Campbell
Guest
Posts: n/a
 
      07-09-2003
In article <(E-Mail Removed)>, Bob Walton wrote:
>
>> open FH, "|$external_program|";

>
> 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
 
Reply With Quote
 
 
 
 
Bob Walton
Guest
Posts: n/a
 
      07-10-2003
Colin Campbell wrote:

> In article <(E-Mail Removed)>, Bob Walton wrote:
>
>>>open FH, "|$external_program|";
>>>

>>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
>


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

--
Bob Walton

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Odd behavior with odd code Michael Speer C Programming 33 02-18-2007 07:31 AM
warning C4267 and warning C4996 B. Williams C++ 17 10-27-2006 09:41 PM
Warning: WARNING Charles Computer Support 7 08-16-2005 09:07 PM
Re: A code fix for MSVC warning C4267 (64-bit compatibility warning,e.g. Boost Spirit) Pete Becker C++ 0 02-10-2005 01:13 PM



Advertisments