strict and warnings

Discussion in 'Perl Misc' started by Robin, Jan 21, 2004.

  1. Robin

    Robin Guest

    btw, I am reading this stuff.

    I still don't understand strict and warnings...
    I'm kinda a newbie...
    can someone explain if this is right... whe you use strict, you have to
    define your variables and then call your subroutines without ands (&) and
    when you use strict and warnings together it will allow you to call your
    subrountines this way, is there anything else you have to do once your using
    strict and/or warnings?

    Thanks,
    -Robin
     
    Robin, Jan 21, 2004
    #1
    1. Advertising

  2. Robin wrote:
    > I still don't understand strict and warnings...
    > I'm kinda a newbie...
    > can someone explain if this is right... whe you use strict, you have
    > to define your variables


    Yes

    > and then call your subroutines without ands
    > (&)


    Has nothing to do with strictures

    > and when you use strict and warnings together it will allow you
    > to call your subrountines this way,


    Which way?

    > is there anything else you have
    > to do once your using strict and/or warnings?


    Why don't you check the documentation:

    perldoc strict
    perldoc warnings

    jue
     
    Jürgen Exner, Jan 21, 2004
    #2
    1. Advertising

  3. Robin

    Robin Guest

    "Jürgen Exner" <> wrote in message
    news:g3mPb.31317$...
    > Robin wrote:
    > > I still don't understand strict and warnings...
    > > I'm kinda a newbie...
    > > can someone explain if this is right... whe you use strict, you have
    > > to define your variables

    >
    > Yes
    >
    > > and then call your subroutines without ands
    > > (&)

    >
    > Has nothing to do with strictures
    >
    > > and when you use strict and warnings together it will allow you
    > > to call your subrountines this way,

    >
    > Which way?


    the way I mentioned before... without operands...
    thanks,
    -Robin
     
    Robin, Jan 21, 2004
    #3
  4. Robin wrote:
    > "Jürgen Exner" <> wrote in message
    > news:g3mPb.31317$...
    >> Robin wrote:
    >>> and then call your subroutines without ands
    >>> (&)
    >>> and when you use strict and warnings together it will allow you
    >>> to call your subrountines this way,

    >
    > the way I mentioned before... without operands...


    From perldoc perlsub:

    To call subroutines:

    NAME(LIST); # & is optional with parentheses.
    NAME LIST; # Parentheses optional if predeclared/imported.
    &NAME(LIST); # Circumvent prototypes.
    &NAME; # Makes current @_ visible to called subroutine.
    [...]
    A subroutine may be called using an explicit "&" prefix. The "&" is
    optional in modern Perl, as are parentheses if the subroutine has been
    predeclared. The "&" is *not* optional when just naming the subroutine,
    such as when it's used as an argument to defined() or undef(). Nor is it
    optional when you want to do an indirect subroutine call with a
    subroutine name or reference using the "&$subref()" or "&{$subref}()"
    constructs, although the "$subref->()" notation solves that problem. See
    the perlref manpage for more about all that.

    Subroutines may be called recursively. If a subroutine is called using
    the "&" form, the argument list is optional, and if omitted, no "@_"
    array is set up for the subroutine: the "@_" array at the time of the
    call is visible to subroutine instead. This is an efficiency mechanism
    that new users may wish to avoid.

    &foo(1,2,3); # pass three arguments
    foo(1,2,3); # the same

    foo(); # pass a null list
    &foo(); # the same

    &foo; # foo() get current args, like foo(@_) !!
    foo; # like foo() IFF sub foo predeclared, else "foo"

    Not only does the "&" form make the argument list optional, it also
    disables any prototype checking on arguments you do provide. This is
    partly for historical reasons, and partly for having a convenient way to
    cheat if you know what you're doing. See the Prototypes manpage below.

    jue
     
    Jürgen Exner, Jan 21, 2004
    #4
  5. Robin

    Robin Guest

    7

    "Jürgen Exner" <> wrote in message
    news:hXmPb.5147$...
    > Robin wrote:
    > > "Jürgen Exner" <> wrote in message
    > > news:g3mPb.31317$...
    > >> Robin wrote:
    > >>> and then call your subroutines without ands
    > >>> (&)
    > >>> and when you use strict and warnings together it will allow you
    > >>> to call your subrountines this way,

    > >
    > > the way I mentioned before... without operands...

    >
    > From perldoc perlsub:
    >
    > To call subroutines:
    >
    > NAME(LIST); # & is optional with parentheses.
    > NAME LIST; # Parentheses optional if predeclared/imported.
    > &NAME(LIST); # Circumvent prototypes.
    > &NAME; # Makes current @_ visible to called subroutine.
    > [...]
    > A subroutine may be called using an explicit "&" prefix. The "&" is
    > optional in modern Perl, as are parentheses if the subroutine has been
    > predeclared. The "&" is *not* optional when just naming the

    subroutine,
    > such as when it's used as an argument to defined() or undef(). Nor is

    it
    > optional when you want to do an indirect subroutine call with a
    > subroutine name or reference using the "&$subref()" or "&{$subref}()"
    > constructs, although the "$subref->()" notation solves that problem.

    See
    > the perlref manpage for more about all that.
    >
    > Subroutines may be called recursively. If a subroutine is called using
    > the "&" form, the argument list is optional, and if omitted, no "@_"
    > array is set up for the subroutine: the "@_" array at the time of the
    > call is visible to subroutine instead. This is an efficiency mechanism
    > that new users may wish to avoid.
    >
    > &foo(1,2,3); # pass three arguments
    > foo(1,2,3); # the same
    >
    > foo(); # pass a null list
    > &foo(); # the same
    >
    > &foo; # foo() get current args, like foo(@_) !!
    > foo; # like foo() IFF sub foo predeclared, else

    "foo"
    >
    > Not only does the "&" form make the argument list optional, it also
    > disables any prototype checking on arguments you do provide. This is
    > partly for historical reasons, and partly for having a convenient way

    to
    > cheat if you know what you're doing. See the Prototypes manpage below.
    >
    > jue
    >

    Thanks...Robin
     
    Robin, Jan 21, 2004
    #5
  6. Robin <> wrote:
    >
    > "J?rgen Exner" <> wrote in message
    > news:g3mPb.31317$...
    >> Robin wrote:
    >> > I still don't understand strict and warnings...
    >> > I'm kinda a newbie...
    >> > can someone explain if this is right... whe you use strict, you have
    >> > to define your variables

    >>
    >> Yes
    >>
    >> > and then call your subroutines without ands
    >> > (&)

    >>
    >> Has nothing to do with strictures
    >>
    >> > and when you use strict and warnings together it will allow you
    >> > to call your subrountines this way,

    >>
    >> Which way?

    >
    > the way I mentioned before... without operands...
    >


    Er, I think you mean *ampersands*. But that is besides the point. The
    use of the strict or warning pragmas has no bearing on how you call your
    subroutines with one exception, that is if you call a subroutine as
    a bareword (i.e. without ampersand or parentheses) before the
    declaration of the subroutine in the program file when strict is in
    operation you will get get a different error message than if it isn't
    i.e :

    Bareword "foo" not allowed while "strict subs" in use at strict.pl line
    4.
    Execution of strict.pl aborted due to compilation errors.

    With strict, and

    Unquoted string "foo" may clash with future reserved word at strict.pl
    line 5.
    Useless use of a constant in void context at strict.pl line 5.

    Without.

    Just do it. Lose the ampersands and use parentheses instead and then use
    strict and warnings and fix all the problems they throw up and you'll
    feel so much better for it.

    /J\
     
    Jonathan Stowe, Jan 21, 2004
    #6
    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. Suresh Govindachar

    Using strict and warnings in embedded perl

    Suresh Govindachar, Jul 14, 2004, in forum: Perl Misc
    Replies:
    0
    Views:
    128
    Suresh Govindachar
    Jul 14, 2004
  2. Ted Sung
    Replies:
    1
    Views:
    333
    Sherm Pendley
    Aug 30, 2004
  3. Replies:
    1
    Views:
    108
    Paul Lalli
    Jan 6, 2005
  4. Marius Gavrilescu

    Re: use strict; use warnings;

    Marius Gavrilescu, Feb 24, 2014, in forum: Perl Misc
    Replies:
    152
    Views:
    590
    $Bill
    Mar 11, 2014
  5. Kaz Kylheku

    Re: use strict; use warnings;

    Kaz Kylheku, Feb 24, 2014, in forum: Perl Misc
    Replies:
    0
    Views:
    76
    Kaz Kylheku
    Feb 24, 2014
Loading...

Share This Page