Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: Is there a way to make these two regex lines cleaner?

by AnomalousMonk (Archbishop)
on Apr 17, 2022 at 22:55 UTC ( [id://11143040]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Is there a way to make these two regex lines cleaner?
in thread Is there a way to make these two regex lines cleaner?

A hyphen placed at the beginning of a character class or tr/// search/replace list is also interpreted literally:

Win8 Strawberry 5.8.9.5 (32) Sun 04/17/2022 18:43:19 C:\@Work\Perl\monks >perl use strict; use warnings; my $s = '123-abc-456'; $s =~ tr/-a-z//cd; print "'$s' \n"; $s = '123-xyz-456'; $s =~ s/[^-a-z]//g; print "'$s' \n"; ^Z '-abc-' '-xyz-'
But one can argue that one is as likely to place new stuff at the start as at the end, so escaping remains wise. :)


Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

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

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

    No recent polls found