in reply to Re: Changing file names as they are uploaded
in thread Changing file names as they are uploaded

wouldn't that still leave me with "J.R_ewing.jpg"?
  • Comment on Re: Re: Changing file names as they are uploaded

Replies are listed 'Best First'.
Re3: Changing file names as they are uploaded
by blakem (Monsignor) on Sep 19, 2002 at 11:50 UTC
    How about:
    my $rindex = rindex($imagename,'.'); $rindex = length($imagename) if $rindex == -1; substr($imagename,0,$rindex) =~ s/\W/_/g;
    It will exclude the extension from the substitution.

    Update: Fixed bug for filenames w/o extensions that end in a nonword char.

    Update2: Thought I'd golf this one a bit:

    substr($file,0,rindex($file,'.')%length"a$file") =~ s/\W/_/g;
    works correctly for $files such as "me~swimming.jpg", "J.R,ewing.jpg" and "abc;;;"

    -Blake