Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic if statements possible?

Status
Not open for further replies.

PJYelton

Programmer
Jan 29, 2003
19
US
I'm fairly new to perl and had a question. Is there an easy way to do something like this without using a whole lot of if statements:

Code:
my $s = "=~";  # could also possibly be "!~", "<=", etc etc
my $b = "^";   # could also be "", "$", etc etc
my $t = "blah"

my $phrase = "blah bleh bluh";

if ($phrase $s /$b $t $b/) {  # equates to "if $phrase =~ /^blah/"
    # this block should run since the statement is true
}

 
You can't use the operator like that (your $s variable). However, you can build up a regexp with variables. The way you're doing it equates to /^ blah ^/ - you have spaces in your regexp, so the regexp engine will try to match those.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top