Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8570375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:32:38+00:00 2026-06-11T18:32:38+00:00

I have a script taking mythtv recorded shows and encoding them in h264 using

  • 0

I have a script taking mythtv recorded shows and encoding them in h264 using handbrake. the script is written in Perl.

My questions is how do I replace spaces and special characters with and underscore using perl?

The strings look something like this when output "Parks and Recreation - S05E01 - Ms. Knope Goes to Washington"

I would like it to look like this

Parks_and_Recreation_S05E01_Ms__Knope_Goes_to_Washington

Thanks in advance. I did do some googling but having found anything useful that I can implement.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:32:39+00:00Added an answer on June 11, 2026 at 6:32 pm

    Something like this might do it – notice that you might introduce duplicates if you transform strings like this.

    my $input ="Parks and Recreation - S05E01 - Ms. Knope Goes to Washington";
    
    $input =~ s/ - /_/g; # Replace all " - " with "_"
    $input =~ s/[^A-Za-z0-9]/_/g; # Replace all non-alphanumericals with "_"
    
    print $input;
    

    This outputs:

    Parks_and_Recreation_S05E01_Ms__Knope_Goes_to_Washington

    Edit

    Érics comment below is very relevant, here is a slightly better approach that replaces accented characters with unaccented before making substitutions:

    use utf8;
    use Unicode::Normalize;
    
    my $input="La femme d'à côté";
    my $result = NFD($input); # Unicode normalization Form D (NFD), canonical decomposition.
    $result !~ s/[^[:ascii:]]//g; # Remove all non-ascii.
    $result =~ s/ - /_/g; # Replace all " - " with "_"
    $result =~ s/[^A-Za-z0-9]/_/g; # Replace all non-alphanumericals with _
    print $result;
    

    This variant outputs:

    La_femme_d_a_cote

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script that is taking too long to run and I have
I have an Ant script running a standard -task after taking in an inputed
Part of my script is taking values and putting them to a text file
I have two servers running on redhat and debian. I am using a perl
I have a PHP script running that's taking hours, it usually takes a long
I have a little script that replace some text, that come from a xml
I have a numpy script that -- according to top -- is using about
I have a perl script that processes a text file line-by-line and converts phrases
Suppose I have a pretty lengthy PHP script taking exactly 60 seconds. I connect
I have script that reads remote file content and writes it to local server.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.