in reply to Having a "default" hash value!

It looks like you're just doing the same thing to all the strings: you're wrapping some sort of terminal-display escape sequence around each matched string, but it's always the same escape sequence ( "\e[31m ... \e[0m"). So why do you need a look-up hash at all?

Also, it looks like you're keeping the open-angle-bracket but deleting the close-angle-bracket -- is that intentional, or a bug?

Here's how I would do it (assuming the close-angle-bracket should be kept):

my $openesc = "\e[31m"; my $closesc = "\e[0m"; s/^(.*<)\:([a-z]+)/$1$openesc$2$closesc/;

Replies are listed 'Best First'.
Re^2: Having a "default" hash value!
by Ace128 (Hermit) on Mar 03, 2006 at 07:40 UTC
    Ah, well, I got that escape code from Term::Color actually :) Dont ask me why its like that, but it works... I dont get the left bracket either... there was no right bracket in the code in that module either. Also, the code is just part of a bigger hash, where I also have \e[32m \e[33m etc... counting up to 47 or so...
      My comment about "deleting the right angle bracket" was not about the escape codes, which always use a single left-square bracket after the ascii "esc" character, because... well, whoever thought it up must have felt it was a good idea at the time.

      I was pointing out that your regex substitution went like this:

      s/(^.*<)\:([a-z]+)>/$1$hash{$2}/;
      Note that you are keeping the left-angle bracket ("<") as part of the first capture ($1), but you are not keeping the associated right-angle bracket (">") -- that one is being deleted, because it's part of the matched pattern, but not part of the replacement string.

      If that's what you want, fine. I just thought it looked a bit like a bug.

        Ah. Sorry then. Well, the code is somewhat modified from the original, so I may have missed something...