I am under the impression that my is for the following:


my $var = 'Whatever';

sub Hey
{
  print $var;
}

Shouldn't print anything...  my is local scope without recursion.  I know
that this works for subroutines.  Declaring a variable local makes a copy
of the variable.  While declaring a variable with $my makes a new variable.

So declaring global variables with my means that subroutines can't change
them.  Declaring local means subroutines and any *child* elements of the current
package can change them.  So there are a few subtle differences.  If someone
can explain this better then please do.  I'm a perl novice at the most.

    - Justin Rogers, CEO DigiTec Web Consultants
    [COOP]DigiTec - Half-Life, Q3A, Unreal Tournament
----- Original Message -----
From: "Aaron" <[EMAIL PROTECTED]>
To: "Perl-Win32-Users Mailing List" <[EMAIL PROTECTED]>
Sent: Saturday, May 13, 2000 10:22 AM
Subject: Why So Much My? (was Re: Finding Latest File)


> I was under the impression that the reason for using
> "my" to declare a variable was to make it act like a
> local variable in a sub-routine or loop.  Once you
> leave the sub or loop, the variable ceases to exist,
> thus making your script more efficient, easier to
> debug, and more flexible.
>
> But, I have yet to understand what the benefit of
> using my on, what I would consider to be, "global"
> variables.  Won't the vars in the "main" part of the
> script get destroyed upon completion?
>
> Alas...I suppose some caring person may wish to impart
> this knowledge to me.  :)
>
> > Your technique is not something to pass on IMHO.
> > A couple of changes may be appropriate or necessary:
> >
> >   use strict;
> >
> > > opendir LD,".\";
> >
> >   opendir LD, '.' or die "Error on opendir: $!\n";      #
> >
> > > @files = readdir LD;
> >
> >   my @files = readdir LD;
> >
> > > closedir LD;
> > >
> > > $y = 0;
> >
> >   my $y = 0;
> >   my $new_file = '';
> >
> > > foreach $f (@files) {
> >
> >   foreach my $f (@files) {
> >
> >     next if $f !~ /^www\d+\.txt$/;      # drop non-conforming files
> >
> > >
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blo
cks)
> > > = stat($f);
> >
> >     my $mtime = (stat $f)[9];   # much simpler
> >
> > >     if($mtime > $y && -f $f) {
> > >         $new_file = $f;
> > >         $y = $mtime
> > >     }
> > > }
> > > print("$new_file\n");
> >
> > Now you can copy it to the new dir.
> >
> > --
> >   ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
> >  (_/   /  )    // //       DBE Collectibles   http://www.wgn.net/~dbe/
> >   / ) /--<  o // //      Mailto:[EMAIL PROTECTED]   http://dbecoll.webjump.com/
> > -/-' /___/_<_</_</_    http://www.freeyellow.com/members/dbecoll/
> >
> > ---
> > You are currently subscribed to perl-win32-users as: [EMAIL PROTECTED]
> > To unsubscribe, forward this message to
> >          [EMAIL PROTECTED]
> > For non-automated Mailing List support, send email to
> >          [EMAIL PROTECTED]
>
> --
>
> -------- Aaron Rainwater ---------
> | Only two things are infinite:  |
> | the universe & stupidity...    |
> | I'm not sure about the former. |
> | ~ Albert Einstein              |
> ----------------------------------
>
> ---
> You are currently subscribed to perl-win32-users as: [EMAIL PROTECTED]
> To unsubscribe, forward this message to
>          [EMAIL PROTECTED]
> For non-automated Mailing List support, send email to
>          [EMAIL PROTECTED]
>
>


---
You are currently subscribed to perl-win32-users as: [archive@jab.org]
To unsubscribe, forward this message to
         [EMAIL PROTECTED]
For non-automated Mailing List support, send email to  
         [EMAIL PROTECTED]

Reply via email to