Hi Owen,

On Saturday 30 October 2010 20:56:57 Owen Chavez wrote:
> A straightforward question I hope.
> 
> Can someone explain why the following code runs without a hitch:
> 
> #!C:/strawberry/perl/bin/perl.exe
> use strict;
> use warnings;
> 
> my $testvar = "TEST";
> &testsub1();

Don't use leading ampersands in subroutine calls:

http://perl-begin.org/tutorials/bad-elements/#ampersand-in-subroutine-calls

Also go over the rest of the page
> 
> sub testsub1 {
> print "The following should read \"TEST\": $testvar \n";
> }
> 
> 

The difference between the two examples is that in the first one you've 
declared the lexical variable "$testvar" before its first use in the code, and 
in the second one you've declared it afterwards. This is not allowed by "use 
strict;". You'll get a similar warning if you do:

[code]
sub my_subroutine
{
        print $myvar, "\n";
        my $myvar = "One Two";
}
[/code]

Same thing really.

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
"Star Trek: We, the Living Dead" - http://shlom.in/st-wtld

<rindolf> She's a hot chick. But she smokes.
<go|dfish> She can smoke as long as she's smokin'.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to