Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Removing unwanted chars from filename.

by harangzsolt33 (Chaplain)
on Oct 08, 2022 at 00:40 UTC ( [id://11147288]=note: print w/replies, xml ) Need Help??

in reply to Removing unwanted chars from filename.

But you want to include plain ASCII characters that are legal though. No?

$FILENAME =~ tr| A-Za-z0-9\!\$\#\%\&\^\`\@\_\-\+\=\~\.\,\;\(\)\[\]\{\} +\/\\||cd;

Replies are listed 'Best First'.
Re^2: Removing unwanted chars from filename.
by hippo (Archbishop) on Oct 08, 2022 at 09:25 UTC

    No. Our anonymous friend clearly wants to remove all the whitespace and the square brackets, both of which your operation keeps.

    What's the story with all those backslashes, BTW?


      Well, I know that the tr operator expects a list of characters, but some of them have special meaning such as the minus sign. Where perlop.html talks about the tr operator, it says,

      "A character range may be specified with a hyphen, so tr/A-J/0-9/ does + the same replacement as tr/ACEGIBDFHJ/0246813579/. For sed devotees, + y is provided as a synonym for tr. If the SEARCHLIST is delimited by + bracketing quotes, the REPLACEMENTLIST has its own pair of quotes, w +hich may or may not be bracketing quotes, e.g., tr[[A-Z]][[a-z]] or t +r(+\-*/)/ABCD/."

      I don't understand what this means. I just know that certain characters have special meanings following the tr operator, so to be on the safe side, I just put a backslash before each.

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-06-15 10:40 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.