[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] unknown error question



At 9.21 -0400 1999.06.10, Robert Pollard wrote:
>You know I tried to figure out why it would complain about the variable
>being used only once when MacPerl doesn't require you to declare
>variables there is a possibility that you would only use the variable
>once.

That's why it is only a warning under -w, not an error.


>BTW this is all of the code.  I was having the warning in some other code
>and decided to paste it into a new window and try it.  So,  I guess what
>I am saying is, this doesn't make sense.

I don't understand what doesn't make sense.  Perl's behavior is that if you
only use a variable once, and you use -w, it will warn you.  This is what
it is supposed to do.  If you don't like it, then work around it:

   # no warning
   $holdingThing = $holdingThing = 'Backup Folder';

In my experience, it is very rare to ever have a variable used only once in
a program.  When it actually does happen, you either remove -w, work around
it, or ignore the warning.


>One of the respondents mentioned the keyword "my."  Am I to understand
>this is a way of declaring local variables?  I have looked for it in
>documentation but haven't run across it yet.  I use Chris & Vicki's book
>and the on-line documentation.

It is in there.  Look in perlfunc, any function reference (including the
book), and in perlsub.  Command-click on "my" in the MacPerl program, or
type it in Shuck's "Lookup" dialog box.  Look on page 113 of the MacPerl
book for a discussion, and 291 for a reference (both are in the book's
index under "my").

my() does NOT make a variable local, it declares it as lexical.  Some
people might call that local, but since we have a local() in Perl which
makes the value of a given variable dynamically scoped, "local" does not
mean "lexical" to most people in Perl circles.

--
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org