jar00n has asked for the wisdom of the Perl Monks concerning the following question:
Working on a new script and was hoping to set a variable named $icase and attempt to match a string with this variable used as the operator. So if $icase is defined then it will be equal to 'i' otherwise it'll be undef. With that in mind, is that even logical/efficient/doable? Quick demo to show what I'm seeing:
Which when ran produces this:#!/usr/bin/perl $icase = 'i'; $str = 'ASdf'; if ( 'asdf' =~ /$str/$icase ) { print "it works!\n" }
$ perl test.pl Scalar found where operator expected at test.pl line 6, near "/$str/$i +case" (Missing operator before $icase?) syntax error at test.pl line 6, near "/$str/$icase " Execution of test.pl aborted due to compilation errors.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Can you use a scaler as an operator?
by hippo (Bishop) on Jan 22, 2014 at 10:04 UTC | |
by AnomalousMonk (Archbishop) on Jan 23, 2014 at 00:12 UTC | |
by jar00n (Novice) on Jan 22, 2014 at 21:28 UTC | |
Re: Can you use a scaler as an operator?
by Eily (Monsignor) on Jan 22, 2014 at 10:06 UTC |
Back to
Seekers of Perl Wisdom