Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

easy extension replace

Status
Not open for further replies.

edog1

Programmer
Oct 9, 2002
12
US
I have a directory that has some files named nnnn.xxx.aaa

these files are in an array and after I do some stuff, I need to ftp them to another server with the .aaa extension removed (nnnn.xxx). I thought I could split on . i have something like :

@files = system("ls *.xxx.aaa");
foreach $files (@files){
@file_name = split(/\./, $files);
print "$file_name[0].[1]";
}

no go, whats up, In sed I would just s/.aaa//, don't make me do sumting like system("echo $files|cut -d . -c1-2");

thanks in advance
 
I don't see why you couldn't just do
Code:
foreach $files (@files){
     $files =~ s/\.aaa$//;
     # etc...
}
The reason that your posted code didn't work was because you need to specify the array name each time you index it:
[tt]
foreach $files (@files){
         @file_name = split(/\./, $files);
         print "$file_name[0].$file_name[1]";
}
[/tt]
you could also use a join statement on an array slice
Code:
print join '.', @file_name[0..$#file_name-1]
which would allow for names like 'nnn.nnn.xxx.aaa'.

jaa
 
Code:
opendir DIR, ".";
@files=readdir DIR;
closedir DIR;
foreach $file (@files){
         ($file_a = $file) =~ s/.pl//;
         print "[$file_a]\n";
}

This does some of what you ask now its time for a pint!
;> Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top