Forum Moderators: coopster & phranque

Message Too Old, No Replies

Removing the %20

         

steekyjim

6:07 am on Dec 14, 2004 (gmt 0)

10+ Year Member



Hi, I'm trying to remove the %20 from filenames:

So say I'm starting with:

$File = 'DJ%20JUM%20-%20Um%20Buffalo%202001%20intro.mp3';

How can I manipulate the value of file to make it as follows:

$File = 'DJ JUM - Um Buffalo 2001 intro.mp3'

I want this to be able to take the %20 out of any strings I throw at it.
Thanks if you can help,
John

moltar

6:41 am on Dec 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WW, steekyjim!

$File =~ s/\%20/ /g;

rocknbil

6:00 pm on Dec 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



/\/\ That'll work. But to remove ALL web-encoded characters the sub from any read/parse will work.

$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

That gets %20, %26, %3B, %3F . . . .
;-D

adni18

11:01 pm on Dec 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just out of curiosity, what would happen if you did this?

$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("D", hex($1))/eg;

moltar

3:17 pm on Dec 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nothing would happen to it. It would stay the way it is.

pack(TEMPLATE,LIST)

Takes an array or list of values and packs it into a binary
structure, returning the string containing the structure. The
TEMPLATE is a sequence of characters that give the order and type
of values, as follows:

A An ascii string, will be space padded.
a An ascii string, will be null padded.
c A signed char value.
C An unsigned char value.
s A signed short value.
S An unsigned short value.
i A signed integer value.
I An unsigned integer value.
l A signed long value.
L An unsigned long value.
n A short in network order.
N A long in network order.
f A single-precision float in the native format.
d A double-precision float in the native format.
p A pointer to a string.
x A null byte.
X Back up a byte.
@ Null fill to absolute position.
u A uuencoded string.
b A bit string (ascending bit order, like vec()).
B A bit string (descending bit order).
h A hex string (low nybble first).
H A hex string (high nybble first).