in reply to Re: store regex in hash
in thread store regex in hash

Try it like this:
$RGX_EVENTID = qr{\A.*? %(.*?): }xms; if ( $current_line =~ /$RGX_EVENTID/ ) { print "got event_id //$1// from input //$_//\n"; }
Note the use of the qr operator to assign a regex-like string to $RGX_EVENTID, and the use of normal regex match delimiters around that variable when applying the match to another string. (You need to be careful about using regex delimiters that either don't occur within the regex itself, or are properly escaped when they do occur.)

Also, I think it's better to update your OP to fix the formatting there, rather than creating a reply that fixes the formatting.

Update: forgot to mention... Welcome to the Monastery! "OP" refers to "original post" (top of the thread).

Replies are listed 'Best First'.
Re^3: store regex in hash
by johngg (Canon) on Jul 04, 2011 at 09:40 UTC
    and the use of normal regex match delimiters around that variable when applying the match to another string.

    The use of regex match delimiters is not actually necessary when matching against a string as the binding operator provides the context to use the compiled regex. They are needed if doing a default match against $_ without a binding operator.

    knoppix@Microknoppix:~$ perl -E ' > $rx = qr{(\d+)}; > > $str = q{ab12ef}; > $_ = q{gh34kl}; > > say $1 if $str =~ $rx; > say $1 if $rx; > say $1 if m{$rx}; > > $_ = q{mn56qr}; > > say $1 if $_ =~ $rx;' 12 12 34 56 knoppix@Microknoppix:~$

    I hope this is of interest.

    Cheers,

    JohnGG