Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Changing the extension of a .txt file to .pl file

Posted on 2009-05-08
2
Medium Priority
?
209 Views
Last Modified: 2012-05-06
I am having a an array like
@array=('a.txt','b.txt',c.txt);
i want to convert the extension of these files to .pl

I did like
foreach  @array
{
tr /.*.tx/.*.p/;
print $_."\n";
}

But it is printing like
a.plp
b.plp
c.plp
How can i print like a.pl,b.pl,c.pl
0
Comment
Question by:ashok1312
2 Comments
 
LVL 39

Accepted Solution

by:
abel earned 1000 total points
ID: 24334462
the tr command replaces each letter of its first argument with the corresponding letter in the replacement string. It is not a regular expression. I think what you are after was this:

s/\.txt$/.pl/;
instead.
0
 
LVL 85

Expert Comment

by:ozo
ID: 24334483
foreach(  @array )
{
s/\.txt$/.pl/;
print $_."\n";
}
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question