Solved

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

Posted on 2009-05-08
2
186 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 250 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 84

Expert Comment

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

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

by Batuhan Cetin Regular expression is a language that we use to edit a string or retrieve sub-strings that meets specific rules from a text. A regular expression can be applied to a set of string variables. There are many RegEx engines for u…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

776 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