Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > strict and warnings

Reply
Thread Tools

strict and warnings

 
 
Robin
Guest
Posts: n/a
 
      01-21-2004
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



 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      01-21-2004
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


 
Reply With Quote
 
 
 
 
Robin
Guest
Posts: n/a
 
      01-21-2004


"Jürgen Exner" <(E-Mail Removed)> wrote in message
news:g3mPb.31317$(E-Mail Removed)...
> 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


 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      01-21-2004
Robin wrote:
> "Jürgen Exner" <(E-Mail Removed)> wrote in message
> news:g3mPb.31317$(E-Mail Removed)...
>> 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


 
Reply With Quote
 
Robin
Guest
Posts: n/a
 
      01-21-2004
7

"Jürgen Exner" <(E-Mail Removed)> wrote in message
news:hXmPb.5147$(E-Mail Removed)...
> Robin wrote:
> > "Jürgen Exner" <(E-Mail Removed)> wrote in message
> > news:g3mPb.31317$(E-Mail Removed)...
> >> 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


 
Reply With Quote
 
Jonathan Stowe
Guest
Posts: n/a
 
      01-21-2004
Robin <(E-Mail Removed)> wrote:
>
> "J?rgen Exner" <(E-Mail Removed)> wrote in message
> news:g3mPb.31317$(E-Mail Removed)...
>> 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\
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
H-P employees,stockholders ,clients and Security Clearance officers :Open letter , questions and warnings about the next CEO financialtools1 Computer Security 0 10-04-2010 06:57 PM
Style sheets and XML Strict =?Utf-8?B?RHlsYW4gVGhvbWFz?= ASP .Net 2 03-22-2005 07:18 PM
Is it correct that strict and warnings will not apply to checking the code in MYCLASS? ioneabu@yahoo.com Perl Misc 1 01-06-2005 05:45 PM
use warnings; and use Warnings; give different results Ted Sung Perl Misc 1 08-30-2004 10:22 PM
Using strict and warnings in embedded perl Suresh Govindachar Perl Misc 0 07-14-2004 03:11 AM



Advertisments