Strange behavior of "use if" (a conditional "use" with the if module)

Discussion in 'Perl Misc' started by David Filmer, Mar 28, 2013.

  1. David Filmer

    David Filmer Guest

    I have a program with this line of code:

    use if( $Config{'osname'} =~ /Win/ ), 'Win32::process::Info';

    Perl complains:

    Too few arguments to `use if' (some code returning an empty list in list context?) at ...

    However, if I change the regex operator to !~ then Perl is quite happy (the only change is replacing the equals with a bang).

    Does anyone know why Perl is unhappy with =~ in my "use if" statement

    thanks!
    David Filmer, Mar 28, 2013
    #1
    1. Advertising

  2. * David Filmer wrote in comp.lang.perl.misc:
    >I have a program with this line of code:
    >
    > use if( $Config{'osname'} =~ /Win/ ), 'Win32::process::Info';
    >
    >Perl complains:
    >
    >Too few arguments to `use if' (some code returning an empty list in list context?) at ...


    If your osname actually matches /Win/ then you probably forgot to load
    Config.pm. Otherwise, the expression returns an empty list, so there are
    no arguments passed, just like the error message says. Use something
    like `scalar($Config{'osname'} =~ /Win/)` to force a scalar context.
    --
    Björn Höhrmann · mailto: · http://bjoern.hoehrmann.de
    Am Badedeich 7 · Telefon: +49(0)160/4415681 · http://www.bjoernsworld.de
    25899 Dagebüll · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
    Bjoern Hoehrmann, Mar 28, 2013
    #2
    1. Advertising

  3. David Filmer

    C.DeRykus Guest

    On Thursday, March 28, 2013 2:22:09 PM UTC-7, David Filmer wrote:
    > I have a program with this line of code:
    >
    >
    >
    > use if( $Config{'osname'} =~ /Win/ ), 'Win32::process::Info';
    >
    >
    >
    > Perl complains:
    >
    >
    >
    > Too few arguments to `use if' (some code returning an empty list in list context?) at ...
    >
    >
    >
    > However, if I change the regex operator to !~ then Perl is quite happy (the only change is replacing the equals with a bang).
    >
    >
    >
    > Does anyone know why Perl is unhappy with =~ in my "use if" statement
    >
    >
    >


    With strict,warnings,(and more hints from diagnostics), you can hone in on what what 's going wrong:

    If you forgot Config, there's a fatal warning from strict:

    perl -Mstrict -wle ' use if( $Config{osname} =~ /Win/ ), "Win32::process::Info"'
    Global symbol "%Config" requires explicit package name at
    line 1.

    Even if you forget Config and strict both, you get hints from warnings:

    perl -Mstrict -wle ' use if( $Config{osname} =~ /Win/ ), "Win32::process::Info"'
    Use of uninitialized value $Config{"osname"} in pattern
    match (m//) at line 1.
    Too few arguments to 'use if' (some code returning an empty list in list context?) ...

    --
    Charles DeRykus
    C.DeRykus, Mar 29, 2013
    #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. Alec S.
    Replies:
    10
    Views:
    10,091
    Alec S.
    Apr 16, 2005
  2. Fred
    Replies:
    8
    Views:
    293
  3. Jeremy Moles

    Strange Extension Module Behavior

    Jeremy Moles, Sep 29, 2005, in forum: Python
    Replies:
    0
    Views:
    231
    Jeremy Moles
    Sep 29, 2005
  4. t_rectenwald

    Strange Behavior: csv module & IDLE

    t_rectenwald, Dec 29, 2007, in forum: Python
    Replies:
    3
    Views:
    312
    t_rectenwald
    Dec 29, 2007
  5. Zev Blut
    Replies:
    3
    Views:
    162
    trans. (T. Onoma)
    Nov 24, 2004
Loading...

Share This Page