Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re3: Changing file names as they are uploaded

by blakem (Monsignor)
on Sep 19, 2002 at 11:50 UTC ( [id://199148]=note: print w/replies, xml ) Need Help??


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

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://199148]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-18 07:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found