Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default matching

    I have the following code to find a quote in a string and replace it
    with a slashquote.

    ie " goes to \"

    How do I get it to do more than one substitution in the string.


    $_ = $$Rules{$yes}{rule_desc};
    s/"/\\"/;
    $$Rules{$yes}{rule_desc} = $_;

    newbie...

    Eric Walker Guest

  2. Similar Questions and Discussions

    1. Text Matching
      Hi everyone. I am working with an Illustrator 9.0 drawing that was given to my, drawn by someone else. I'm just trying to do some updating to it....
    2. Matching/replacing
      LoneWolf wrote: What exactly is it you need help with? The only potential problem that I see is that the while loop needs a closing '}' bracket....
    3. Matching { } braces ???
      In the example below, I'm testing if a string contains either the { or } braces. The problem is that it is causing me a syntax error. The { on the...
    4. and/or matching question
      Hi, On a web form, I have two fields "US_State" and "Other_State". In my perl script I have.... &no_State unless $FORM{'US_State'}; How...
    5. string matching
      I need to remove $b from $a $a = "abc/\def/ghi" ; $b = "abc/\def"; Regards Kamal
  3. #2

    Default Re: matching

    On Nov 17, 2003, at 4:18 PM, Eric Walker wrote:
    > I have the following code to find a quote in a string and replace it
    > with a slashquote.
    >
    > ie " goes to \"
    >
    > How do I get it to do more than one substitution in the string.
    The /g modifier, for "global".
    > $_ = $$Rules{$yes}{rule_desc};
    > s/"/\\"/;
    > $$Rules{$yes}{rule_desc} = $_;
    Let's clean that up a little. We don't need $_ here.

    $$Rules{$yes}{rule_desc} =~ s/"/\\"/g;

    How's that?

    James

    James Edward Gray II Guest

  4. #3

    Default Re: matching

    Thanks that worked....



    On Mon, 2003-11-17 at 15:27, James Edward Gray II wrote:

    On Nov 17, 2003, at 4:18 PM, Eric Walker wrote:
    > I have the following code to find a quote in a string and replace it
    > with a slashquote.
    >
    > ie " goes to \"
    >
    > How do I get it to do more than one substitution in the string.
    The /g modifier, for "global".
    > $_ = $$Rules{$yes}{rule_desc};
    > s/"/\\"/;
    > $$Rules{$yes}{rule_desc} = $_;
    Let's clean that up a little. We don't need $_ here.

    $$Rules{$yes}{rule_desc} =~ s/"/\\"/g;

    How's that?

    James



    Eric Walker Guest

  5. #4

    Default Re: matching

    On Mon, 17 Nov 2003 15:18:47 -0700, Eric Walker wrote:
    > How do I get it to do more than one substitution in the string.
    By using the /g modifier.
    > $_ = $$Rules{$yes}{rule_desc};
    No. Don't _ever_ try to set $_ yourself, unless you _really_ have to
    (which you don't in this case).
    > $_ = $$Rules{$yes}{rule_desc};
    > s/"/\\"/;
    > $$Rules{$yes}{rule_desc} = $_;
    These three lines could easily have been shortened down to only one;

    $$Rules{$yes}{rule_desc} =~ s/"/\\"/g;

    However: Why do you need to quote the " characters?


    --
    Tore Aursand <tore@aursand.no>

    Tore Aursand Guest

  6. #5

    Default Re: matching

    The /g modifier worked thanks all. I needed to take the quotes in the
    file and backslash them so the file could be read into one of our tools
    without a problem. Thanks for the short version too. I never thought
    of it that way.

    Newbie..

    On Mon, 2003-11-17 at 20:37, Tore Aursand wrote:

    On Mon, 17 Nov 2003 15:18:47 -0700, Eric Walker wrote:
    > How do I get it to do more than one substitution in the string.
    By using the /g modifier.
    > $_ = $$Rules{$yes}{rule_desc};
    No. Don't _ever_ try to set $_ yourself, unless you _really_ have to
    (which you don't in this case).
    > $_ = $$Rules{$yes}{rule_desc};
    > s/"/\\"/;
    > $$Rules{$yes}{rule_desc} = $_;
    These three lines could easily have been shortened down to only one;

    $$Rules{$yes}{rule_desc} =~ s/"/\\"/g;

    However: Why do you need to quote the " characters?


    --
    Tore Aursand <tore@aursand.no>


    --
    To unsubscribe, e-mail: [email]beginners-unsubscribe@perl.org[/email]
    For additional commands, e-mail: [email]beginners-help@perl.org[/email]



    Eric Walker Guest

  7. #6

    Default Re: matching

    At 03:18 PM 11/17/03 -0700, you wrote:
    >I have the following code to find a quote in a string and replace it
    >with a slashquote.
    >
    >ie " goes to \"
    >
    >How do I get it to do more than one substitution in the string.
    >
    >
    >$_ = $$Rules{$yes}{rule_desc};
    >s/"/\\"/;
    >$$Rules{$yes}{rule_desc} = $_;
    >
    >newbie...
    Put a g before the second semicolon above.


    Tim Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139