vacant has asked for the wisdom of the Perl Monks concerning the following question:
A couple of extra-difficulty points:
The re's are values in a hash, which makes using concatenation not only messy, but impractical, too.
The depth of nesting of sub-expressions is variable, so that multiple slashes would be very difficult to maintain.
If the answer to all this is simple and obvious, I promise to eat several pages of the "Perl Cookbook".
OK, as requested, here is a contrived example I think illustrates the situation:
I just made this up, and it might not work as is, but I think it illustrates the point. The re does, indeed, match one or more legal domain name segments followed by the respective TLD. Unfortunately, instead of matching the dots, it matches any single character, because the "\." need by the re is interpolated by the string operator "" along with the variables $name and $nname. So, if only the interpolation of the characters could be prevented while allowing the interpolation of the variables, this would work, probably.my $name = '(\w[\w-]*\w?)'; # any valid hostname segment my $nnam = "(($name\.)*$name)"; # one or more "name" segments my %domainnames = ( "$nname\.com" => 'a commercial domain', "$nname\.edu" => 'an educational institution', )
Thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: variable interpolation sans character interpolation
by ikegami (Patriarch) on Oct 27, 2005 at 23:41 UTC | |
|
Re: variable interpolation sans character interpolation
by Nkuvu (Priest) on Oct 27, 2005 at 23:44 UTC | |
|
Re: variable interpolation sans character interpolation
by ikegami (Patriarch) on Oct 28, 2005 at 01:28 UTC | |
by vacant (Pilgrim) on Oct 28, 2005 at 03:05 UTC | |
by ikegami (Patriarch) on Oct 28, 2005 at 04:28 UTC | |
|
Re: variable interpolation sans character interpolation
by Tanktalus (Canon) on Oct 27, 2005 at 23:35 UTC |