in reply to Regex with variables?

Use qr//. It is used to store a regex in a variable. Think you want something like this.
my $re = qr/.+\-(.+)/; $foo =~ s/$re/$1/;
but if all are in domain-computer form, you could just use
$foo =~ s/.+\-(.+)/$1/;
Update: but on second thought the first way could run in a loop and you could just define the regex before the loop using qr//. That would probably be more efficient.

Example:
use strict; my $re = qr/.+\-(.+)/; while(<DATA>){ s/$re/$1/; print; } __DATA__ domain-comp1 domain-comp2 domain-comp3
Output:
comp1 comp2 comp3

Replies are listed 'Best First'.
Re: Re: Regex with variables?
by Quadzilla (Initiate) on Aug 22, 2003 at 15:13 UTC
    Thanks tcf22! Thanks for taking the time to answer my question! That's exactly what I was trying to achieve.

    “Pie Iesu Domine. Dona eis Requiem.” Whack!