Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^13: Immediately writing the results of search-and-replace

by elemkeh (Acolyte)
on Aug 12, 2022 at 13:40 UTC ( [id://11146117]=note: print w/replies, xml ) Need Help??


in reply to Re^12: Immediately writing the results of search-and-replace
in thread Immediately writing the results of search-and-replace

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 $_?

Replies are listed 'Best First'.
Re^14: Immediately writing the results of search-and-replace
by hippo (Bishop) on Aug 12, 2022 at 13:52 UTC

    $_ and ${_} are the same. You are free to enclose the name of any variable in curly brackets after its sigil. In this case they are required because the use is to append an m immediately after the $_ and if you were to write $_m then that would look for a scalar variable with name _m which doesn't exist. eg:

    $ 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.


    🦛

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11146117]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (1)
As of 2024-04-25 12:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found