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

Re: [MacPerl] Style Guidelines



At 10:50 PM on 6/19/96, you wrote in "[MacPerl] Style Guidelines":

>I'm finding difficulty keeping my name spaces straight between subroutines
>and global variables.
>
>I've looked at several Perl style guides, but haven't seen anything
>definitive about naming variables, other the file handles in upper case.
>
>Is it OK - recommended - not recommended to do things like
>All global variables start with upper case letter
>All local variables start with _

hi,

soubroutines and scalers (and filehandles and arrays and hashes and
formats) all have different namespaces, so you don't have to worry about
the stuff like you mentioned above.

the reason why people use uppercase for filehandles (and others) is that
any words that Perl reserves are lowercase (like functions and statements),
so it is safe to choose uppercase filehandles so that you don't get a fatal
error.

global variables have nothing to do with namespaces. global variables mean
that the variables are available throughout the script/program, as opposed
to local variables, which is available to only the enclosing block (like
subroutine, eval, package, if, etc.).

so the following is legal.
$myvar = "something";
@myvar = ($myvar, "other thing");
%myvar{$myvar} = $myvar[1];
&myvar;
sub myvar {
   open (myvar, ">/usr/myvar") || die;
   #...
}

hope this helps.

--Akira

~~~~~~~~~~~~~~~~~~~~~~~~~  AKIRA HANGAI ~~~~~~~~~~~~~~~~~~~~~~~~~
akira@ecnet.com
http://www.ecnet.com/home/akira/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
No longer riding on the merry-go-round, I just have to let it go.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~