Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: Regex (?{ code }) and use re 'eval'

by mwah (Hermit)
on Nov 21, 2007 at 19:20 UTC ( [id://652206]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Regex (?{ code }) and use re 'eval'
in thread Regex (?{ code }) and use re 'eval'

i want to take a hash of simple regex ie(0-9, a-z) and match them in square brackets/box brackets

Under these conditions, your "example 6" would look sth. like:

use strict; use warnings; my %Build = ( jj => '0-9', kk => 'a-z', ); my $message = '[445] [5353453] [fff] [445]'; my $message6 = $message; while( my ($k,$v) = each %Build) { my %speed_fix; if(my @re_match = $message6 =~ m{ (?<=\[) [$v]+ (?=\]) }xisg ) { foreach my $m_check (@re_match) { next if $speed_fix{$m_check}; if( my $built = return_number($m_check) ) { $message6 =~ s{ \[ $m_check \] }{$built}xisg; ++$speed_fix{$m_check}; } } } } print "$message6\n"; sub return_number { my $numbers = shift; return $numbers; }

Maybe one could delete more stuff - if you could provide an exact specification of the problem.

Regards

mwa

Replies are listed 'Best First'.
Re^4: Regex (?{ code }) and use re 'eval'
by SFLEX (Chaplain) on Nov 21, 2007 at 20:04 UTC
    it looks nice, but i do not know what you meant by "sth."
    The problem i found in the example 6 was when the "@re_match" is made it can have repeated values(thats why i have a check to see if its been used) and kinda seemed to me that it could take up to much resources if I used a larger message.
      sth. = something

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://652206]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-19 15:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found