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

RE: [PBML] Re: auto-vivify?

Expand Messages
  • greg.hering@bench.com
    Dear perlmedian, Are you saying that @HostComm::Path does NOT refer to a variable called @Path in the HostComm package? A package rather than a lexical
    Message 1 of 3 , Jul 2 3:00 PM
    • 0 Attachment
      Dear perlmedian,

      Are you saying that @HostComm::Path does NOT refer to a variable called '@Path' in the HostComm package? A 'package' rather than a 'lexical' variable? But I though that 'use strict' was supposed to force you to make all your variables lexical by requiring 'my'.

      And still I'm so new at creating the member variables inside the class that I'm not sure about what I'm doing. I know 'get' and 'set' methods are coming. I'm just not there yet.

      And YES your
      foreach my $path2 ( $ftp->GetPaths() ) {
      line is
      definitely where I want to go. Very 'object' methodology.


      > # I assume you have something like:
      > my ($self) = @_; # here is your $ftp object

      Actually it looks like:

      sub getConfigFile
      {
      my $class = shift;
      my $srcDir = @_ > 1 ? shift(@_) : "/";
      my $destDir = @_ > 2 ? shift(@_) : "/tmp";
      my $fileToGet = "hostconfig.xml";
      .
      .
      .

      But don't I have to do something in the constructor like

      My $self = { @Path = (); }

      bless $self, ref($class) || $class;

      to 'create' a valid object member variable, before I can

      > push (@{$self->{Path}}, $hash->{name});

      yes? And I know that syntax is incorrect and it causes the GLOB prob for my ancestor.

      To make matters worse, my ancestry is like this:

      Net::FTP
      MyFTPthing has 'new' and 'getFiles'
      HostThing has getConfigFile - calls SUPER::getFiles

      And so far, the 'HostThing' just does the specialized getFiles with knowledge of To, From, and Name. So my constructor/destructor for HostThing is defaulted to the parent object MyFTPthing.

      I guess I should be making a constructor with the 'bless $self' in HostThing so I can create the @Path there, or is @Path still accessible
      via @{$self->{Path}} using inheritance from HostThing if I create it in the parent MyFTPthing?

      Thanks,

      Greg


      Gregory L. Hering
      (256) 722-6420
      4807 Bradford Dr
      Benchmark Electronics, Inc.
      Huntsville, Al 35805


      -----Original Message-----
      From: perlmedian [mailto:perlmedian@...]
      Sent: Wednesday, July 02, 2003 4:36 PM
      To: Hering, Greg
      Subject: [PBML] Re: auto-vivify?

      Ah... They why aren't you storing the paths to your object? Something
      like:

      > > sub getConfig {
      # I assume you have something like:
      my ($self) = @_; # here is your $ftp object

      > > .
      > > .
      > > .
      > > if (ref($dir_names) eq "ARRAY") {
      > > foreach my $hash (@$dir_names) {
      > > push(@HostComm::Path, $hash->{name});
      ## then instead of the above line use:
      push (@{$self->{Path}}, $hash->{name});

      > > print "$$hash{name}\n";
      > > }
      > > }
      > > }
      > >

      ## then you setup a retrieving method in your package:
      sub GetPaths {
      my($self) = @_;
      return @{$self->{Path}};
      }

      ## now your script calling will look like
      > > my $ftp = HostComm->new( login stuff );
      > > $ftp->getConfig() #here's where I call the
      > >
      > > foreach my $path2 ( $ftp->GetPaths() ) {
      > > printf "foreach Path %s\n", $path2;
      > > }

      This is untested of course. Let me know if it helped.


      --- In perl-beginner@yahoogroups.com, <greg.hering@b...> wrote:
      > Dear perlmedian,
      >
      > The goal is to
      > connect to a remote machine,
      > get a 'config' file from the machine,
      > read that config file and
      > get more files based upon what 'config' said
      > process those 'more files' and
      > store some of that info in a database.
      > And learn object perl too!
      >
      > My first class is derived off Net::FTP so that it knows about FTP
      connect, login and get.
      > When I call MyFTPthing->get() it pulls remote information into
      itself as member data. I can use that member data (@paths) to get
      more files. Once I've gotten all the files I can close the
      connection, but I do want to keep some of the config data for use in
      the processing.
      >
      > I suppose I could just return a list and not 'memberize' it, but
      really I don't HAVE to derive off Net::FTP either and so on, but now
      I've lost my whole OOPness.
      >
      > I have DB work to do and I'm using a separate class for that. I
      could go the other direction and do multiple inheritance from
      Net::FTP and DBI:: and have one huge 'blob-from-space' that does
      everything, but I think that's a bit much! Plus I've seen enough 'B'
      sci-fi to know better than to create a 'blob-from-space' on purpose!
      >
      > My current problem is trying to create member data (I guess using
      the bless trick) and not getting that '(in cleanup) Not a GLOB
      reference' warning from Net::FTP (see earlier post '[PBML] Object
      member - error.') which happens when I bless my member data (I think
      I'm breaking the inheritance chain somehow).
      >
      > Thanks,
      >
      > Greg
      >
      >
      > Gregory L. Hering
      > (256) 722-6420
      > 4807 Bradford Dr
      > Benchmark Electronics, Inc.
      > Huntsville, Al 35805
      >
      > -----Original Message-----
      > From: perlmedian [mailto:perlmedian@y...]
      > Sent: Wednesday, July 02, 2003 3:45 PM
      > To: perl-beginner@yahoogroups.com
      > Subject: [PBML] Re: auto-vivify?
      >
      > 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.
      >
      >
      >
      >
      > Yahoo! Groups Sponsor
      > ADVERTISEMENT
      >
      >
      >
      >
      > Unsubscribing info is here:
      http://help.yahoo.com/help/us/groups/groups-32.html
      >
      > Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
    Your message has been successfully submitted and would be delivered to recipients shortly.