my ($old, $new, $reset) = map "\e[${_}m", 91, 92, 0;
Left-hand side: Three variables, $old, $new, $reset.
Right-hand side: A map expression iterating over the three values 91, 92, and 0. map evaluates the expression "\e[${_}m" for each of the three values, resulting in the list "\e[91m", "\e[92m", "\e[0m".
Finally, the three element RHS list is assigned to the LHS list of variables.
The values are ANSI terminal escape sequences for setting text attributes, see https://en.wikipedia.org/wiki/ANSI_escape_code#SGR. 91 selects bright red foreground, 92 selects bright green foreground, 0 resets back to defaults.
Alexander
--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
| [reply] [d/l] [select] |
my ($old, $new, $reset) = map "\e[${_}m", 91, 92, 0;
... doesn't appear to be a common Perl trick ...
It's a very common (and very valuable) Perl "trick". See map and its cousin grep, and see List::Util for many useful functions inspired by the basic behavior of these two built-ins (i.e., iterate over a list and produce another list). As for other examples of the use of this type of function... well, keep your eyes open and I think you'll start to see quite a few, especially in code on this and similar websites. See also Map: The Basics in Tutorials.
Update: Per a /msg from hippo, double-quote "trick" to emphasize that it's not really a trick, but common usage. Also, another minor wording change for clarity.
Give a man a fish: <%-{-{-{-<
| [reply] [d/l] [select] |
Thank you. It's not the behavior of map or grep that was/is mysterious to me, but the particular use of "\e[${_}m", which looks like some manner of regex (which it isn't), and I couldn't figure out what it was supposed to be doing to the numbers. I got hung up on the presence of an open square bracket but no closing square bracket, and the ${_} which looks like some sort of default variable distinct from $_, but for which I could find no definition. If I understand right from afoken's comment, then ${_} substitutes in the values from the provided list, which is what I would have expected $_ to do in a map. Is there anywhere the ${_} form is documented so I could read up on it? I had read the various docs you pointed to and didn't find it there. If it is not a form of its own, why use the curly braces instead of just $_?
| [reply] [d/l] [select] |
$ perl -wE 'say "$_m" for (1 .. 5)'
Use of uninitialized value $_m in string at -e line 1.
Use of uninitialized value $_m in string at -e line 1.
Use of uninitialized value $_m in string at -e line 1.
Use of uninitialized value $_m in string at -e line 1.
Use of uninitialized value $_m in string at -e line 1.
$ perl -wE 'say "${_}m" for (1 .. 5)'
1m
2m
3m
4m
5m
$
HTH.
| [reply] [d/l] [select] |