Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: grep for windows

by Athanasius (Archbishop)
on Oct 15, 2016 at 03:05 UTC ( [id://1174052]=note: print w/replies, xml ) Need Help??


in reply to grep for windows

Hello Datz_cozee75,

Fleshing out RonW’s answer a little:

My question is what this line is doing:

$file =~ s,/,\\,g;

It’s replacing / (forward slash) with \\ (backslash) throughout the string $file.

Here, s introduces the substitution operator. It’s normally written s///, but since the string to be substituted is itself a forward slash, a different delimiter has been chosen: a , (comma). See perlretut#Simple-word-matching.

The backslash is doubled because a single backslash introduces an escape sequence — see perlop#Quote-and-Quote-like-Operators. So two consecutive backslashes represent an actual (single!) backslash character.

And of course the /g modifier on the regex causes the substitution to be made globally throughout the string. See perlre#Modifiers.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-04-25 17:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found