freelanceprogrammers.org Forum Index » Perl

string help


View user's profile Post To page top
c_dito Posted: Mon Jun 27, 2005 7:54 pm


Joined: 27 Jun 2005

Posts: 1
string help
Hi,
I`m debugging code written by someone else.
How do I modify the code to include the `Gi` on the front of the port
number?

here`s the input:
300 0000.0c07.ac02 DYNAMIC Gi1/0/12

here`s the code:
if (/([0-9a-f]{2})([0-9a-f]{2}).([0-9a-f]{2})([0-9a-f]{2}).([0-9a-
f]
{2})([0-9a-f]{2})s+.*(d+/d+/d+)/)
{
$hostmac = $1 . "-" . $2 . "-" . $3 . "-" . $4 . "-" . $5 . "-
" . $6;
$hostport = $7;
print "mac: $hostmac, port: $hostport
";
}

here`s the actual output:
mac: 00-00-0c-07-ac-02, port: 1/0/12

here`s the desired output:
mac: 00-00-0c-07-ac-02, port: Gi1/0/12
Reply with quote
Send private message
View user's profile Post To page top
paulalapatt Posted: Fri Jul 01, 2005 4:33 pm


Joined: 06 Apr 2005

Posts: 12
string help
>
>
> ________________________________________
> From: perl_official@yahoogroups.com [mailto:perl_official@yahoogroups.com]
On Behalf Of c_dito
>
> here`s the input:
> 300 0000.0c07.ac02 DYNAMIC Gi1/0/12
>
> here`s the code:
> if (/([0-9a-f]{2})([0-9a-f]{2}).([0-9a-f]{2})([0-9a-f]{2}).([0-9a-
> f]
> {2})([0-9a-f]{2})s+.*(d+/d+/d+)/)

This "(d+/d+/d+)" in the above regex means series of digitis separated
by /, which is evidently 1/0/12 in your case.

To accommodate Gi which I presume will be a set of the type w the regex can
be modified to "(w+d+/d+/d+)"

> {
> $hostmac = $1 . "-" . $2 . "-" . $3 . "-" . $4 . "-" . $5 . "-
> " . $6;
> $hostport = $7;
> print "mac: $hostmac, port: $hostport
";
> }
>
> here`s the actual output:
> mac: 00-00-0c-07-ac-02, port: 1/0/12
>
> here`s the desired output:
> mac: 00-00-0c-07-ac-02, port: Gi1/0/12
>

Take care,
Paul Alapatt

http://www.bernardlabs.org/


>
>
>
>
>
>________________________________________
>YAHOO! GROUPS LINKS
>
>•  Visit your group "perl_official" on the web.

>•  To unsubscribe from this group, send an email to:
> perl_official-unsubscribe@yahoogroups.com

>•  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
>
________________________________________
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help