Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Think about Loose Coupling
 
PerlMonks  

Replacing strings

by perl_99_monk (Novice)
on Apr 25, 2006 at 16:14 UTC ( [id://545633]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

perl_99_monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a multi line string stored in a variable. I want to replace all the occurences of %ad with another variable stored in $temp. Any suggestions..... Thanks

Replies are listed 'Best First'.
Re: Replacing strings
by Tanktalus (Canon) on Apr 25, 2006 at 16:32 UTC
    $var =~ s/%ad/$temp/g

    What did you try?

Re: Replacing strings
by SamCG (Hermit) on Apr 25, 2006 at 16:52 UTC
    I suggest this node on asking questions effectively. Unless tanktalus really has hit on your basic issue, in which case, congratulations on your economy of means (though I still think you'd be well-served by making your question more explicit).



    -----------------
    s''limp';@p=split '!','n!h!p!';s,m,s,;$s=y;$c=slice @p1;so brutally;d;$n=reverse;$c=$s**$#p;print(''.$c^chop($n))while($c/=$#p)>=1;
Re: Replacing strings
by GrandFather (Saint) on Apr 25, 2006 at 17:02 UTC

    Well, we can make guesses at what you mean. But a little sample code like the following would allow us to answer your actual question rather than any one of the many we could invent for you.

    use strict; use warnings; my $temp = 'Plugh'; my $str = <<STR; To %ad or not to %ad, that is the question. Oh %ad on you. STR $str =~ s/%ad/$temp/g; print $str;

    Prints:

    To Plugh or not to Plugh, that is the question. Oh Plugh on you.

    If that isn't the answer to the question you were intending, please alter the sample code to illustrate what you really want to know. You ought to read I know what I mean. Why don't you? BTW. It was written for you.

    Update: fix cut and paste problem


    DWIM is Perl's answer to Gödel
      I guess you meant either

      my $temp = 'xyzzy';

      or

      To Plugh or not to Plugh. that is the question. Oh Plugh on you.

      Perhaps that should be "Oh plague on cut and paste" :-)

      Cheers,

      JohnGG

        Argh ...

        A plague on doing stuff in a hurry while the world is falling apart :)


        DWIM is Perl's answer to Gödel

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://545633]
Approved by Corion
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.