Ask a Question related to PERL Modules, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. 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...
    4. 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...
    5. 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...
  3. #2

    Default 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

  4. #3

    Default Re: The 'if' module

    Sisyphus wrote:
    > 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" ?
    I have no idea.

    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

  5. #4

    Default Re: The 'if' module

    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";
    > 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" ?
    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).

    use if scalar($^O =~ /another/), "Non::Existent";

    should do what you want.

    Paul Lalli

    Paul Lalli Guest

  6. #5

    Default Re: The 'if' module


    "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.
    >
    > 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


    Sisyphus Guest

  7. #6

    Default Re: The 'if' module

    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 confused as to why you chose to
    disregard it and instead change the syntax of your module call
    syntax...

    Paul Lalli

    Paul Lalli Guest

  8. #7

    Default Re: The 'if' module


    "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...
    > > > 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 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.
    > 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" ??

    The arrogance of that assertion is, of course, insulting. The fact that it's
    false doesn't really bother me.

    Cheers,
    Rob


    Sisyphus Guest

  9. #8

    Default Re: The 'if' module

    Sisyphus wrote:
    > "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.
    'some code' on line 2, which was:
    use if $^O =~ /another/, "Non::Existent";
    Exactly how many parts of that code do you think can return an empty
    list in list context?
    > > 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" ??
    Sure seems that way to me. Your original message to this newsgroup
    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.
    > The arrogance of that assertion is
    It's an assumption, based on evidence presented by your posts. Not an
    assertion.
    >, of course, insulting.
    I'm sorry you felt insulted.
    > The fact that it's false doesn't really bother me.
    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.

    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

  10. #9

    Default Re: The 'if' module


    "Paul Lalli" <mritty@gmail.com> wrote in message
    > >
    > > I "chose to disregard it" ??
    >
    > It's an assumption, based on evidence presented by your posts. Not an
    > assertion.
    Yeah - but I read that as an unqualified assertion rather than an assumption
    (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.
    >
    > 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.

    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

  11. #10

    Default 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> :
    > > 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.
    I do. A little bit of history: when I designed if.pm, I had no the
    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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139