Re: modules - lost again
Examine your concept of reside in. You appear to be confused with modules that use the Exporter. You don't. I believe you'll find that you use SomeOther::Module *before* using Configuration in the main program, which means that the assignments haven't taken place yet. A-ha! Some days I am dumber than other days :) Everything was exactly as you described. In this light I have a couple of additional questions. This one is about my Tools.pm which uses Exporter and delivers a set of 5- 10 line subroutines for stupud tasks (number rounder, strip commas from numbers, commify them back, customized html entity decoder etc etc etc). What I am currently doing is automatically exporting ALL these subroutines (using fairly descriptive names to avoid clashes) and use Tools; in all modules that might benefit from them. Pretty standard. However I do not understand if importing just a subset of just the necessary functions is beneficial in terms of speed. What I am thinking is that since every single function IS going to be used sooner or later by at least one of the modules, and since EVERY module is called at least once from the main program over its runtime - the entire Tools.pm is being processed anyway and wether I import all functions or just a few makes no difference on the entire picture. Or am I wrong? And if I am, and specifying explicit imports for each module is beneficial - is Autoloader applicable to this situation? I've seen tons of examples of how OO can benefit from calls to non-existent instances, but I didn't see a single usage of Autoloader in a non-OO envirnoment which leads me to believe that it is not applicable. Thank you. Peter -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: First time Parsing XML
On Saturday 02 Apr 2005 04:29, Johnstone, Colin wrote: Gidday All, I would like to use xml Parser to parse this chunk of xml (below) and return the business unit name and id attributes for each of the elements where division id = '221' I have tried Why not try: http://search.cpan.org/~grantm/XML-Simple-2.14/lib/XML/Simple.pm If all you want to do is grab a business unit, follow the example on the page above. #!/web/Interwoven/TeamSite/iw-perl/bin/iwperl use XML::XPath; use XML::XPath::XMLParser; my $xpath; my $nodeset; my @memberList; my $arg; my $argVal; my $fileToParse = qq[/web/Interwoven/TeamSite/custom/config/DET_structure.xml]; $xpath = XML::XPath-new( filename = $fileToParse ); $nodeSet = $xpath-find( $xpathQuery ); @memberList = map { XML::XPath::XMLParser::as_string( $_ ) } $nodeSet-get_nodelist(); @memberList = map { s|^.*(?=htdocs)||; $_; } @memberList; @memberList = map { s|//|/|g; $_; } @memberList; # %masterList = map { $_, 1 } @memberList; while( @memberList ){ print( $_ . '\n' ); } Any help appreciated Cheers Colin ?xml version=1.0 encoding=UTF-8? organisation lastUpdate=21/03/05 division name=Office of the Director-General id=202 business-unit name=Correspondence unit id=203/ /division division name=Office of the Deputy Director-General id=276/ division name=Strategic Communications and Marketing id=204 business-unit name=Communications unit id=1002/ /division division name=Strategic Legal Unit id=1003/ division name=Internal Audit id=222/ division name=Strategic Infrastructure Initiatives id=1022/ division name=Human Resource Strategy and Performance id=221 business-unit name=Workforce Capability id=214/ business-unit name=Ethics id=214C/ business-unit name=eDRMS Project id=1024/ business-unit name=Workforce Management id=216/ business-unit name=Strategic Legal and FOI id=1003/ business-unit name=HR Strategy and Information Policy and Reporting - name may change id=221 sub-business-unit name=HR Business/Workforce Planning id=1024/ sub-business-unit name=HR Strategy id=1025/ sub-business-unit name=HR Governance/Governance Structures id=1026/ sub-business-unit name=HR Reporting id=1027/ sub-business-unit name=HR Business Performance and Analysis id=1028/ sub-business-unit name=HR Information System Protocols id=1029/ /business-unit business-unit name=Office of the GM (HR) id=1005/ /division /organisation ** Colin Johnstone Independent Interwoven Teamsite Analyst Programmer (Contractor) eGovernment Delivery Team Department of Employment and Training Phone (07) 3244 6268 Fax (07) 3244 6265 Email Colin.Johnstone mailto:[EMAIL PROTECTED] Web www.trainandemploy.qld.gov.au http://www.trainandemploy.qld.gov.au/ Address 417 Main Street, Kangaroo Point 4169, QLD, Australia. ** --- - This E-Mail is intended only for the addressee. Its use is limited to that intended by the author at the time and it is not to be distributed without the author's consent. Unless otherwise stated, the State of Queensland accepts no liability for the contents of this E-Mail except where subsequently confirmed in writing. The opinions expressed in this E-Mail are those of the author and do not necessarily represent the views of the State of Queensland. This E-Mail is confidential and may be subject to a claim of legal privilege. If you have received this E-Mail in error, please notify the author and delete this message immediately. --- - !DEPTSTAMP1! -- Just getting into the best language ever... Fancy a [EMAIL PROTECTED] or something on http://www.perl.me.uk Just ask!!! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: modules - lost again
On Sat, 02 Apr 2005 09:23:53 -0500, Peter Rabbitson wrote: This one is about my Tools.pm which uses Exporter and delivers a set of 5- 10 line subroutines for stupud tasks (number rounder, strip commas from numbers, commify them back, customized html entity decoder etc etc etc). What I am currently doing is automatically exporting ALL these subroutines (using fairly descriptive names to avoid clashes) and use Tools; in all modules that might benefit from them. Pretty standard. However I do not understand if importing just a subset of just the necessary functions is beneficial in terms of speed. What I am thinking is that since every single function IS going to be used sooner or later by at least one of the modules, and since EVERY module is called at least once from the main program over its runtime - the entire Tools.pm is being processed anyway and wether I import all functions or just a few makes no difference on the entire picture. Or am I wrong? Confused. The first use Tools will load Tools.pm and cause *all* of the subroutines to be compiled. Subsequent use Tools won't load Tools.pm because it's in %INC; but, like the first time, *will* call Tools-import(). That call will result in the names being exported. Observe: % cat foo #!/usr/bin/perl -l use Bar; use Foo; % cat Foo.pm package Foo; use Bar; 1; % cat Bar.pm package Bar; sub import { print Bar import } print Bar load; 1; % ./foo Bar load Bar import Bar import And if I am, and specifying explicit imports for each module is beneficial - Not for reason of speed. For reason of maintainability. You should only import names you are going to use, and then do so explicitly, so that a maintenance programmer doesn't look at the program wondering where thunk_widgets() has come from. The exceptions to this rule are few and far between. is Autoloader applicable to this situation? I've seen tons of examples of how OO can benefit from calls to non-existent instances, but I didn't see a single usage of Autoloader in a non-OO envirnoment which leads me to believe that it is not applicable. I think you're confused again. If AUTOLOAD() exists in a package it will be called when a non-existent function is called in that package. Doesn't matter whether or not it's O-O. It isn't going to help you. I assume you meant non-existent methods, because non-existent instances is an oxymoron. Autoloader.pm allows you to put subroutines in a data block so they are only compiled when needed (the autosplit function must be used to copy them to individual files). I've never used it with the Exporter and don't know what would happen; at worst, though, you might need to declare stubs in the main body and then suppress redefinition warnings in the individual definitions. Given the case you describe though, I can't see it making any measurable difference in performance. If you really need to speed things up there are more appropriate ways of doing it. If you don't know you need to speed things up yet, don't throw wacky devices at the code thinking they're doing any good :-) There's more I could say, but I already wrote large parts of a book about it :-) -- Peter Scott http://www.perlmedic.com/ http://www.perldebugged.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: modules - lost again
And if I am, and specifying explicit imports for each module is beneficial - Not for reason of speed. For reason of maintainability. You should only import names you are going to use, and then do so explicitly, so that a maintenance programmer doesn't look at the program wondering where thunk_widgets() has come from. The exceptions to this rule are few and far between. Yep... this says it right there, and makes perfect sense. I am glad I asked before I converted what I have so far to modules. Thank you! Peter -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: .pm and .pl files.
Jay == Jay Savage [EMAIL PROTECTED] writes: Jay I respectfully disagree. I blame Richard Stallman for my habits, not Jay Bill Gates, et. al. 'emacs test' when creating a file opens it in Jay Text Fill, but 'emacs test.pl' when creating a file saves me 'M-x Jay perl-mode' (or 'M-x Cperl-mode', depending). If it's going to end up Jay as an executable, I strip the suffix later. And emacs foo, typing the shebang line, and M-x normal-mode CR *also* gets you into cperl-mode. No need for the extension on foo. Also, never call your program test. Conflicts with the built-in test command. Ick. :) -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 merlyn@stonehenge.com URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Attempting OO with Perl - New() method in subclass not working
Brad == Brad Carlson [EMAIL PROTECTED] writes: Brad Just to clarify, the only reason I don't need a new() method in the Brad subclass is because any class-specific logic is contained in the _init() Brad method for both parent and subclass. If there were no _init() method, Brad then both classes would have a new(), right? Yes. You can either put your per-class initialization into -new, and use SUPER::new for parent classes, or have an _init, which your most-parent-class must remember to call. The latter is a Smalltalk-ish standard, where Object class[1] has something like: new ^self basicNew initialize and initialize[2] looks like initialize ^self Then every derived class that wants additional hooks does: initialize super initialize. my code here. ^self In Perl terms, this would look like: sub new { my $class = shift; my $self = bless [EMAIL PROTECTED], $class; return $self-initialize; # and return this } sub initialize { # base definition my $self = shift; return $self; } sub initialize { # derived definition my $self = shift; $self-SUPER::initialize; $self-{extra} = thing; return $self; } By the way, I really really recommend that people who are doing serious OO get some Smalltalk experience. Smalltalk got a *lot* of things right. Free implementations of Smalltalk for all platforms are available at www.squeak.org, and there's a wealth of both free and commercial publications about learning Smalltalk. [1] Actually, it's in Behavior class. [2] Defined in ProtoObject, the base class for Object -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 merlyn@stonehenge.com URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: First time Parsing XML
Gavin Henry [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Saturday 02 Apr 2005 04:29, Johnstone, Colin wrote: Gidday All, I would like to use xml Parser to parse this chunk of xml (below) and return the business unit name and id attributes for each of the elements where division id = '221' I have tried Why not try: http://search.cpan.org/~grantm/XML-Simple-2.14/lib/XML/Simple.pm If all you want to do is grab a business unit, follow the example on the page above. Stick with XPath. Its definitely easier than trying to deciper the datastructure created by XML::Simple. The XPath query is as simple as: //[EMAIL PROTECTED]'221']/@name See below for solution #!/web/Interwoven/TeamSite/iw-perl/bin/iwperl use XML::XPath; use XML::XPath::XMLParser; my $xpath; my $nodeset; my @memberList; my $arg; my $argVal; my $fileToParse = qq[/web/Interwoven/TeamSite/custom/config/DET_structure.xml]; $xpath = XML::XPath-new( filename = $fileToParse ); $nodeSet = $xpath-find( $xpathQuery ); Where is this $xpathQuery defined? I dont see it anywhere. Are you not using the warnings and strict pragmas. @memberList = map { XML::XPath::XMLParser::as_string( $_ ) } $nodeSet-get_nodelist(); @memberList = map { s|^.*(?=htdocs)||; $_; } @memberList; @memberList = map { s|//|/|g; $_; } @memberList; # %masterList = map { $_, 1 } @memberList; while( @memberList ){ print( $_ . '\n' ); } You are working too hard. Once you decide to go with XPath, stick with it. It can do everything and more that regular expressions can do to xml, and its easier to read. Output of the following program: C:\tempperl xp.pl HR Strategy and Information Policy and Reporting - name may change # xp.pl use warnings; use strict; use XML::XPath; use Data::Dumper; my $query = q|//[EMAIL PROTECTED]'221']/@name|; my $xp = XML::XPath-new( xml = join('', DATA) ); my $node_set = $xp-find( $query ); foreach my $node ( $node_set-get_nodelist ) { print( $node-getNodeValue, \n ); } # the loop can simplify to: # foreach my $node ( $xp-find( $query )-get_nodelist ) { # rendering the $node_set variable unnecessary __DATA__ ?xml version=1.0 encoding=UTF-8? organisation lastUpdate=21/03/05 division name=Office of the Director-General id=202 business-unit name=Correspondence unit id=203/ /division division name=Office of the Deputy Director-General id=276/ division name=Strategic Communications and Marketing id=204 business-unit name=Communications unit id=1002/ /division division name=Strategic Legal Unit id=1003/ division name=Internal Audit id=222/ division name=Strategic Infrastructure Initiatives id=1022/ division name=Human Resource Strategy and Performance id=221 business-unit name=Workforce Capability id=214/ business-unit name=Ethics id=214C/ business-unit name=eDRMS Project id=1024/ business-unit name=Workforce Management id=216/ business-unit name=Strategic Legal and FOI id=1003/ business-unit name=HR Strategy and Information Policy and Reporting - name may change id=221 sub-business-unit name=HR Business/Workforce Planning id=1024/ sub-business-unit name=HR Strategy id=1025/ sub-business-unit name=HR Governance/Governance Structures id=1026/ sub-business-unit name=HR Reporting id=1027/ sub-business-unit name=HR Business Performance and Analysis id=1028/ sub-business-unit name=HR Information System Protocols id=1029/ /business-unit business-unit name=Office of the GM (HR) id=1005/ /division /organisation -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response