Loading ...
Sorry, an error occurred while loading the content.

Re: auto-vivify?

Expand Messages
  • perlmedian
    This will get confusing, so I will try to reference some docs. ... It gets generated on the fly. ... Depends where the use strict is. use has a scope too.
    Message 1 of 2 , Jul 2, 2003
    • 0 Attachment
      This will get confusing, so I will try to reference some docs.
      See in-line comments:

      --- In perl-beginner@yahoogroups.com, <greg.hering@b...> wrote:
      > What is happening when I push onto an array I haven't declared?

      It gets generated on the fly.

      >
      > I thought with 'use strict' you had to use the 'my' operator first.

      Depends where the 'use strict' is. 'use' has a scope too. If you put
      it on top of the script file it's scope is to the end of the file.
      If your package is in another file, it would need its own 'use
      strict' for it to be inforced.

      > I also thought I had to 'bless Path, \$HostComm' but I didn't and
      it seems that the data survived 'going out of scope'.

      take a look at 'our' or 'use vars' and 'my' and 'local' basically you
      don't have to bless everything into something. You can have local
      globals that you could use when hacking out a module for testing
      purposes. But I wouldn't recommend it (unless you really need to).

      Have you read the 'perldoc perltoot' ?

      >
      > This code is in a method in a derived object. I do a new and then
      call this, so I guess the new object isn't really going out of scope,
      just lexicals inside getConfig(). But since I didn't bless it's not
      object data the correct way.
      >
      > Package HostComm;
      > @ISA = qw(Mycomm); # Which inherit from Net::FTP
      >
      > sub getConfig {
      > .
      > .
      > .
      > if (ref($dir_names) eq "ARRAY") {
      > foreach my $hash (@$dir_names) {
      > push(@HostComm::Path, $hash->{name});
      > print "$$hash{name}\n";
      > }
      > }
      > }
      >
      > I'm doing a
      > my $ftp = HostComm->new( login stuff );
      > ftp->getConfig() #here's where I call the
      foreach ... push
      >
      > foreach my $path2 (@HostComm::Path) {
      > printf "foreach Path %s\n", $path2;
      > }
      >
      >
      > The data is still there but this looks klunky. I'm still reading
      but I know I'm in over my head!!!
      >
      > Greg :o)
      >

      You need specify what your goal with this is. Sorry it just doesn't
      pop out at me.
    Your message has been successfully submitted and would be delivered to recipients shortly.