[Israel.pm] regex substitue with lookup table

Yossi.Itzkovich at ecitele.com Yossi.Itzkovich at ecitele.com
Sun Mar 28 05:44:05 PST 2004


Thanks.

I used the longer one (I usually prefer readability), but I wanted to know
the shorter way to.

Yossi



                                                                                                                                   
                      "Offer Kaye"                                                                                                 
                      <oferk at oren.co.i         To:      "Perl in Israel" <perl at perl.org.il>                                        
                      l>                       cc:                                                                                 
                      Sent by:                 Subject: RE: [Israel.pm] regex substitue with lookup table                          
                      perl-bounces at per                                                                                             
                      l.org.il                                                                                                     
                                                                                                                                   
                                                                                                                                   
                      03/28/2004 12:02                                                                                             
                      Please respond                                                                                               
                      to Perl in                                                                                                   
                      Israel                                                                                                       
                                                                                                                                   
                                                                                                                                   



> Hi,
>
> I have a code that looks like this:
>
> if (/someText (.+?) someMoreText (\d+)/)
> {
>       if (exists $hash{$2})
>       {
>             my $newStr=$hash{$2};
>             s/someText $newStr someMoreText/;
>       }
> }
>
> I know There Is Another Way To Do It, and even a shorter one - how ?
>
> Thanks
>
> Yossi
>

> Sorry,
> It should be:
> s/someText (.+?) someMoreText/someText $newStr someMoreText/;
>


Ah, I see now. Well, I guess one shorter version of the above code is:
s/someText (.+?) someMoreText (\d+)/(exists $hash{$2})?"someText $hash{$2}
someMoreText $2":"someText $1 someMoreText $2"/e;

But frankly in this case I personally would go for the longer way- it's
simply more readable.

----------------------------------
Offer Kaye
_______________________________________________
Perl mailing list
Perl at perl.org.il
http://www.perl.org.il/mailman/listinfo/perl







More information about the Perl mailing list