How about this:
my @filenames = glob("*.*.noheadscript");
my $fn;
foreach $fn (@filenames)
{
$fn =~ s/\.noheadscript//;
}
use Data::Dumper;
print Dumper \@filenames; # <== your desired result
Greg
Erik Price wrote:
> Hi,
>
> I'm just starting learning Perl and I'm trying to write a simple Perl
> script that will change a file's name for me.
>
> All of my filenames match the following pattern:
>
> \w+-\d{2,2}\.php\.noheadscript # ex: "index0-18.php.noheadscript"
>
> and I want to remove the ".noheadscript" part. This can be done really
> easily in bash using a foreach loop and then using bash's awkward
> globbing to "mv" the filename to the new filename, but two things -- I
> don't have a reference handy for the advanced globbing syntax and I'd
> rather do it in Perl as an exercise anyway. I think what I have so far
> would work except that I don't know how to print to the file's name --
> it's not the same thing as printing to a file's contents as far as I can
> tell.
>
> #!/usr/bin/perl -w
>
> # hsnamerewrite.pl
> # stupid script that changes the name of a file
>
> use strict;
>
> foreach my $file (@ARGV) {
> $file =~ s!^([\w-]+\.php)\.noheadscript!$1!;
> }
>
> The above script would work fine if I was attempting the substitution
> against a line or some kind of file data, but not the filename itself.
> Can someone give me a pointer?
>
> Thanks,
>
> Erik
>
> ----
>
> Erik Price
> Web Developer Temp
> Media Lab, H.H. Brown
> [EMAIL PROTECTED]