Gossamer Forum
Home : General : Perl Programming :

replace question....

Quote Reply
replace question....
Hi

I have a database with the 2 following colums : ID and filename

1 the first filename
2 the second one
3 another name number3
4 yet another:good one
5 my/filename


With this table I want to build static HTML files : like :

the_name_of_my_file_ID.html

So for my five lines it sould be

the_first_filename_1.html
the_second_one_2.html
another_name_number3_3.html
yet_another_good_one_4.html
my_filename_5.html

So I have made a rule to make some replaces :

$filename =~s/[ ,()'?".\/+-:]/_/g;
$filename =~s/[éèê]/e/g;
$filename =~s/[àâ]/a/g;
$filename =~s/ô/o/g;
$filename =~s/î/o/g;
$filename =~s/ç/c/g;
$filename =~s/____/___/g;
$filename =~s/___/__/g;
$filename =~s/__/_/g;
$filename =lc($filename);

(maybe it could be improved)

It works great : except when I put the : (that I want to be replaced by a underscore linke in the line4) : then all the numbers that are in the URL are not displayed. For example I will have another_name_number_.html for the line 3

Could you halp? have you an idea?Unsure




Txs FMP
Quote Reply
Re: [fmp] replace question.... In reply to
Strange. Try:

\:
Quote Reply
Re: [Paul] replace question.... In reply to
In Reply To:
Strange. Try:

\:


txs for your quick answer

I did it but it didn't work

is my syntax seems good for you?

$filename =~s/[ ,()'?".\/+-:]/_/g;
$filename =~s/[éèê]/e/g;
$filename =~s/[àâ]/a/g;
$filename =~s/ô/o/g;
$filename =~s/î/o/g;
$filename =~s/ç/c/g;
$filename =~s/____/___/g;
$filename =~s/___/__/g;
$filename =~s/__/_/g;
$filename =lc($filename);



txs
Quote Reply
Re: [fmp] replace question.... In reply to
Try:

$filename =~ s/\W/_/g;
$filename = lc $filename;

to replace everything but letters and numbers with an underscore.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] replace question.... In reply to
Hi AlexWink

Works like a charm

txs

FMP