From pll at lanminds.com Thu Feb 6 14:05:08 2003 From: pll at lanminds.com (pll@lanminds.com) Date: Mon Aug 2 21:33:07 2004 Subject: [Nh-pm] overloading subs? Message-ID: <20030206200508.80363F833@tater> Hi all, I have a chunk of code which "use"s a module I wrote. I want to be able distribute this code without the requiring the use of this module. Is there any way to have an externally imported sub mask a local one? Basically, what I'd like is this: if (external module) { use that; } else { use this one here; } I think I'm missing something very obvios here, but how can I test if a module has been imported at execution time? IOW, use statements are evaluated at compile time, but any test I do probably needs to be done later on. Any ideas? Thanks, -- Seeya, Paul -- Key fingerprint = 1660 FECC 5D21 D286 F853 E808 BB07 9239 53F1 28EE It may look like I'm just sitting here doing nothing, but I'm really actively waiting for all my problems to go away. If you're not having fun, you're not doing it right! From morbus at disobey.com Thu Feb 6 14:21:42 2003 From: morbus at disobey.com (Morbus Iff) Date: Mon Aug 2 21:33:07 2004 Subject: [Nh-pm] overloading subs? In-Reply-To: <20030206200508.80363F833@tater> Message-ID: <5.2.0.9.2.20030206152030.00affb70@red.totalnetnh.net> >I have a chunk of code which "use"s a module I wrote. I want to be >able distribute this code without the requiring the use of this >module. Is there any way to have an externally imported sub mask a >local one? Basically, what I'd like is this: eval("use Module::Name"); if ($@) { module isn't installed } else { module is installed and loaded } See in-use here: http://disobey.com/d/perl/itunes2html.txt -- Morbus Iff ( i'm the droid you're looking for ) Culture: http://www.disobey.com/ and http://www.gamegrene.com/ Please Me: http://www.amazon.com/exec/obidos/wishlist/25USVJDH68554 icq: 2927491 / aim: akaMorbus / yahoo: morbus_iff / jabber.org: morbus From pll at lanminds.com Thu Feb 27 14:37:26 2003 From: pll at lanminds.com (pll@lanminds.com) Date: Mon Aug 2 21:33:07 2004 Subject: [Nh-pm] Regexp help Message-ID: <20030227203726.8C90EF7C3@tater> Hi, I'm trying to match a MAC addr in perl with a regex. This is what I've got so far: ((([0-9A-F]{2}):){5}$1) But when I do something like $foo = s/.*((([0-9A-F]{2}):){5}$1).*/$1/g ; print "$foo\n"; I get the first 5 octets followed by a ':' like this: 00:E0:81:02:2E: What am I missing? There's got to be something really subtle here I'm not quite getting. Should I be using '?' in there somewhere (something I've never quite understood :) (yes, I know there's a Regexp::Common::net module I could use, but I just need something quick and dirty, and don't want to require an external dependancy just yet if I don't need to) Thanks, -- Seeya, Paul -- Key fingerprint = 1660 FECC 5D21 D286 F853 E808 BB07 9239 53F1 28EE It may look like I'm just sitting here doing nothing, but I'm really actively waiting for all my problems to go away. If you're not having fun, you're not doing it right! From ben at blackavar.com Thu Feb 27 15:28:38 2003 From: ben at blackavar.com (Ben Boulanger) Date: Mon Aug 2 21:33:07 2004 Subject: [Nh-pm] Regexp help In-Reply-To: <20030227203726.8C90EF7C3@tater> References: <20030227203726.8C90EF7C3@tater> Message-ID: <1046381318.3894.0.camel@bensbox.blackavar.com> On Thu, 2003-02-27 at 15:37, pll@lanminds.com wrote: > But when I do something like > > $foo = s/.*((([0-9A-F]{2}):){5}$1).*/$1/g ; > print "$foo\n"; I think you're forgetting to match that last piece there.. how about this: s/.*((([0-9A-F]{2}):){5}[0-9A-F]{2}$1).*/$1/g; From kclark at CetaceanNetworks.com Thu Feb 27 15:34:43 2003 From: kclark at CetaceanNetworks.com (Kevin D. Clark) Date: Mon Aug 2 21:33:07 2004 Subject: [Nh-pm] Regexp help In-Reply-To: <20030227203726.8C90EF7C3@tater> References: <20030227203726.8C90EF7C3@tater> Message-ID: <7csmu9s8zw.fsf@koan.cetaceannetworks.com> pll@lanminds.com writes: > I'm trying to match a MAC addr in perl with a regex. This is what > I've got so far: > > ((([0-9A-F]{2}):){5}$1) In some sense, I can see what you're trying to do with the "$1", but you should know that if you're trying to do something like this, then you need to use \1 instead of $1 (due to how internals of the Perl machine works...). But you're fundamentally using this wrong anyways (\1 will match whatever the regex engine matches, not the actual regex itself) How about this instead?: (?:[[:xdigit:]]{2}:){5}[[:xdigit:]]{2} or, if you wanted to make your code look neat, you could do something like this: $hexre = '(?:[[:xdigit:]]{2}:){5}[[:xdigit:]]{2}'; ($macaddr) = /$hexre/o; ...which I think is something like what you were trying to do in the first place. Hope this helps, --kevin -- Kevin D. Clark / Cetacean Networks / Portsmouth, N.H. (USA) cetaceannetworks.com!kclark (GnuPG ID: B280F24E) alumni.unh.edu!kdc From pll at lanminds.com Thu Feb 27 15:50:07 2003 From: pll at lanminds.com (Paul Lussier) Date: Mon Aug 2 21:33:07 2004 Subject: [Nh-pm] Regexp help In-Reply-To: Message from kclark@CetaceanNetworks.com (Kevin D. Clark) of "27 Feb 2003 16:34:43 EST." <7csmu9s8zw.fsf@koan.cetaceannetworks.com> References: <20030227203726.8C90EF7C3@tater> <7csmu9s8zw.fsf@koan.cetaceannetworks.com> Message-ID: <20030227215007.540B8F7C3@tater> In a message dated: 27 Feb 2003 16:34:43 EST Kevin D. Clark said: >In some sense, I can see what you're trying to do with the "$1", but >you should know that if you're trying to do something like this, then >you need to use \1 instead of $1 (due to how internals of the Perl >machine works...). But you're fundamentally using this wrong anyways >(\1 will match whatever the regex engine matches, not the actual regex >itself) I figured I was missing something fundamental, like understanding how the regex engine really works :) >How about this instead?: > > (?:[[:xdigit:]]{2}:){5}[[:xdigit:]]{2} Just need one more set of () : ((?:[[:xdigit:]]{2}:){5}[[:xdigit:]]{2}) This here works just fine: s/.*((?:[[:xdigit:]]{2}:){5}[[:xdigit:]]{2})/\1/o Thanks much! -- Seeya, Paul -- Key fingerprint = 1660 FECC 5D21 D286 F853 E808 BB07 9239 53F1 28EE It may look like I'm just sitting here doing nothing, but I'm really actively waiting for all my problems to go away. If you're not having fun, you're not doing it right! From pll at lanminds.com Fri Feb 28 15:35:07 2003 From: pll at lanminds.com (Paul Lussier) Date: Mon Aug 2 21:33:07 2004 Subject: [Nh-pm] Regexp help In-Reply-To: Message from kclark@CetaceanNetworks.com (Kevin D. Clark) of "27 Feb 2003 16:34:43 EST." <7csmu9s8zw.fsf@koan.cetaceannetworks.com> References: <20030227203726.8C90EF7C3@tater> <7csmu9s8zw.fsf@koan.cetaceannetworks.com> Message-ID: <20030228213507.48D0DF7C3@tater> In a message dated: 27 Feb 2003 16:34:43 EST Kevin D. Clark said: >How about this instead?: > > (?:[[:xdigit:]]{2}:){5}[[:xdigit:]]{2} Okay, I've stared at this until my brain hurts, and I can't quite be sure I understand what's going on here. I think I've got it, but I'm not sure, so please correct me where I'm wrong :) First we've got: ( gobbldeygook ) more_gobbledeygook The stuff within the parens will be saved as $1, correct? Then, we have within the ()'s: ?:[[:xdigit:]]{2}: I'm a little lost onthe '?:' but the '[[:xdigit:]]{2}:' I'm pretty sure is "Any hex digit twice followed by a :". Now, the '?:', according to perldoc perlre states: "(?:pattern)" "(?imsx-imsx:pattern)" This is for clustering, not capturing; it groups subexpressions like "()", but doesn't make back- references as "()" does. So, I'm assuming that this means the match isn't assigned to one the the $digit vars? Then we've got that mess 5 times, followed by a 2 more hex digits, right? Okay, I think that makes sense. And, if I place the *entire* thing into ()s, I get $1 assigned to that? Thanks, -- Seeya, Paul -- Key fingerprint = 1660 FECC 5D21 D286 F853 E808 BB07 9239 53F1 28EE It may look like I'm just sitting here doing nothing, but I'm really actively waiting for all my problems to go away. If you're not having fun, you're not doing it right! From kclark at CetaceanNetworks.com Fri Feb 28 17:34:02 2003 From: kclark at CetaceanNetworks.com (Kevin D. Clark) Date: Mon Aug 2 21:33:07 2004 Subject: [Nh-pm] Regexp help In-Reply-To: <20030228213507.48D0DF7C3@tater> References: <20030227203726.8C90EF7C3@tater> <7csmu9s8zw.fsf@koan.cetaceannetworks.com> <20030228213507.48D0DF7C3@tater> Message-ID: <9xd6lc56ad.fsf@koan.cetaceannetworks.com> Paul Lussier writes: > First we've got: > > ( gobbldeygook ) more_gobbledeygook > > The stuff within the parens will be saved as $1, correct? No, but in a later paragraph you explain why this isn't so. > Then, we have within the ()'s: > > ?:[[:xdigit:]]{2}: > > I'm a little lost onthe '?:' No, I don't think that you're lost. > but the '[[:xdigit:]]{2}:' I'm pretty > sure is "Any hex digit twice followed by a :". Yup. > Now, the '?:', according to perldoc perlre states: > > "(?:pattern)" > "(?imsx-imsx:pattern)" > This is for clustering, not capturing; it groups > subexpressions like "()", but doesn't make back- > references as "()" does. > > So, I'm assuming that this means the match isn't assigned to one the > the $digit vars? Yes, I just used the (?:pattern) construct for grouping, not capturing. > Then we've got that mess 5 times, followed by a 2 more hex digits, right? Exactly. > Okay, I think that makes sense. And, if I place the *entire* thing > into ()s, I get $1 assigned to that? Yes, that's it exactly. Hope this helps! --kevin -- Kevin D. Clark / Cetacean Networks / Portsmouth, N.H. (USA) cetaceannetworks.com!kclark (GnuPG ID: B280F24E) alumni.unh.edu!kdc