wind has asked for the wisdom of the Perl Monks concerning the following question:
Now, I only observed this in the process of helping someone on another forum with their malformed code. In that example the best way to fix their issue was /(?:\Q$var\E){5}/.my $string = 'aaaaa'; my $var = 'a'; my %var = (5 => 'hash interpolated'); print "String: $var{5}\n"; print "Regex: ", ($string =~ /$var{5}/ ? 'scalar interpolated' : 'hash + interpolated'), "\n"; print "Regex (force hash): ", ($string =~ /${var{5}}/ ? 'scalar' : 'ha +sh'), "\n"; print "Regex (force scalar): ", ($string =~ /${var}{5}/ ? 'scalar' : ' +hash'), "\n"; # Output is: # String: hash interpolated # Regex: scalar interpolated # Regex (force hash): hash # Regex (force scalar): scalar
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Interpolation differences between Strings and Regular Expressions (weight)
by tye (Sage) on Jun 13, 2007 at 02:32 UTC | |
by grinder (Bishop) on Jun 13, 2007 at 06:28 UTC | |
by TimToady (Parson) on Jun 13, 2007 at 19:35 UTC | |
|
Re: Interpolation differences between Strings and Regular Expressions
by naikonta (Curate) on Jun 13, 2007 at 02:37 UTC | |
|
Re: Interpolation differences between Strings and Regular Expressions
by aquarium (Curate) on Jun 13, 2007 at 06:13 UTC |