Ask a Question related to PERL Modules, Design and Development.
-
Sisyphus #1
The 'if' module
D:\pscrpt\if>cat try.pl
use if $^O =~ /another/, MODULE => "Non::Existent";
print "OK\n";
D:\pscrpt\if>perl try.pl
Can't locate Non/Existent.pm in @INC (@INC contains: D:/perl58_M/5.8.8/lib
D:/perl58_M/site/5.8.8/lib D:/perl58_M/site/lib .) at
D:/perl58_M/5.8.8/lib/if.pm line 13.
BEGIN failed--compilation aborted at try.pl line 1.
Since $^O does not match "another", I expected there to be no attempt to
load the non-existent module (Non::Existent).
What's the correct usage of the 'if' module for this case where I want to
load Non::Existent iff $^O matches "another" ?
Cheers,
Rob
Sisyphus Guest
-
How to set module to be on top of another module
hello guys!! i'm just newbie in flex, and cant figured out how to manage loaded modules to set who's on top of each other. if i load one module... -
RFC: New module 'Module::Bundled::Files'
I've written a module, tentatively named Module::Bundled::Files. A section of the POD docs is included to (attempt) to explain it's purpose. It... -
looking for a module
has anyone ever seen modules with any of these features? 1) take a block of text and list all words in alpha order a) list word only once with... -
Module Object and sub module function
Howdy folks, Yet another module question. I'm so close and I've done this but I can't get it to work. I am writing a module that is an... -
nvnet module not working after kernel (and module) recompile
--- SYNeR <tups77@tsn.cc> escribió: Make sure that when you 'make-kpkg <options here> kernel_image kernel_headers' that you have that... -
Sisyphus #2
The 'if' module
D:\pscrpt\if>cat try.pl
use if $^O =~ /another/, MODULE => "Non::Existent";
print "OK\n";
D:\pscrpt\if>perl try.pl
Can't locate Non/Existent.pm in @INC (@INC contains: D:/perl58_M/5.8.8/lib
D:/perl58_M/site/5.8.8/lib D:/perl58_M/site/lib .) at
D:/perl58_M/5.8.8/lib/if.pm line 13.
BEGIN failed--compilation aborted at try.pl line 1.
Since $^O does not match "another", I expected there to be no attempt to
load the non-existent module (Non::Existent).
What's the correct usage of the 'if' module for this case where I want to
load Non::Existent iff $^O matches "another" ?
Cheers,
Rob
Sisyphus Guest
-
Gunnar Hjalmarsson #3
Re: The 'if' module
Sisyphus wrote:
I have no idea.> D:\pscrpt\if>cat try.pl
> use if $^O =~ /another/, MODULE => "Non::Existent";
> print "OK\n";
> D:\pscrpt\if>perl try.pl
> Can't locate Non/Existent.pm in @INC (@INC contains: D:/perl58_M/5.8.8/lib
> D:/perl58_M/site/5.8.8/lib D:/perl58_M/site/lib .) at
> D:/perl58_M/5.8.8/lib/if.pm line 13.
> BEGIN failed--compilation aborted at try.pl line 1.
>
> Since $^O does not match "another", I expected there to be no attempt to
> load the non-existent module (Non::Existent).
>
> What's the correct usage of the 'if' module for this case where I want to
> load Non::Existent iff $^O matches "another" ?
Why not just do:
BEGIN {
if ($^O =~ /another/) {
require Non::Existent;
import Non::Existent;
}
}
--
Gunnar Hjalmarsson
Email: [url]http://www.gunnar.cc/cgi-bin/contact.pl[/url]
Gunnar Hjalmarsson Guest
-
Paul Lalli #4
Re: The 'if' module
Sisyphus wrote:
You've misread the documentation (which, admittedly, is sparse). You> D:\pscrpt\if>cat try.pl
> use if $^O =~ /another/, MODULE => "Non::Existent";
> print "OK\n";
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";
Unfortunately, the above doesn't solve your problem. That's because> D:\pscrpt\if>perl try.pl
> Can't locate Non/Existent.pm in @INC (@INC contains: D:/perl58_M/5.8.8/lib
> D:/perl58_M/site/5.8.8/lib D:/perl58_M/site/lib .) at
> D:/perl58_M/5.8.8/lib/if.pm line 13.
> BEGIN failed--compilation aborted at try.pl line 1.
>
> Since $^O does not match "another", I expected there to be no attempt to
> load the non-existent module (Non::Existent).
>
> What's the correct usage of the 'if' module for this case where I want to
> load Non::Existent iff $^O matches "another" ?
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).
use if scalar($^O =~ /another/), "Non::Existent";
should do what you want.
Paul Lalli
Paul Lalli Guest
-
Sisyphus #5
Re: The 'if' module
"Paul Lalli" <mritty@gmail.com> wrote in message
news:1149213330.151488.24350@c74g2000cwc.googlegro ups.com...Yes, that was my first attempt but it produced the error:> 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";
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.
Yep.>
> 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).
It does indeed. Thanks Paul.>
> use if scalar($^O =~ /another/), "Non::Existent";
>
> should do what you want.
>
Cheers,
Rob
Sisyphus Guest
-
Paul Lalli #6
Re: The 'if' module
Sisyphus wrote:
I do feel the need to point out that this error message told you> "Paul Lalli" <mritty@gmail.com> wrote in message
> news:1149213330.151488.24350@c74g2000cwc.googlegro ups.com...>> > 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.
exactly what the problem was. I'm confused as to why you chose to
disregard it and instead change the syntax of your module call
syntax...
Paul Lalli
Paul Lalli Guest
-
Sisyphus #7
Re: The 'if' module
"Paul Lalli" <mritty@gmail.com> wrote in message
news:1149249143.316925.80170@f6g2000cwb.googlegrou ps.com...I don't think this is the forum to discuss your needs.> Sisyphus wrote:>> > "Paul Lalli" <mritty@gmail.com> wrote in message
> > news:1149213330.151488.24350@c74g2000cwc.googlegro ups.com...> >> > > 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.
> I do feel the need to point out that this error message told you
> exactly what the problem was.
I'm also not so sure that you and I would agree on the meaning of "exactly".
The term "some code" does not strike me as being all that exact.
I "chose to disregard it" ??> I'm confused as to why you chose to
> disregard it and instead change the syntax of your module call
> syntax...
>
The arrogance of that assertion is, of course, insulting. The fact that it's
false doesn't really bother me.
Cheers,
Rob
Sisyphus Guest
-
Paul Lalli #8
Re: The 'if' module
Sisyphus wrote:
'some code' on line 2, which was:> "Paul Lalli" <mritty@gmail.com> wrote in message
> news:1149249143.316925.80170@f6g2000cwb.googlegrou ps.com...>> > Sisyphus wrote:> >> > > "Paul Lalli" <mritty@gmail.com> wrote in message
> > > news:1149213330.151488.24350@c74g2000cwc.googlegro ups.com...
> > > > 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.
> > I do feel the need to point out that this error message told you
> > exactly what the problem was.
> I don't think this is the forum to discuss your needs.
> I'm also not so sure that you and I would agree on the meaning of "exactly".
> The term "some code" does not strike me as being all that exact.
use if $^O =~ /another/, "Non::Existent";
Exactly how many parts of that code do you think can return an empty
list in list context?
Sure seems that way to me. Your original message to this newsgroup>> > I'm confused as to why you chose to
> > disregard it and instead change the syntax of your module call
> > syntax...
> >
> I "chose to disregard it" ??
contained a piece of code that was presumably your latest attempt. It
was counter to the way the module's call syntax is supposed to be
given. It bared no resemblence to any fix suggested by the error
message. Further, your original post made absolutely no mention of the
original attempt, or of the error message that you later told us it
gave you.
It's an assumption, based on evidence presented by your posts. Not an> The arrogance of that assertion is
assertion.
I'm sorry you felt insulted.>, of course, insulting.
Okay. Please explain to me what you did when you saw that error> The fact that it's false doesn't really bother me.
message. Because your apparent next attempt at the module call
certainly had nothing to do with anything the error message told you.
I'm really not interested in getting into an argument about this, so
this will be my last message in this thread. You're welcome to have
the last word.
Paul Lalli
Paul Lalli Guest
-
Sisyphus #9
Re: The 'if' module
"Paul Lalli" <mritty@gmail.com> wrote in messageYeah - but I read that as an unqualified assertion rather than an assumption>> >
> > I "chose to disregard it" ??
> It's an assumption, based on evidence presented by your posts. Not an
> assertion.
(and I still do read it that way) - and that's what really irked me. Still -
I shouldn't have snapped - and I apologise for so doing.
Well - you'll note that "my next attempt at the module call" added an extra>
> Okay. Please explain to me what you did when you saw that error
> message. Because your apparent next attempt at the module call
> certainly had nothing to do with anything the error message told you.
>
argument - which *did* have something to do with what the error message told
me. Not only that, but it worked to the extent that the script compiled
without any warnings being issued, and behaved as expected - iff CONDITION
was true. I think I was also sucked in by my own (false) assumption that I
knew what "use if CONDITION" (from the docs) meant. I was therefore lead to
concentrate on the "MODULE => ARGUMENTS" bit (which I wasn't sure about).
Beyond that I don't see much point in providing details on my (flawed)
thought processes.
Anyway - thanks again for the original explanation. The elaboration I
provided in my follow-up was meant simply to demonstrate that I understood
the points you had made.
Cheers,
Rob
Sisyphus Guest
-
Ilya Zakharevich #10
Re: The 'if' module
[A complimentary Cc of this posting was sent to
Sisyphus
<sisyphus1@nomail.afraid.org>], who wrote in article <4482c365$0$16769$afc38c87@news.optusnet.com.au> :I do. A little bit of history: when I designed if.pm, I had no the>> > Okay. Please explain to me what you did when you saw that error
> > message. Because your apparent next attempt at the module call
> > certainly had nothing to do with anything the error message told you.
> >
> Well - you'll note that "my next attempt at the module call" added an extra
> argument - which *did* have something to do with what the error message told
> me. Not only that, but it worked to the extent that the script compiled
> without any warnings being issued, and behaved as expected - iff CONDITION
> was true. I think I was also sucked in by my own (false) assumption that I
> knew what "use if CONDITION" (from the docs) meant. I was therefore lead to
> concentrate on the "MODULE => ARGUMENTS" bit (which I wasn't sure about).
>
> Beyond that I don't see much point in providing details on my (flawed)
> thought processes.
idea that CONDITION is subject to cryptocontext. When somebody
reported this behaviour as a bug, the best "solution" I got was to try
to detect this situation (only possible when module is called without
arguments!), and provide a readable error message.
The current error message may be improved a lot. I welcome everybody
to think the message over and try to make it more clear. Likewise,
for
use if CONDITION, strict => 'refs';
with CONDITION returning en empty list, what the module sees is
CONDITION := 'strict', MODULE := 'refs'. Since there is no refs.pm,
the if.pm could also detect this, and emit a similar message.
Patches welcome,
Ilya
Ilya Zakharevich Guest



Reply With Quote

