geniezlife has asked for the wisdom of the Perl Monks concerning the following question:
The problem with the above is that it treats the NAME in the 'if' line as plaintext, rather than the constant I defined. I know I could do something like -use constant NAME => "abc"; # read some user input my $input = $ARGV[0]; # I need to check if the input string contains my constant # Something like the following is what I need: if ($input =~ /NAME/) { print "Matched!"; }
but I want to avoid that variable. So 2 questions for the enlightened ones here -my $name = NAME; if ($input =~ /$name/) { ... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: using constants in regex/search
by f00li5h (Chaplain) on Dec 02, 2008 at 04:52 UTC | |
by geniezlife (Initiate) on Dec 02, 2008 at 08:51 UTC | |
|
Re: using constants in regex/search
by plobsing (Friar) on Dec 02, 2008 at 14:46 UTC | |
|
Re: using constants in regex/search
by JavaFan (Canon) on Dec 02, 2008 at 09:50 UTC | |
by spmlingam (Scribe) on Dec 02, 2008 at 11:34 UTC | |
by JavaFan (Canon) on Dec 02, 2008 at 11:43 UTC | |
by spmlingam (Scribe) on Dec 03, 2008 at 07:59 UTC | |
by JavaFan (Canon) on Dec 03, 2008 at 10:11 UTC | |
| |
by ikegami (Patriarch) on Dec 03, 2008 at 08:27 UTC |