Odd open but no warning

Discussion in 'Perl Misc' started by Colin Campbell, Jul 8, 2003.

  1. 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
    Colin Campbell, Jul 8, 2003
    #1
    1. Advertising

  2. In article <>, 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
    Colin Campbell, Jul 9, 2003
    #2
    1. Advertising

  3. Colin Campbell

    Bob Walton Guest

    Colin Campbell wrote:

    > In article <>, 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
    Bob Walton, Jul 10, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pete Becker
    Replies:
    0
    Views:
    1,368
    Pete Becker
    Feb 10, 2005
  2. Michael Speer

    Odd behavior with odd code

    Michael Speer, Feb 16, 2007, in forum: C Programming
    Replies:
    33
    Views:
    1,069
    Richard Heathfield
    Feb 18, 2007
  3. B. Williams

    warning C4267 and warning C4996

    B. Williams, Oct 26, 2006, in forum: C++
    Replies:
    17
    Views:
    2,615
  4. WARNING! Prosoftstore.com is a SCAM! WARNING!

    , Jul 8, 2007, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    306
  5. Julian Mehnle
    Replies:
    17
    Views:
    853
    Julian Mehnle
    May 18, 2006
Loading...

Share This Page