[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cgi-list
Subject:    Re: [CGI] desperate
From:       Terry Brown <Terry.Brown () ncl ! ac ! uk>
Date:       1999-03-23 8:21:22
[Download RAW message or body]

At 15:51 22/03/99, Jan Krynicky wrote:
>> 
>> 
>> 
>> I made a program that reads a HTML file, replacing every $blahblah$ in
>> the HTML with $blahblah and every $blahblah[ ]$ with $blahblah[ ] with
>> the following two lines
>> 
>>       s/ \$(\w+\[\d+\])\$/${$1}/g;      #doesn't work
>>       s/ \$(\w+)\$/${$1}/g;            #works
>> 
>> Why doesn't the first one work, the secong one does work??? If I try to
>> make a rerence to a list item, I never get the right result, I just get
>> blank.
>> 
>> if I remove the $, using
>> 
>>     s/ \$(\w+\[\d+\])\$/{$1}/g;
>> 
>> it does give {$blahblah[1]}, but when I add $, it doesn't return
>> $blahblah[1]. (I have set that to "GRRRRR" and it doesn't return that.)

s~(\$\w+)(\[.*?\])?(\$)~$1$2~igs;

Should do it on all strings you mention above.

e.g.
$string = 'This is a $blahblah$ test to see if $moreblah[junk]$ will
                do some valid $blah[]$ substitutions on
$variables[$thatlookfunny]$';

$string =~ s~(\$\w+)(\[.*?\])?(\$)~$1$2~igs;

$string now = This is a $blahblah test to see if $moreblah[junk] will
                do some valid $blah[] substitutions on
$variables[$thatlookfunny]

HTH,
Tez

Terry Brown			http://numedsun.ncl.ac.uk/
C&IT Development Officer
Faculty of Medicine Computing Centre
University of Newcastle, NE2 4HH
Tel: +44 191 222 5116	Fax: +44 191 222 5016

PGP: 22A4 6205 0F2D 9DD7 5614  DD77 99AD FAD9 D766 E18F
-----------------------------------------------------------------
To unsubscribe, send mail to "majordomo@jann.com" with "unsubscribe cgi-list"
in the body.

The CGI Tips & Tricks website (and archive of the list) is located
at http://perl.jann.com/

cgi-list is hosted by Summit Communication Design (http://www.summitdesign.net).

Summit Communication Design is a full-service web hosting firm
providing web design, cgi programming and inter/intra-net support.
-----------------------------------------------------------------

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic