Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: What is the difference between s/ and tr/

by valdez (Monsignor)
on Apr 15, 2003 at 15:06 UTC ( #250590=note: print w/replies, xml ) Need Help??


in reply to What is the difference between s/ and tr/

From perlop:

tr/SEARCHLIST/REPLACEMENTLIST/cds
y/SEARCHLIST/REPLACEMENTLIST/cds

Transliterates all occurrences of the characters found in the search list with the corresponding character in the replacement list. It returns the number of characters replaced or deleted. If no string is specified via the =~ or !~ operator, the $_ string is transliterated. (The string specified with =~ must be a scalar variable, an array element, a hash element, or an assignment to one of those, i.e., an lvalue.)

From perlrequick:

Search and replace
Search and replace is performed using "s/regex/replacement/modifiers". The "replacement" is a Perl double quoted string that replaces in the string whatever is matched with the "regex". The operator "=~" is also used here to associate a string with "s///". If matching against $_, the "$_ =~" can be dropped. If there is a match, "s///" returns the number of substitutions made, otherwise it returns false.

Ciao, Valerio

  • Comment on Re: What is the difference between s/ and tr/

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (1)
As of 2022-01-17 05:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (51 votes). Check out past polls.

    Notices?