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

  • SEARCH
  • Home
  • 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 8316969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:28:51+00:00 2026-06-08T21:28:51+00:00

Before I start off, I’d like to let you know that I’m no Perl

  • 0

Before I start off, I’d like to let you know that I’m no Perl expert. I’m just starting out because of some specific tasks assigned to me.

The requirement of this task is to extract the extension of the file (.dat) and replace it with .trg. The problem is we are zipping the .dat file to make $filename.dat.gz and when we extract the extension and replace it we get $filename.dat.trg while want we would ideally want is $filename.trg.

As for the code (mind you, this seems to be a very old ‘legacy’ code and I don’t want to tinker with it too much as it was/is being maintained by another person), this is how it is put down

#prepare the trigger file
#get the extension  
my @contains_extension = split (/\./ , $filename);
my $ext = $contains_extension[-1];

#replace with  a ".trg" extension
my $remote_trgfile = $filename;
$remote_trgfile =~ s/$ext$/trg/;
my $trgfile = $out;
$trgfile =~ s/$ext$/trg/;

Remember $filename in the above code is suffixed with .dat.gz i.e., the filename is $filename.dat.gz

I would appreciate if someone could help me out with an easier way to extract both the extensions (.dat and .gz) and replacing it with .trg

  • 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-08T21:28:52+00:00Added an answer on June 8, 2026 at 9:28 pm

    So you want to change the ‘extension’ of a filename, including a optional .gz? Try:

    $filename =~ s{\.[^.]*(?:\.gz)?$}{.trg}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, to start off, I want to point out that I know that these
Let me start off by clarifying that(before you guys dismiss me), this is not
before I start I want to point out that I tagged this question as
Let me start off by saying that I am very new to WPF and
Let me start off with some code. When the application loads, it calls the
To start things off, let me explain that I'm working with a class that
To start things off, let me explain that I'm working with a class that
Before start let me tell my experience: I am experienced with C#.NET, web services,
Am using Mediainfo library in my C# project,before start invoking this dll,i just ran
Before I start, I want to make it clear that my code is working

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.