Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Strange behavior of "use if" (a conditional "use" with the if module)

Reply
Thread Tools

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

 
 
David Filmer
Guest
Posts: n/a
 
      03-28-2013
I have a program with this line of code:

use if( $Config{'osname'} =~ /Win/ ), 'Win32:rocess::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!

 
Reply With Quote
 
 
 
 
Bjoern Hoehrmann
Guest
Posts: n/a
 
      03-28-2013
* David Filmer wrote in comp.lang.perl.misc:
>I have a program with this line of code:
>
> use if( $Config{'osname'} =~ /Win/ ), 'Win32:rocess::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 · (E-Mail Removed) · 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/
 
Reply With Quote
 
 
 
 
C.DeRykus
Guest
Posts: n/a
 
      03-29-2013
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:rocess::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:rocess::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:rocess::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
 
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
Strange operands to conditional operator paulo C Programming 5 11-14-2006 10:17 PM
? ELSE Conditional Comment / Using Conditional Comments Inside Other Tags To Comment Out Attributes Alec S. HTML 10 04-16-2005 02:21 AM
Re: very strange conditional problem J. Romano Perl 0 02-21-2004 04:55 PM
Re: very strange conditional problem J. Romano Perl 0 02-21-2004 04:14 PM
very strange conditional failure Kodeguru Perl 0 02-20-2004 08:20 PM



Advertisments