in reply to Using regex with a variable

Hello Praveen Dharmaraj

please first of all reformat your question (edit) addig code tags around your code. See Markup in the Monastery

Second, to store a regex into a variable you need the qr operator; you'll find in the Quote and quote like operator part of perlop

ps as always someone burned me on the time.. so i add a little example.. ;=)

perl -e "$regex = qr/=/; print ref $regex,' ',$regex" Regexp (?^:=)

and see also: /o is dead, long live qr//!

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^2: Using regex with a variable
by Praveen Dharmaraj (Novice) on Mar 14, 2016 at 08:50 UTC

    First of all, sorry for the messy formatting. I am new here. Thanks to you both, using "qr" worked.

    But thing is, I used these variables to reduce the time taken to match. Initially it used to take abt 30 minutes. After using variables, it takes only 10-15 sec. Now after using "qr", it again is taking longer time to match. Reducing the time is my main motto here. This variable problem came up when trying to reduce time.

    Any suggestions ??

      ++ for reformatting your code..

      Now i see that $ur is declared after the regexes.. what your code is supposed to do? if you just put qr in the meanwhile $ur is uundefined and probably is not ywhat you want.. are you using strict and warnings? probably we need more informations about your intention and your possible data inputs.

      L*

      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
        Sorry for the misunderstanding. I wasn't assigning $ur with a value in code. The question is updated now. The value of $ur remains constant throughout the looping of lines. I cannot exactly paste all the code here. I am not allowed to. And yes, I am using "use Strict", "use Warnings".
        Sorry for the misunderstanding. Im not assigning $ur with a value in code. It remains constant through out the looping process. And, I cannot exactly paste my code in here, as Im not allowed to. And yes, Im using "use strict" and "use warnings".