[Pdx-pm] What am I doing wrong?

Joshua Keroes joshua at keroes.com
Thu Dec 1 11:01:22 PST 2011


"use strict" will complain when you use a new variable; that is, a variable
that you haven't predeclared using the "my" keyboard.  This is well and
good and leads to better code.

The first program probably works because $a and $b are special: they're
predeclared for use by the sort() function.  $v1 and $v2 in the second
program are not.

In all cases, you want to replace your variable declarations ($this =
"that") with a definition and declaration (my $this = "that") - and that
goes for both programs.

-Joshua

2011/11/30 Art Burke <Art.Burke at educationnorthwest.org>

> I just installed ActivePerl and am trying it out.  ****
>
> ** **
>
> This runs fine:****
>
> ** **
>
> #!/usr/bin/perl****
>
> ** **
>
> use 5.006;****
>
> use strict;****
>
> use warnings;****
>
> ** **
>
> $a = 6;****
>
> $b = 7;****
>
> print (($a*$b), "\n");****
>
> ** **
>
> The script below fails with a message that “Global symbol “$v1” requires
> explicit package name …”. Could someone tell me what I am doing wrong?****
>
> ** **
>
> #!/usr/bin/perl****
>
> ** **
>
> use 5.006;****
>
> use strict;****
>
> use warnings;****
>
> ** **
>
> $v1 = 6;****
>
> $v2 = 7;****
>
> print (($v1*$v2), "\n");****
>
> ** **
>
> Thanks!****
>
> Art****
>
> _______________________________________****
>
> Arthur J. Burke****
>
> Senior Methodology Advisor****
>
> Education Northwest****
>
> 101 SW Main St, Suite 500****
>
> Portland OR 97204-3213****
>
> Art.Burke at educationnorthwest.org****
>
> Phone: 503-275-9592****
>
> http://educationnorthwest.org****
>
> ** **
>
> Need help finding evidence-based answers to questions about education
> practices, policies, or programs? Take advantage of our *free reference
> desk service *offered by our *REL Northwest* project. Contact
> Jennifer Klump at http://askarel.org/northwest for prompt, authoritative,
> and customized answers to your questions. ****
>
> ** **
>
> ** **
>
> _______________________________________________
> Pdx-pm-list mailing list
> Pdx-pm-list at pm.org
> http://mail.pm.org/mailman/listinfo/pdx-pm-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/pdx-pm-list/attachments/20111201/0e377d39/attachment-0001.html>


More information about the Pdx-pm-list mailing list