[Israel.pm] A regexp question

Itzik Lerner lerner at perl-expert.com
Mon May 17 06:21:47 PDT 2004


the explenation is:
  in the first case:
    $mac is           8      :   0   :   2   0   :    9   f   :   2   2   :
7   8
                   $1   $2   $3
allthow you are using the 'g' option , there is just one match, becouse each
time you have to continues bytes with one digit, the first match is 'eating'
the colon character,

if for instance your string will be:
                              8      :  4 0   :   2    :    9   f   :   2
2   :   7   8
it will do the job.

when you do the while loop it solves the problem becouse every iteration it
starts over again
that way 'para para' it is 'dofeking' the hole 'eder' ....

as you can imagine you didnt choose the optimal regexp to do what you want
to do
try harder ...

--Itzik


----- Original Message ----- 
From: "Ishay Inbar" <ishay at checkpoint.com>
To: "'Perl in Israel'" <perl at perl.org.il>
Sent: Monday, May 17, 2004 5:44 AM
Subject: RE: [Israel.pm] A regexp question


> The question is not how to do it in another way - like in everything there
are many ways to do the same action. The question is why
> the global flag does not work in this regexp...
>
> -----Original Message-----
> From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On Behalf
Of Oron Peled
> Sent: Sunday, May 16, 2004 7:18 PM
> To: ishay at checkpoint.com; Perl in Israel
> Subject: Re: [Israel.pm] A regexp question
>
> On Sunday 16 May 2004 18:15, Ishay Inbar wrote:
> > just get the left value, for example from Solaris:
> > 8:0:20:9f:22:78, where the first and the second couples start with 0.
>
> Why not simply (not tested):
>   @vals = split(/[:-]/, $mac);
>   die "Bad value" if @vals != 6; # Optional sanity checking
>   $mac = sprintf("%02x:%02x:%02x:%02x:%02x:%02x", @vals);
>
> Havn't benchmarked, but at least it looks more robust to me.
>
> -- 
> Oron Peled                             Voice/Fax: +972-4-8228492
> oron at actcom.co.il                  http://www.actcom.co.il/~oron
>
> A physicist, an engineer, and a computer scientist were
> discussing the nature of God.  Surely a Physicist, said the
> physicist, because early in the Creation, God made Light; and you
> know, Maxwell's equations, the dual nature of electro-magnetic
> waves, the relativist consequences... An Engineer!, said the
> engineer, because before making Light, God split the Chaos into
> Land and Water; it takes a hell of an engineer to handle that big
> amount of mud, and orderly separation of solids from
> liquids... The computer scientist shouted: And the Chaos,
> where do you think it was coming from, hmm?
>
> ---Anonymous
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://www.perl.org.il/mailman/listinfo/perl
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://www.perl.org.il/mailman/listinfo/perl
>
>



More information about the Perl mailing list