|
Posted by Sisyphus on June 1, 2006, 10:39 pm
Please log in for more thread options
> Sisyphus wrote:
> > D:\pscrpt\if>cat try.pl
> > use if $^O =~ /another/, MODULE => "Non::Existent";
> > print "OK\n";
>
> You've misread the documentation (which, admittedly, is sparse). You
> are supposed to pass the module name as the second argument, and any
> arguments you would normally pass to use or import() as the remaining
> arguments. So this should be:
>
> use if $^O =~ /another/, "Non::Existent";
Yes, that was my first attempt but it produced the error:
Too few arguments to `use if' (some code returning an empty list in list
context?) at D:/perl58_M/5.8.8/lib/if.pm line 7.
BEGIN failed--compilation aborted at try.pl line 2.
>
> Unfortunately, the above doesn't solve your problem. That's because
> the pattern match is being evaluated in a list context, which means a
> failure to match returns the empty list, not 0. So you actually only
> passed one argument to if's subroutine. This causes the if module to
> fail (albeit differently than your original attempt).
Yep.
>
> use if scalar($^O =~ /another/), "Non::Existent";
>
> should do what you want.
>
It does indeed. Thanks Paul.
Cheers,
Rob
|