From doug.miles at ns2.phoenix.bowne.com Thu Feb 3 11:24:59 2000 From: doug.miles at ns2.phoenix.bowne.com (Douglas E. Miles) Date: Thu Aug 5 00:16:05 2004 Subject: Phoenix.pm: Meeting 01/08/2000 Message-ID: <3899B9EB.BF1E213@bpxinternet.com> We'll be having a Phoenix.pm meeting Tuesday, February 8th at 7:00PM. It will be held at Bowne, which is located at 1500 N. Central Avenue, which is on the Southwest corner of Central and McDowell. The parking lot is gated, so just press the button on the intercom, and tell the receptionist that you are there for the Perl meeting. Park in the lot that is straight ahead from the entrance on the South side of McDowell. Park in any uncovered, non-reserved space. Proceed to the main lobby, which is on the Northeast side of the parking lot. Topic is unknown. Volunteers are welcome. If there are no volunteers, we'll have an open forum, so bring your questions and/or war stories! -- For a list of the ways which technology has failed to improve our quality of life, press 3. From doug.miles at ns2.phoenix.bowne.com Fri Feb 4 16:06:26 2000 From: doug.miles at ns2.phoenix.bowne.com (Douglas E. Miles) Date: Thu Aug 5 00:16:05 2004 Subject: Phoenix.pm: Next meeting Message-ID: <389B4D62.B3D0BB22@bpxinternet.com> I don't really have a topic, but I do have an OO quandry that I could use some help with. Anybody interested? It's a little too complicated to explain here. -- Socrates is a man. All men are mortal. Therefore, all mortals are Socrates. From kev at primenet.com Fri Feb 4 16:25:25 2000 From: kev at primenet.com (Kevin Buettner) Date: Thu Aug 5 00:16:05 2004 Subject: Phoenix.pm: Next meeting In-Reply-To: "Douglas E. Miles" "Phoenix.pm: Next meeting" (Feb 4, 3:06pm) References: <389B4D62.B3D0BB22@bpxinternet.com> Message-ID: <1000204222525.ZM3916@saguaro.lan> On Feb 4, 3:06pm, Douglas E. Miles wrote: > I don't really have a topic, but I do have an OO quandry that I could > use some help with. Anybody interested? It's a little too complicated > to explain here. Why don't you explain it here? Not all of us come to the meetings. Also, I have found that sometimes explaining a problem in writing helps clarify the problem (in the writer's mind) and often a solution will occur to you in the process. Kevin -- Kevin Buettner kev@primenet.com, kevinb@redhat.com From Beaves at aol.com Fri Feb 4 16:41:51 2000 From: Beaves at aol.com (Beaves@aol.com) Date: Thu Aug 5 00:16:05 2004 Subject: Phoenix.pm: Next meeting Message-ID: From root at nebuchadnezzar.slowass.net Fri Feb 4 19:24:28 2000 From: root at nebuchadnezzar.slowass.net (Scott Walters) Date: Thu Aug 5 00:16:05 2004 Subject: Phoenix.pm: Next meeting In-Reply-To: <389B4D62.B3D0BB22@bpxinternet.com> Message-ID: Of course we are interested. We worship you, Doug. On Fri, 4 Feb 2000, Douglas E. Miles wrote: > I don't really have a topic, but I do have an OO quandry that I could > use some help with. Anybody interested? It's a little too complicated > to explain here. > > -- > Socrates is a man. All men are mortal. Therefore, all mortals are > Socrates. > From doug.miles at bpxinternet.com Sat Feb 5 17:14:13 2000 From: doug.miles at bpxinternet.com (Douglas E. Miles) Date: Thu Aug 5 00:16:05 2004 Subject: OOP Question was: (Re: Phoenix.pm: Next meeting) References: <389CA194.DB659BF7@bpxinternet.com> Message-ID: <389CAEC5.42036C6E@bpxinternet.com> "Douglas E. Miles" wrote: > > On Feb 4, 3:06pm, Douglas E. Miles wrote: > > > I don't really have a topic, but I do have an OO quandry that I could > > use some help with. Anybody interested? It's a little too complicated > > to explain here. > > Why don't you explain it here? Not all of us come to the meetings. Mainly because I thought it might be too complicated to try to explain well in an email, and because it would take quite a bit of time. :) However, I'll make an attempt. > Also, I have found that sometimes explaining a problem in writing > helps clarify the problem (in the writer's mind) and often a solution > will occur to you in the process. I agree with this wholeheartedly. I often use this technique (usually verbally though) to solve problems. Without further ado... I am using XML::Parser (in the object style) to parse XML documents to a database. When you create a new XML::Parser object, you can specify a package (class) that the objects in the object tree get blessed into. If you specify the package to be "XML" and if you have XML like this: title blah, blah, blah the doc element gets blessed into XML::doc. The character data gets blessed into XML::Characters. This occurs by just appending the two together (yes, I did use the Source :) ). However, the packages don't appear to be declare anywhere (I don't know if this makes a difference or not). My problem is that I want to have all of the XML::* classes to inherit from the XML class. I did something like this (full source later): package XML; package XML::title @ISA = ('XML'); package XML::Characters @ISA = ('XML'); etc. However, perl could not find the methods that I was trying to inherit from XML. Also, I tried dumping the symbol table (I haven't done this before, so I may have screwed up), and found the XML package, but not any of the XML::* packages. I have this working now by creating the method in each of XML::* which calls the same method in XML. Not as clean as I would like. Eventually, I want to loop through XML::* in the symbol table, and tell each one to inherit from XML. The reason I want to do all of this, is that I want to be able to process XML documents without knowing all of the element names ahead of time. DISCLAIMER this source is highly experimental, ugly, partially functional, and sub optimal. I'm not responsible if it makes your hair fall out, your nose bleed, or causes madness. :) #!/usr/bin/perl use XML::Parser; use Data::Dumper; require 'xml_parser.cfg'; require 'dba.pl'; my $xml_document = shift; my $parser = new XML::Parser(Style => 'Objects', Pkg => 'XML_ObjTree'); my $object_tree = $parser->parsefile($xml_document); print "$object_tree\n"; foreach $symname (sort(keys(%main::))) { local *sym = $main::{$symname}; print "\$$symname is defined\n" if defined $sym; print "\@$symname is defined\n" if defined @sym; print "\%$symname is defined\n" if defined %sym; print "\&$symname is defined\n" if defined &sym; } $object_tree->[0]->traverse(); $object_tree->[0]->dump_tree(); package XML_ObjTree; # Initialize global node counter. $Node_Counter = 0; sub traverse { my $self = shift; # Number the left side of the node. $self->{left_node_count} = ++$Node_Counter; local ($index); # Loop through all kids. foreach $index (0..$#{$self->{Kids}}) { # Recurse kid. $self->{Kids}->[$index]->traverse(); } # Done with branch; number right side of the node. $self->{right_node_count} = ++$Node_Counter; XML_ObjTree::insert_element($self); } # END: traverse sub insert_element { my $self = shift; # Get the element from the class name. my $element = (reverse(split(/::/, ref($self))))[0]; print "\$element: $element\n"; my @fields = (1, $element, 1, $self->{left_node_count}, $self->{right_node_count}); my $fields = join(',', map("\'$_\'", @fields)); printf($::Element_Insert, $fields); # SQL_Insert(sprintf($Event_Insert, $values)); } # END: insert_element sub dump_tree { my $self = shift; print main::Dumper($self); } package XML_ObjTree::report; @ISA = ('XML_ObjTree'); sub traverse { my $self = shift; XML_ObjTree::traverse($self); } sub dump_tree { my $self = shift; print main::Dumper($self); } package XML_ObjTree::title; @ISA = ('XML_ObjTree'); sub traverse { my $self = shift; XML_ObjTree::traverse($self); } sub dump_tree { my $self = shift; print main::Dumper($self); } package XML_ObjTree::Characters; @ISA = ('XML_ObjTree'); sub traverse { my $self = shift; XML_ObjTree::traverse($self); } sub dump_tree { my $self = shift; print main::Dumper($self); } #################################### Here is the XML: title1title2 If Netscape screws up the formatting here, the above should all be on one line, so that no extra Characters objects are created for useless white space. Enjoy! -- "We've heard that a million monkeys at a million keyboards could produce the Complete Works of Shakespeare; now, thanks to the Internet, we know this is not true." --Robert Wilensky From doug.miles at ns2.phoenix.bowne.com Sat Feb 5 17:18:11 2000 From: doug.miles at ns2.phoenix.bowne.com (Douglas E. Miles) Date: Thu Aug 5 00:16:05 2004 Subject: Phoenix.pm: Next meeting References: Message-ID: <389CAFB3.B58C384B@bpxinternet.com> Scott Walters wrote: > > Of course we are interested. We worship you, Doug. Oh! That explains why I have to beat off all the groupies with a stick. ;) P.S. I certainly hope not. Very scary thought. :) > On Fri, 4 Feb 2000, Douglas E. Miles wrote: > > > I don't really have a topic, but I do have an OO quandry that I could > > use some help with. Anybody interested? It's a little too complicated > > to explain here. > > > > -- > > Socrates is a man. All men are mortal. Therefore, all mortals are > > Socrates. > > -- Socrates is a man. All men are mortal. Therefore, all mortals are Socrates. From doug.miles at ns2.phoenix.bowne.com Sat Feb 5 17:19:04 2000 From: doug.miles at ns2.phoenix.bowne.com (Douglas E. Miles) Date: Thu Aug 5 00:16:05 2004 Subject: Phoenix.pm: Next meeting References: Message-ID: <389CAFE8.DBECC1F9@bpxinternet.com> Beaves@aol.com wrote: > > Is this the Sound of Silence? :) -- Socrates is a man. All men are mortal. Therefore, all mortals are Socrates. From doug.miles at ns2.phoenix.bowne.com Mon Feb 7 15:50:05 2000 From: doug.miles at ns2.phoenix.bowne.com (Douglas E. Miles) Date: Thu Aug 5 00:16:05 2004 Subject: Phoenix.pm: Meeting 02/08/2000 Reminder Message-ID: <389F3E0D.7B9688A6@bpxinternet.com> We'll be having a Phoenix.pm meeting Tuesday, February 8th at 7:00PM. It will be held at Bowne, which is located at 1500 N. Central Avenue, which is on the Southwest corner of Central and McDowell. The parking lot is gated, so just press the button on the intercom, and tell the receptionist that you are there for the Perl meeting. Park in the lot that is straight ahead from the entrance on the South side of McDowell. Park in any uncovered, non-reserved space. Proceed to the main lobby, which is on the Northeast side of the parking lot. We'll have an open forum, so bring your questions and/or war stories! -- For a list of the ways which technology has failed to improve our quality of life, press 3. From Bryan.Lane at VITALPS.COM Mon Feb 7 16:10:08 2000 From: Bryan.Lane at VITALPS.COM (Bryan Lane) Date: Thu Aug 5 00:16:05 2004 Subject: Phoenix.pm: Meeting 02/08/2000 Reminder Message-ID: Sounds great! I'll be there! -----Original Message----- From: Douglas E. Miles [mailto:doug.miles@ns2.phoenix.bowne.com] Sent: Monday, February 07, 2000 2:50 PM To: Phoenix.pm Cc: Rose Keys Subject: Phoenix.pm: Meeting 02/08/2000 Reminder We'll be having a Phoenix.pm meeting Tuesday, February 8th at 7:00PM. It will be held at Bowne, which is located at 1500 N. Central Avenue, which is on the Southwest corner of Central and McDowell. The parking lot is gated, so just press the button on the intercom, and tell the receptionist that you are there for the Perl meeting. Park in the lot that is straight ahead from the entrance on the South side of McDowell. Park in any uncovered, non-reserved space. Proceed to the main lobby, which is on the Northeast side of the parking lot. We'll have an open forum, so bring your questions and/or war stories! -- For a list of the ways which technology has failed to improve our quality of life, press 3. From Beaves at aol.com Tue Feb 8 13:37:00 2000 From: Beaves at aol.com (Beaves@aol.com) Date: Thu Aug 5 00:16:05 2004 Subject: Phoenix.pm: Re: OOP Question Message-ID: Hi, sorry, I can't make the meeting tonight. When your run the parser, and XML::doc (et al) springs into existence, have you looked at whether the parser at that point defines @XML::doc::ISA? If this occurs when you run the parser, it will be overwriting any definitions of @XML::doc::ISA that you may have already defined, which might be screwing up you inheritance plan. Have you thought about maybe adding a class the XML inherits from? Something like: push(@XML::ISA, 'XML::DougsXML') and then defining all the same methods but in XML::DougsXML. This way, any method called that finds its way to XML and is still not found, will eventually be found in DougsXML by inheritance. (of course, be leery of your method names in this case, so they won't be found before the lookup gets to your level). Also, you said something interesting not finding the package declarations anywhere in the source code. It may be done in a way you are not expecting. Since the XML parser does not know what elements it will later have to create packages for, it may be done in an indirect fashion. It may be doing something like: my $element = shift; # or however the parser gets the string... my $class = "XML::$element"; @{"$class\::ISA"} = (XML); bless $somehash, $class; Now, you can call methods like XML::doc->traverse; or $someobject->traverse and it will have the inheritance you would expect. I'm not sure if this was what you were getting at with the package declaration stuff, but if not, then maybe someone else can use it. Have fun at the meeting tonight! Tim From pablo at dosomething.org Tue Feb 8 18:53:03 2000 From: pablo at dosomething.org (Pablo Velasquez) Date: Thu Aug 5 00:16:05 2004 Subject: Phoenix.pm: Website Updates with Perl In-Reply-To: Message-ID: <4.2.0.58.20000208164520.00b72d30@mail.dosomething.org> Greetings: It's been a while since I last posted... I was wondering if you've ever heard of some Perl site management script, that does the following: allows you to keep a "test" copy of you website, then when you press the magic button it updates any changed files to your "real-production" machine. I few years ago I worked with a company that used such a script, they called it WebScript.pl But my searches have not produced results on the web, nor the myriad of online scripts forums. Thanks very much. -Pablo From kev at primenet.com Tue Feb 8 22:04:38 2000 From: kev at primenet.com (Kevin Buettner) Date: Thu Aug 5 00:16:05 2004 Subject: Phoenix.pm: Website Updates with Perl In-Reply-To: Pablo Velasquez "Phoenix.pm: Website Updates with Perl" (Feb 8, 4:53pm) References: <4.2.0.58.20000208164520.00b72d30@mail.dosomething.org> Message-ID: <1000209040438.ZM4474@saguaro.lan> On Feb 8, 4:53pm, Pablo Velasquez wrote: > I was wondering if you've ever heard of some Perl site management script, > that does the following: allows you to keep a "test" copy of you website, > then when you press the magic button it updates any changed files to your > "real-production" machine. > > I few years ago I worked with a company that used such a script, they > called it WebScript.pl It's not written in perl, but take a look at http://samba.anu.edu.au/rsync/ This utility won't update and/or fix links, but it will move your changed sources from one place to another *very* efficiently. (And your links shouldn't be a problem if you use relative links anyway.) I started using this utility earlier this week to help me manage development of some sources on some remote machines at work. (Where "remote" is in another state.) I've written a perl script to sync in both directions. First it attempts to fetch any new or updated files from the remote machine. Next it attempts to put any new/updated files from the local machine to the remote. This allows me to be fairly undisciplined and change files on both sides. So long as I don't make changes to the same file on both sides, I won't be in trouble. Below is my script; I've named the script to something appropriate for the project that I'm working on and have actually hardwired $REMOTE_SRC and $LOCAL_SRC to the appropriate paths. I also have $RSYNC_PATH set to the location of rsync in my home directory. (rsync is installed on the remote machine, but it is a much older version than the one I'm using on the local machine and I wanted to make sure that the protocols matched.) I use ssh to transfer the files securely. If you don't already have ssh-agent managing your key data for you, it'll start one up and prompt you for your passphrase prior to invoking the rsyncs. The reason for this is to avoid having to enter your passphrase more than once. If you give it command line arguments, these are interpreted as paths relative to the main hierarchy to synchronize. These can be either actual filenames or directories somewhere within the main hierarchy. ---sync-local-remote--- #!/usr/bin/perl -w $REMOTE_SRC = "remote.host.com:/path/to/remote/src"; $LOCAL_SRC = "/path/to/local/src"; $RSYNC_PATH = "/usr/local/bin/rsync"; $ENV{RSYNC_RSH} = 'ssh'; if (!$ENV{SSH_AGENT_PID}) { my $agentdata = `ssh-agent -s`; die "Problem starting ssh-agent" if (!defined($agentdata)); my ($agent_pid) = $agentdata =~ /^SSH_AGENT_PID=([^;]*);/m; my ($agent_sock) = $agentdata =~ /^SSH_AUTH_SOCK=([^;]*);/m; die "Can't fetch ssh agent environment variables" unless defined($agent_pid) && defined($agent_sock); print "agent_pid=$agent_pid; agent_sock=$agent_sock\n"; $ENV{SSH_AGENT_PID} = $agent_pid; $ENV{SSH_AUTH_SOCK} = $agent_sock; system("ssh-add"); sleep(4); } if (@ARGV) { foreach $arg (@ARGV) { sync_dir("$REMOTE_SRC/$arg", "$LOCAL_SRC/$arg"); } } else { sync_dir($REMOTE_SRC, $LOCAL_SRC); } system("ssh-agent -k"); sub sync_dir { my ($remote_src, $local_src) = @_; my $remote_dir = $remote_src; $remote_dir =~ s#/[^/]*$##; my $local_dir = $local_src; $local_dir =~ s#/[^/]*$##; system("rsync -avuz --exclude '*~' --rsync-path=$RSYNC_PATH $remote_src $local_dir"); system("rsync -Cavuz --exclude '*~' --rsync-path=$RSYNC_PATH $local_src $remote_dir"); } --- end sync-local-remote --- -- Kevin Buettner kev@primenet.com, kevinb@redhat.com From root at nebuchadnezzar.slowass.net Wed Feb 9 06:27:05 2000 From: root at nebuchadnezzar.slowass.net (Scott Walters) Date: Thu Aug 5 00:16:05 2004 Subject: Phoenix.pm: Meeting 02/08/2000 Reminder In-Reply-To: <389F3E0D.7B9688A6@bpxinternet.com> Message-ID: Hey all, sorry I missed the meeting. Overslept... -scott From edelsys at edelsys.com Wed Feb 9 06:38:40 2000 From: edelsys at edelsys.com (EdelSys Consulting) Date: Thu Aug 5 00:16:05 2004 Subject: Phoenix.pm: Meeting 02/08/2000 Reminder In-Reply-To: References: <389F3E0D.7B9688A6@bpxinternet.com> Message-ID: <3.0.6.32.20000209053840.00a7f100@swlink.net> At 04:27 AM 02/09/2000 -0800, you wrote: > >Hey all, sorry I missed the meeting. Overslept... > >-scott > > You snoozer!! =) In other news, I recommend that all of you retrocomputing enthusiasts check out MuLinux: http://sunsite.auc.dk/mulinux/ It is a "minimal" linux distro that fits on a few floppies and coexists peacefully with DOS/WIN 3.1 in UMSDOS install on my oldy moldy 486/66 ternary standby box. =P I've gotten the author to upload a perl.tar.gz to his Binaries page: http://sunsite.auc.dk/mulinux/mu/misc/ If enough of us email him, we may convince him to make Perl Floppy Addon #6 ! =) Tony -- -- Anthony R. Nemmer -- EdelSys Consulting -- http://www.edelsys.com/ -- edelsys@edelsys.com -- ICQ #14638605 -- EFNet IRC Nicks: Teratogen, PerlGod -- vCard: http://www.edelsys.com/edelsys.vcf -- (480) 968-6438 -- P.O. Box 1883, Tempe, Arizona 85280-1883 -- "Even the safest course is fraught with peril." -- Anonymous From sinck at corp.quepasa.com Wed Feb 9 12:21:37 2000 From: sinck at corp.quepasa.com (sinck@corp.quepasa.com) Date: Thu Aug 5 00:16:05 2004 Subject: Phoenix.pm: Website Updates with Perl References: <4.2.0.58.20000208164520.00b72d30@mail.dosomething.org> Message-ID: <14497.45105.875569.585227@ip100.corp.quepasa.com> \_ Greetings: \_ It's been a while since I last posted... \_ \_ I was wondering if you've ever heard of some Perl site management script, \_ that does the following: allows you to keep a "test" copy of you website, \_ then when you press the magic button it updates any changed files to your \_ "real-production" machine. Investigate HTML::Mason; YMMV. David From doug.miles at ns2.phoenix.bowne.com Wed Feb 9 12:32:43 2000 From: doug.miles at ns2.phoenix.bowne.com (Douglas E. Miles) Date: Thu Aug 5 00:16:05 2004 Subject: Phoenix.pm: OOP quandry the sequel (and the answer) Message-ID: <38A1B2CB.50856991@bpxinternet.com> OK, I discovered what my problem was. It was simply that my packages needed to come before the object is instantiated. Here is a simple example: # This works! #!/usr/bin/perl foreach $symname (sort(keys(%main::))) { local *sym = $main::{$symname}; print "\$$symname is defined\n" if defined $sym; print "\@$symname is defined\n" if defined @sym; print "\%$symname is defined\n" if defined %sym; print "\&$symname is defined\n" if defined &sym; } package XML_ObjTree::report; @ISA = qw(XML_ObjTree); package XML_ObjTree; sub new { print "NEW!!!!!!!!!!!!!\n"; } my $obj = XML_ObjTree::report->new; # This doesn't work. #!/usr/bin/perl foreach $symname (sort(keys(%main::))) { local *sym = $main::{$symname}; print "\$$symname is defined\n" if defined $sym; print "\@$symname is defined\n" if defined @sym; print "\%$symname is defined\n" if defined %sym; print "\&$symname is defined\n" if defined &sym; } my $obj = XML_ObjTree::report->new; package XML_ObjTree::report; @ISA = qw(XML_ObjTree); package XML_ObjTree; sub new { print "NEW!!!!!!!!!!!!!\n"; } Notice the difference in where this line is: my $obj = XML_ObjTree::report->new; I was under the mistaken assumption that this was all resolved at compile time. Apparently, this is not the case. Bonus: I also discovered something else I didn't know. XML_ObjTree::report is stored under the XML_ObjTree:: symbol table - not under main::. This suprised me because everything I have seen says that there is no implied relationship. I guess that just refers to the fact that there is no automatic inheritance. Hope this is helpful. It was definitely educational to me. -- Socrates is a man. All men are mortal. Therefore, all mortals are Socrates. From Bryan.Lane at VITALPS.COM Wed Feb 9 12:46:55 2000 From: Bryan.Lane at VITALPS.COM (Bryan Lane) Date: Thu Aug 5 00:16:05 2004 Subject: Phoenix.pm: OOP quandry the sequel (and the answer) Message-ID: Good job. I knew you would figure it out. It makes sense about the packages needing to come before the object is instantiated. I'm not sure why none of us saw it. Later, Bryan -----Original Message----- From: Douglas E. Miles [mailto:doug.miles@ns2.phoenix.bowne.com] Sent: Wednesday, February 09, 2000 11:33 AM To: Phoenix.pm Subject: Phoenix.pm: OOP quandry the sequel (and the answer) OK, I discovered what my problem was. It was simply that my packages needed to come before the object is instantiated. Here is a simple example: # This works! #!/usr/bin/perl foreach $symname (sort(keys(%main::))) { local *sym = $main::{$symname}; print "\$$symname is defined\n" if defined $sym; print "\@$symname is defined\n" if defined @sym; print "\%$symname is defined\n" if defined %sym; print "\&$symname is defined\n" if defined &sym; } package XML_ObjTree::report; @ISA = qw(XML_ObjTree); package XML_ObjTree; sub new { print "NEW!!!!!!!!!!!!!\n"; } my $obj = XML_ObjTree::report->new; # This doesn't work. #!/usr/bin/perl foreach $symname (sort(keys(%main::))) { local *sym = $main::{$symname}; print "\$$symname is defined\n" if defined $sym; print "\@$symname is defined\n" if defined @sym; print "\%$symname is defined\n" if defined %sym; print "\&$symname is defined\n" if defined &sym; } my $obj = XML_ObjTree::report->new; package XML_ObjTree::report; @ISA = qw(XML_ObjTree); package XML_ObjTree; sub new { print "NEW!!!!!!!!!!!!!\n"; } Notice the difference in where this line is: my $obj = XML_ObjTree::report->new; I was under the mistaken assumption that this was all resolved at compile time. Apparently, this is not the case. Bonus: I also discovered something else I didn't know. XML_ObjTree::report is stored under the XML_ObjTree:: symbol table - not under main::. This suprised me because everything I have seen says that there is no implied relationship. I guess that just refers to the fact that there is no automatic inheritance. Hope this is helpful. It was definitely educational to me. -- Socrates is a man. All men are mortal. Therefore, all mortals are Socrates. From doug.miles at ns2.phoenix.bowne.com Wed Feb 9 14:42:45 2000 From: doug.miles at ns2.phoenix.bowne.com (Douglas E. Miles) Date: Thu Aug 5 00:16:05 2004 Subject: Phoenix.pm: Symbol table question Message-ID: <38A1D145.28253C05@bpxinternet.com> Now I have a symbol table question. As I mentioned before, XML::Parser blesses objects into packages like this: XML_ObjTree:: (XML_ObjTree was provided to XML::Parser as a parameter to new) The problem I am experiencing is that although these objects are blessed into these packages, the packages don't seem to exist in the symbol table. I have looked in %main:: and %XML_ObjTree::. Can anyone shed some light on this? Thanks! -- Socrates is a man. All men are mortal. Therefore, all mortals are Socrates. From doug.miles at ns2.phoenix.bowne.com Wed Feb 9 15:21:06 2000 From: doug.miles at ns2.phoenix.bowne.com (Douglas E. Miles) Date: Thu Aug 5 00:16:05 2004 Subject: Phoenix.pm: More symbol table weirdness Message-ID: <38A1DA42.C880C91B@bpxinternet.com> Some more info here: The packages I'm looking for DO exist as keys for %XML_ObjTree. However, the hash for the particular package is not defined: foreach $package (keys(%XML_ObjTree::)) { print "$package\n"; local *sym = $XML_ObjTree::{$package}; print "\$$package is defined\n" if defined $sym; print "\@$package is defined\n" if defined @sym; print "\%$package is defined\n" if defined %sym; print "\&$package is defined\n" if defined &sym; } gives this: report:: index Characters:: traverse &traverse is defined dump_tree &dump_tree is defined Node_Counter $Node_Counter is defined title:: insert_element &insert_element is defined The guys with the '::' at the end are the packages that I have been looking for. Any clue why they aren't defined? -- Socrates is a man. All men are mortal. Therefore, all mortals are Socrates. From doug.miles at ns2.phoenix.bowne.com Wed Feb 9 16:20:29 2000 From: doug.miles at ns2.phoenix.bowne.com (Douglas E. Miles) Date: Thu Aug 5 00:16:05 2004 Subject: Phoenix.pm: Questions Message-ID: <38A1E82D.30A79EC8@bpxinternet.com> Is everyone out there wondering what the heck I'm talking about? :) -- Socrates is a man. All men are mortal. Therefore, all mortals are Socrates. From Bryan.Lane at VITALPS.COM Wed Feb 9 16:48:49 2000 From: Bryan.Lane at VITALPS.COM (Bryan Lane) Date: Thu Aug 5 00:16:05 2004 Subject: Phoenix.pm: Questions Message-ID: Yep. -----Original Message----- From: Douglas E. Miles [mailto:doug.miles@ns2.phoenix.bowne.com] Sent: Wednesday, February 09, 2000 3:20 PM To: Phoenix.pm Subject: Phoenix.pm: Questions Is everyone out there wondering what the heck I'm talking about? :) -- Socrates is a man. All men are mortal. Therefore, all mortals are Socrates. From Beaves at aol.com Thu Feb 10 10:15:09 2000 From: Beaves at aol.com (Beaves@aol.com) Date: Thu Aug 5 00:16:05 2004 Subject: Phoenix.pm: More symbol table weirdness Message-ID: Doug, It may be because your sub needs to be recursive to catch the definedness of nested packages in a symbol table. How about something like this... &print_or_expand('XML_ObjTree'); sub print_or_expand { local $symname = shift; print "\nPrinting or expanding the contents of %$symname\n"; foreach $name ( keys %{$symname} ) { print "The key '$name' in the symbol table %$symname " . "points to ${$symname}{$name}"; print " (it is defined)" if defined ${$symname}{$name}; if ($name =~ /::$/) { print "\nIts another symbol table, let's do this again...\n"; &print_or_expand; } else { print "\nIt points to a glob (${$symname}{$name}), lets see the details\n"; local *sym = ${$symname}{$name}; print "\t\$$package is defined\n" if defined $sym; print "\t\@$package is defined\n" if defined @sym; print "\t\%$package is defined\n" if defined %sym; print "\t\&$package is defined\n" if defined &sym; } } } I have not tested this thing out, so all bets are off! But it may give you some ideas. Let me know more about what you find out... Tim From doug.miles at ns2.phoenix.bowne.com Thu Feb 10 11:29:26 2000 From: doug.miles at ns2.phoenix.bowne.com (Douglas E. Miles) Date: Thu Aug 5 00:16:05 2004 Subject: Phoenix.pm: More symbol table weirdness References: Message-ID: <38A2F576.D443CB11@bpxinternet.com> > I have not tested this thing out, so all bets are off! But it may give you > some ideas. Let me know more about what you find out... > > Tim Thanks Tim. I'll give this a try and let you know. Sorry I didn't reply to your other message. Before I got a chance to dive into what you said, I figured out some of it my self. Just FYI, I have my program working now. This question is still relevant though, because I'd like to understand. Here's the code (following the code is an explanation of what I did): #!/usr/bin/perl package XML_ObjTree; # Initialize global node counter. $Node_Counter = 0; sub traverse { my $self = shift; # Number the left side of the node. $self->{left_node_count} = ++$Node_Counter; local ($index); # Loop through all kids. foreach $index (0..$#{$self->{Kids}}) { # Recurse kid. $self->{Kids}->[$index]->traverse(); } # Done with branch; number right side of the node. $self->{right_node_count} = ++$Node_Counter; XML_ObjTree::insert_element($self); } # END: traverse sub insert_element { my $self = shift; # Get the element from the class name. my $element = (reverse(split(/::/, ref($self))))[0]; my @fields = (1, $element, 1, $self->{left_node_count}, $self->{right_node_count}); my $fields = join(',', map("\'$_\'", @fields)); # SQL_Insert(sprintf($Event_Insert, $values)); } # END: insert_element sub dump_tree { use Data::Dumper; my $self = shift; print Dumper($self); } #package XML_ObjTree::report; # #@ISA = ('XML_ObjTree'); # #package XML_ObjTree::title; # #@ISA = ('XML_ObjTree'); # #package XML_ObjTree::Characters; # #@ISA = ('XML_ObjTree'); package main; use XML::Parser; require 'xml_parser.cfg'; require 'dba.pl'; my $xml_document = shift; my $parser = new XML::Parser(Style => 'Objects', Pkg => 'XML_ObjTree'); my $object_tree = $parser->parsefile($xml_document); # Grab all of the XML_ObjTree::* packages. foreach $package (grep(/\:\:$/, keys(%XML_ObjTree::))) { $package =~ s/://g; # Make XML_ObjTree::* inherit from XML_ObjTree. my $package_declaration = <<"EOD"; package XML_ObjTree::$package; \@ISA = ('XML_ObjTree'); EOD eval $package_declaration; # *base_package_stash = $XML_ObjTree::{$package}; # @{$package_stash{ISA}} = ('XML_ObjTree'); # @{$XML_ObjTree::{$package}->{ISA}} = ('XML_ObjTree'); } $object_tree->[0]->traverse(); $object_tree->[0]->dump_tree(); ############################ Basically, the new stuff is that I search through the XML_ObjTree:: package for all packages in that namespace (grep). Then I create a package declaration, and @ISA statement, and eval them. This gives me the generic inheritance that I was looking for. I must say that this has been the most difficult and educational program I've done in a while. Hope I didn't bore you guys too much. :) -- Socrates is a man. All men are mortal. Therefore, all mortals are Socrates. From Beaves at aol.com Thu Feb 10 12:24:32 2000 From: Beaves at aol.com (Beaves@aol.com) Date: Thu Aug 5 00:16:05 2004 Subject: Phoenix.pm: More symbol table weirdness Message-ID: <3a.13965a9.25d45c60@aol.com> In a message dated 2/10/00 10:31:20 AM US Mountain Standard Time, doug.miles@ns2.phoenix.bowne.com writes: << # Make XML_ObjTree::* inherit from XML_ObjTree. my $package_declaration = <<"EOD"; package XML_ObjTree::$package; \@ISA = ('XML_ObjTree'); EOD eval $package_declaration; >> I think I mentioned this in a previous post, but this eval is unecessary. You just have to declare at least one variable in the package and that package springs into existence. And, it doesn't matter what the current package is. So the above code could be reduced to one line with no eval. # package is the current package. @{"XML_ObjTree::$package\::ISA"} = ('XML_ObjTree'); and the package XML_ObjTree::$package will be created. Note, you have to escape the first colon before the 'ISA'. If you don't, then you'll be interpolating the variable $ISA in the package 'package' which is not what you want in this case. If someone doesn't quite get this stuff, post your questions. Since I started understanding a bit about Perl packages and symbol tables, I've found the above technique and stuff similar to it to be VERY useful. I think it should be in everyone's Bag o' Tricks. Tim From doug.miles at ns2.phoenix.bowne.com Thu Feb 10 12:36:59 2000 From: doug.miles at ns2.phoenix.bowne.com (Douglas E. Miles) Date: Thu Aug 5 00:16:05 2004 Subject: Phoenix.pm: More symbol table weirdness References: <3a.13965a9.25d45c60@aol.com> Message-ID: <38A3054B.D12C5B63@bpxinternet.com> Thanks alot Tim! I bow to your superior symbol table knowledge. I'm not worthy! :) Actually that was the first approach that I tried. I just couldn't get the derefrencing right. :( I was actually hoping that someone might show me how to do this. I guess I need to dig deeper into the symbol table. I'll try this too and let you know. Thank! Beaves@aol.com wrote: > > In a message dated 2/10/00 10:31:20 AM US Mountain Standard Time, > doug.miles@ns2.phoenix.bowne.com writes: > > << # Make XML_ObjTree::* inherit from XML_ObjTree. > my $package_declaration = <<"EOD"; > package XML_ObjTree::$package; > \@ISA = ('XML_ObjTree'); > EOD > > eval $package_declaration; > >> > > I think I mentioned this in a previous post, but this eval is unecessary. > You just have to declare at least one variable in the package and that > package springs into existence. And, it doesn't matter what the current > package is. So the above code could be reduced to one line with no eval. > > # package is the current package. > @{"XML_ObjTree::$package\::ISA"} = ('XML_ObjTree'); > > and the package XML_ObjTree::$package will be created. Note, you have to > escape the first colon before the 'ISA'. If you don't, then you'll be > interpolating the variable $ISA in the package 'package' which is not what > you want in this case. > > If someone doesn't quite get this stuff, post your questions. Since I started > understanding a bit about Perl packages and symbol tables, I've found the > above technique and stuff similar to it to be VERY useful. I think it should > be in everyone's Bag o' Tricks. > > Tim -- Socrates is a man. All men are mortal. Therefore, all mortals are Socrates. From doug.miles at ns2.phoenix.bowne.com Thu Feb 10 12:39:23 2000 From: doug.miles at ns2.phoenix.bowne.com (Douglas E. Miles) Date: Thu Aug 5 00:16:05 2004 Subject: Phoenix.pm: More symbol table weirdness References: <3a.13965a9.25d45c60@aol.com> Message-ID: <38A305DB.EBA9B55F@bpxinternet.com> I just tried it, and it works great (less filling too!)! You rock! Beaves@aol.com wrote: > > In a message dated 2/10/00 10:31:20 AM US Mountain Standard Time, > doug.miles@ns2.phoenix.bowne.com writes: > > << # Make XML_ObjTree::* inherit from XML_ObjTree. > my $package_declaration = <<"EOD"; > package XML_ObjTree::$package; > \@ISA = ('XML_ObjTree'); > EOD > > eval $package_declaration; > >> > > I think I mentioned this in a previous post, but this eval is unecessary. > You just have to declare at least one variable in the package and that > package springs into existence. And, it doesn't matter what the current > package is. So the above code could be reduced to one line with no eval. > > # package is the current package. > @{"XML_ObjTree::$package\::ISA"} = ('XML_ObjTree'); > > and the package XML_ObjTree::$package will be created. Note, you have to > escape the first colon before the 'ISA'. If you don't, then you'll be > interpolating the variable $ISA in the package 'package' which is not what > you want in this case. > > If someone doesn't quite get this stuff, post your questions. Since I started > understanding a bit about Perl packages and symbol tables, I've found the > above technique and stuff similar to it to be VERY useful. I think it should > be in everyone's Bag o' Tricks. > > Tim -- Socrates is a man. All men are mortal. Therefore, all mortals are Socrates. From doug.miles at bpxinternet.com Thu Feb 17 15:55:01 2000 From: doug.miles at bpxinternet.com (Douglas E. Miles) Date: Thu Aug 5 00:16:05 2004 Subject: Phoenix.pm: Meeting 02/22/2000 Message-ID: <38AC6E34.739E84BD@bpxinternet.com> We'll be having a Phoenix.pm meeting Tuesday, February 22nd at 7:00PM. It will be held at Bowne, which is located at 1500 N. Central Avenue, which is on the Southwest corner of Central and McDowell. The parking lot is gated, so just press the button on the intercom, and tell the receptionist that you are there for the Perl meeting. Park in the lot that is straight ahead from the entrance on the South side of McDowell. Park in any uncovered, non-reserved space. Proceed to the main lobby, which is on the Northeast side of the parking lot. I'm trying to reach Scott. If he can't do the presentation, I will share what I have learned recently about Packages and Objects. -- For a list of the ways which technology has failed to improve our quality of life, press 3. From doug.miles at bpxinternet.com Mon Feb 21 14:25:41 2000 From: doug.miles at bpxinternet.com (Douglas E. Miles) Date: Thu Aug 5 00:16:05 2004 Subject: Phoenix.pm: Reminder: Meeting 02/22/2000 Message-ID: <38B19F45.F90C7EDB@bpxinternet.com> We'll be having a Phoenix.pm meeting Tuesday, February 22nd at 7:00PM. It will be held at Bowne, which is located at 1500 N. Central Avenue, which is on the Southwest corner of Central and McDowell. The parking lot is gated, so just press the button on the intercom, and tell the receptionist that you are there for the Perl meeting. Park in the lot that is straight ahead from the entrance on the South side of McDowell. Park in any uncovered, non-reserved space. Proceed to the main lobby, which is on the Northeast side of the parking lot. I will share what I have learned recently about Packages and Objects and Perl's tk debugger - ptkdb. -- For a list of the ways which technology has failed to improve our quality of life, press 3.