use warnings unless $foo

Discussion in 'Perl Misc' started by Florian Kaufmann, Mar 20, 2009.

  1. use, no, package are special in that I can not say

    use warnings if $foo;

    Is there a name for those keywords which do not form a normal
    expression? I.e. where I can not append a statement modifier.

    Where in the perldoc do I find a complete list of those keywords?

    Thank you

    Flo
     
    Florian Kaufmann, Mar 20, 2009
    #1
    1. Advertising

  2. Florian Kaufmann <> wrote:
    >use, no, package are special in that I can not say
    >
    >use warnings if $foo;


    Well, yes, you can. But it doesn't do what you seem to expect it to do.
    use() is executed at compile time because it is a short form of
    BEGIN { require Module; import Module LIST; }

    If you don't want that but want it to be executed at compile time after
    evaluating and assessing $foo then just use the block without the
    BEGIN/END:
    if $foo then {require warnings; import warnings;}

    >Is there a name for those keywords which do not form a normal
    >expression? I.e. where I can not append a statement modifier.


    Missleading way of thinking. The problem is It is not that you can't
    statement modifiers, it is that
    >Where in the perldoc do I find a complete list of those keywords?
    >
    >Thank you
    >
    >Flo
     
    Jürgen Exner, Mar 21, 2009
    #2
    1. Advertising

  3. Jürgen Exner <> wrote:
    [Sorry, hit the wrong button]
    >Florian Kaufmann <> wrote:
    >>use, no, package are special in that I can not say
    >>
    >>use warnings if $foo;

    >
    >Well, yes, you can. But it doesn't do what you seem to expect it to do.
    >use() is executed at compile time because it is a short form of
    > BEGIN { require Module; import Module LIST; }
    >
    >If you don't want that but want it to be executed at compile time after
    >evaluating and assessing $foo then just use the block without the
    >BEGIN/END:
    > if $foo then {require warnings; import warnings;}
    >
    >>Is there a name for those keywords which do not form a normal
    >>expression? I.e. where I can not append a statement modifier.


    Misleading way of thinking. The problem is NOT that you couldn't
    use statement modifiers. The problem is that that BEGIN/END enforces
    execution at compile time, i.e. before perl had any chance to look at
    the condition 'if $foo'.

    >>Where in the perldoc do I find a complete list of those keywords?


    About the fourth line of
    perldoc -f use

    As for where to find "BEGIN/END": that's a good question :) I couldn't
    find an entry after a brief search.

    jue
     
    Jürgen Exner, Mar 21, 2009
    #3
  4. > Well, yes, you can. But it doesn't do what you seem to expect it to do.

    Apparently not:

    $ perl -e 'use warnings if $foo'
    syntax error at -e line 1, near "use warnings if"
    Execution of -e aborted due to compilation errors.
    $ perl --version

    This is perl, v5.10.0 built for i486-linux-gnu-thread-multi

    It's not that I currently wan't to do such sort of thing, I just want
    to learn Pearl properly. But you mentioned the right thing: use, no,
    package happen at compile time. So I ask another way round: Is there a
    complete list of things (keywords?) that happen at compile time, and
    thus can't have a statement modifier. Is there a name for the group of
    such things?

    Flo
     
    Florian Kaufmann, Mar 21, 2009
    #4
  5. Florian Kaufmann <> wrote in news:53fe0fcb-e404-47e1-
    :

    > use, no, package are special in that I can not say
    >
    > use warnings if $foo;


    perldoc if

    Example:

    C:\Temp> cat t.pl
    #!/usr/bin/perl

    use if $ENV{STRICT}, 'strict';
    use if $ENV{WARNINGS}, 'warnings';

    print "$x = something\n";

    __END__

    C:\Temp> t
    = something

    C:\Temp> t
    Name "main::x" used only once: possible typo at C:\Temp\t.pl line 6.
    Use of uninitialized value $x in concatenation (.) or string at C:\Temp
    \t.pl line 6.
    = something

    C:\Temp> set strict=1

    C:\Temp> t
    Global symbol "$x" requires explicit package name at C:\Temp\t.pl line
    6. Execution of C:\Temp\t.pl aborted due to compilation errors.

    Sinan

    --
    A. Sinan Unur <>
    (remove .invalid and reverse each component for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://www.rehabitation.com/clpmisc/
     
    A. Sinan Unur, Mar 21, 2009
    #5
  6. Jürgen Exner <> wrote:

    > As for where to find "BEGIN/END": that's a good question :) I couldn't
    > find an entry after a brief search.



    See the "BEGIN, CHECK, INIT and END" section in perlmod.pod.

    Took me less than two seconds to find it, because of the indexes
    I've created as described at the end of the Perl problem resolution checklist:

    http://groups.google.com/groups/search?as_umsgid=


    I don't actually do the "cd ..." part, I've defined an alias for that.

    So I just did:

    gopod
    grep BEGIN all.heads


    :)


    --
    Tad McClellan
    email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
     
    Tad J McClellan, Mar 21, 2009
    #6
  7. Jürgen Exner <> wrote:
    > Florian Kaufmann <> wrote:



    >>use warnings if $foo;

    >
    > Well, yes, you can. But it doesn't do what you seem to expect it to do.
    > use() is executed at compile time because it is a short form of
    > BEGIN { require Module; import Module LIST; }
    >
    > If you don't want that but want it to be executed at compile time after

    ^^^^^^^^^^^^

    s/compile time/run time/;


    > evaluating and assessing $foo then just use the block without the
    > BEGIN/END:
    > if $foo then {require warnings; import warnings;}



    --
    Tad McClellan
    email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
     
    Tad J McClellan, Mar 21, 2009
    #7
  8. Florian Kaufmann <> wrote:


    Please choose one posting address, and stick to it.


    > It's not that I currently wan't to do such sort of thing



    It's not that you currently wa not to do such sort of thing?


    --
    Tad McClellan
    email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
     
    Tad J McClellan, Mar 21, 2009
    #8
  9. On 2009-03-21, Jürgen Exner <> wrote:
    >>>use warnings if $foo;


    >>>Is there a name for those keywords which do not form a normal
    >>>expression? I.e. where I can not append a statement modifier.


    > Misleading way of thinking. The problem is NOT that you couldn't
    > use statement modifiers. The problem is that that BEGIN/END enforces
    > execution at compile time, i.e. before perl had any chance to look at
    > the condition 'if $foo'.


    This is not fully kosher explanation. Note that arguments to `use'
    ARE executed at compile time. Why not if/unless conditions?

    Note that this bug in Perl has a fix - for about a decade. It is just
    that some %@$#$* rejected my patch which fixed this bug.

    Thus I needed to created this `use if ...' ugliness...

    Hope this helps,
    Ilya
     
    Ilya Zakharevich, Mar 21, 2009
    #9
  10. Florian Kaufmann

    Guest

    On Sat, 21 Mar 2009 10:30:50 -0500, Tad J McClellan <> wrote:

    >Florian Kaufmann <> wrote:
    >
    >
    >Please choose one posting address, and stick to it.
    >
    >
    >> It's not that I currently wan't to do such sort of thing

    >
    >
    >It's not that you currently wa not to do such sort of thing?


    I just wan't to say Tad, you should learn English because I do'nt
    think yo've been to school lately.

    -sln
     
    , Mar 22, 2009
    #10
  11. Florian Kaufmann

    Guest

    On Fri, 20 Mar 2009 13:08:10 -0700 (PDT), Florian Kaufmann <> wrote:

    >use, no, package are special in that I can not say
    >
    >use warnings if $foo;
    >
    >Is there a name for those keywords which do not form a normal
    >expression? I.e. where I can not append a statement modifier.
    >
    >Where in the perldoc do I find a complete list of those keywords?
    >
    >Thank you
    >
    >Flo


    Yeah, isin't some use's pragmata though? If not then all pragmata are
    packages then. How bizzare.. Never get what you wan't huh. Not out of Perl.
    If you did, there would be no air time for the hackers with no jobs here.

    -sln
     
    , Mar 22, 2009
    #11
    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. Replies:
    3
    Views:
    407
    John Roth
    Jul 29, 2005
  2. .rhavin grobert

    vector: Foo[5] == ((foo*)Foo) + 5 ?

    .rhavin grobert, Sep 23, 2008, in forum: C++
    Replies:
    4
    Views:
    421
    JaredGrubb
    Sep 24, 2008
  3. Gábor SEBESTYÉN

    Unless unless

    Gábor SEBESTYÉN, Jun 17, 2005, in forum: Ruby
    Replies:
    3
    Views:
    178
    Gábor SEBESTYÉN
    Jun 17, 2005
  4. Ted Sung
    Replies:
    1
    Views:
    346
    Sherm Pendley
    Aug 30, 2004
  5. Replies:
    4
    Views:
    172
    Thomas 'PointedEars' Lahn
    Dec 23, 2007
Loading...

Share This Page