substituting string of text 
Author Message
 substituting string of text

Please forgive my Perl newbie-ness, but I need help with a line of
code that causing me problems.

I want to substitue one filename with another. I don't know how to
work around the issue of forward slashes in the filename.

I tried this:

-----------CODE-----------------
# convert one bullet graphic to another bullet graphic
  $t =~ s/"/images/static/gfx/bullet.gif"/" http://www.*-*-*.com/ ;/>/gi;
--------------------------------

Attempts to run the script with this line of code didn't work. How can
I identify the address of the graphics without the slashes, or a least
making the script ignore the slashes in the filenames?

Thanks to anyone who can help!



Sun, 05 Dec 2004 22:08:15 GMT  
 substituting string of text
Also sprach jns:

Quote:
> I want to substitue one filename with another. I don't know how to
> work around the issue of forward slashes in the filename.

> I tried this:

> -----------CODE-----------------
> # convert one bullet graphic to another bullet graphic
>   $t =~ s/"/images/static/gfx/bullet.gif"/"http://www.mywebsite.com/images/newbullet.gif"/>/gi;

This can't possibly work since Perl has no means to determine what the delimiters are. You can either escape the forward slashes by prepending a backslash \ or you choose a different set of delimiters, which is preferable here:

    $s =~ s!/images/static/gfx/bullet.gif!http://www.mywebsite.com/images/newbullet.gif!gi;

Tassilo
--

pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;



Sun, 05 Dec 2004 22:24:40 GMT  
 substituting string of text

Quote:

> Please forgive my Perl newbie-ness, but I need help with a line of
> code that causing me problems.

> I want to substitue one filename with another. I don't know how to
> work around the issue of forward slashes in the filename.

> I tried this:

> -----------CODE-----------------
> # convert one bullet graphic to another bullet graphic
>   $t =~ s/"/images/static/gfx/bullet.gif"/"http://www.mywebsite.com/images/newbullet.gif"/>/gi;
> --------------------------------

> Attempts to run the script with this line of code didn't work. How can
> I identify the address of the graphics without the slashes, or a least
> making the script ignore the slashes in the filenames?

Use a delimiter other than '/' for the s/// operator.

$t =~ s{"/images/static/gfx/bullet.gif"}
       {"http://www.mywebsite.com/images/newbullet.gif"/>}gi;

John
--
use Perl;
program
fulfillment



Sun, 05 Dec 2004 22:28:03 GMT  
 substituting string of text

try:
$oim=qq~images/static/gfx/bullet.gif~;
$nim=qq~http://www.mywebsite.com/images/newbullet.gif~;
$t =~ s,$oim,$nim,g;
also remember about muti-line strings & case SENSITIVETY.

Have fun, Eliot



Sun, 05 Dec 2004 22:21:33 GMT  
 substituting string of text

Quote:

> Please forgive my Perl newbie-ness, but I need help with a line of
> code that causing me problems.

> I want to substitue one filename with another. I don't know how to
> work around the issue of forward slashes in the filename.

> I tried this:

> -----------CODE-----------------
> # convert one bullet graphic to another bullet graphic
>   $t =~ s/"/images/static/gfx/bullet.gif"/"http://www.mywebsite.com/images/newbullet.gif"/>/gi;
> --------------------------------

> Attempts to run the script with this line of code didn't work. How can
> I identify the address of the graphics without the slashes, or a least
> making the script ignore the slashes in the filenames?

> Thanks to anyone who can help!

You shouldn't try so much without first trying to figure out what you're
doing. Just typing in random things is going to cause you problems.

$t =~
s!"/images/static/gfx/bullet\.gif"!"http://www.mywebsite.com/images/newbullet.gif"/>!gi;

If you start the substitution with /, you can only use is as
s/stuffhere/newstuffhere/ Otherwise you need to backwack it as in
s/some\/stuff\/here/some\/new\/stuff/\here/

Anyway, the above still doesn't look right, even if it fixes your error
in the code, but I don't want to guess.

Regards,
Robert
--

Server administrator/support - 2Host.com web hosting.
Secure, reliable hosting - What you expect & deserve!
How are we different? Find out: http://www.2host.com/



Sun, 05 Dec 2004 23:58:22 GMT  
 substituting string of text

Quote:

> # convert one bullet graphic to another bullet graphic
>   $t =~ s/"/images/static/gfx/bullet.gif"/"http://www.mywebsite.com/images/newbullet.gif"/>/gi;

$t =~ s/"\/images\/static\/gfx\/bullet\.gif"/"http:\/\/www\.mywebsite\.com\/images\/newbullet\.gif"/;

I think that might work.  I don't know what the >/gi part of your
original code did, so I'm gonna go out on a limb and guess it's not
important.  ;-)  That's like saying, "I've never seen my spleen before
so I guess I don't need it."  Anyway, just tack all that onto the end of
the line if it doesn't work.

Also, learn more about regex's.  do a "man grep" on a linux box or
search for stuff on regex's on google.

chris
--

http://www.headnut.org

"How can you have any pudding if you don't eat your meat?!"



Mon, 06 Dec 2004 00:15:41 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. split and substitute, substitute, substitute

2. Substituting variables in a text file

3. Need help substituting text except when in an HTML anchor

4. methods to insert/substitute blocks of text?

5. substituting text in a var (beginner question)

6. Substituting many strings in one pass over the input

7. Substituting many sparsely distrbuted strings in many files

8. substituting strings in source trees?

9. Pattern Match - substitute a string after the match

10. Repeat string matching/substituting ?

11. substitute a string in array

12. how to substitute letters within a string

 

 
Powered by phpBB® Forum Software