Loading ...
Sorry, an error occurred while loading the content.

Substitute a single-quote syntax

Expand Messages
  • hooyar66
    I would like to know the correct syntax to allow me to substitute an apostrophe (or single-quote) with a backslash prefix. The following code s/( )/ /g;
    Message 1 of 6 , Feb 1 7:10 AM
    • 0 Attachment
      I would like to know the correct syntax to allow me to substitute an
      apostrophe (or single-quote) with a backslash prefix.

      The following code

      s/(\')/\\\'/g;

      comments all the subsequent code until the next single-quote
      character appears.

      The following code does what I want, but relies on using a memory
      variable

      s/(\')/\\$1/g;

      Thanks
    • hooyar66
      ... an ... This: /( )/ /g; Should read: / / /g; Removed the unnecessary paretheses. Any ideas? NJH
      Message 2 of 6 , Feb 1 12:52 PM
      • 0 Attachment
        --- In perl-beginner@yahoogroups.com, "hooyar66" <pcbcad@...> wrote:
        >
        > I would like to know the correct syntax to allow me to substitute
        an
        > apostrophe (or single-quote) with a backslash prefix.
        >
        > The following code
        >
        > s/(\')/\\\'/g;
        >
        > comments all the subsequent code until the next single-quote
        > character appears.
        >
        > The following code does what I want, but relies on using a memory
        > variable
        >
        > s/(\')/\\$1/g;
        >
        > Thanks
        >

        This:

        /(\')/\\\'/g;

        Should read:

        /\'/\\\'/g;


        Removed the unnecessary paretheses.

        Any ideas?

        NJH
      • merlyn@stonehenge.com
        ... hooyar66 Any ideas? About what? Looks like you solved it. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
        Message 3 of 6 , Feb 1 1:30 PM
        • 0 Attachment
          >>>>> "hooyar66" == hooyar66 <pcbcad@...> writes:

          hooyar66> Any ideas?

          About what? Looks like you solved it.

          --
          Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
          <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
          Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
          See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
        • hooyar66
          ... 777 0095 ... training! ... Hi Randal No still not solved it. The code below although it looks correct is not being interpreted correctly: ########### #!
          Message 4 of 6 , Feb 2 2:50 AM
          • 0 Attachment
            --- In perl-beginner@yahoogroups.com, merlyn@... wrote:
            >
            > >>>>> "hooyar66" == hooyar66 <pcbcad@...> writes:
            >
            > hooyar66> Any ideas?
            >
            > About what? Looks like you solved it.
            >
            > --
            > Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503
            777 0095
            > <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
            > Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
            > See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
            training!
            >

            Hi Randal

            No still not solved it.

            The code below although it 'looks' correct is not being interpreted
            correctly:

            ###########
            #! perl
            use strict;
            use warnings;
            use diagnostics;

            my $text = 'A ver~sion, of 5 6 NJH\'s SD card \'which\'
            enab\'@#~%les the PCB itself to be plug\'ged (directly) i@nto a
            #,standard SD card input connector';

            $text =~ s/\'/\\\'/g;

            print "\$text:\n$text\n\n";

            print 'The previous single-quote should be a opener not a closing
            quote';

            ###########

            The second single-quote in my substitution line is not being escaped
            causing all subsequent code - until the next single-quote - to be
            treated as a sting.

            They say 'a picture is worth a thousand words', the link below will
            show a screenshot of my text-editor which uses Perl syntax colour
            coding.

            http://tinyurl.com/yrja7g

            Thanks
            NJH
          • Rob Biedenharn
            ... Your problem is in thinking that this is a Perl issue. It s just your editor. Mine handles this code just fine:
            Message 5 of 6 , Feb 2 5:58 AM
            • 0 Attachment
              On Feb 2, 2007, at 5:50 AM, hooyar66 wrote:
              > --- In perl-beginner@yahoogroups.com, merlyn@... wrote:
              >>>>>>> "hooyar66" == hooyar66 <pcbcad@...> writes:
              >>
              >> hooyar66> Any ideas?
              >>
              >> About what? Looks like you solved it.
              >>
              >> --
              >> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503
              >> 777 0095
              >> <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
              >> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
              >> See PerlTraining.Stonehenge.com for onsite and open-enrollment
              >> Perl training!
              >>
              >
              > Hi Randal
              >
              > No still not solved it.
              >
              > The code below although it 'looks' correct is not being interpreted
              > correctly:
              >
              > ###########
              >
              > The second single-quote in my substitution line is not being escaped
              > causing all subsequent code - until the next single-quote - to be
              > treated as a sting.
              >
              > They say 'a picture is worth a thousand words', the link below will
              > show a screenshot of my text-editor which uses Perl syntax colour
              > coding.
              >
              > http://tinyurl.com/yrja7g
              >
              > Thanks
              > NJH

              Your problem is in thinking that this is a Perl issue. It's just
              your editor. Mine handles this code just fine:
              http://agileconsultingllc.com/single_quote.png

              -Rob

              Rob Biedenharn http://agileconsultingllc.com
              Rob@...
            • hooyar66
              ... 503 ... etc. ... interpreted ... escaped ... will ... Thanks Rob - time to change my editor ;-)
              Message 6 of 6 , Feb 2 6:14 AM
              • 0 Attachment
                --- In perl-beginner@yahoogroups.com, Rob Biedenharn <Rob@...> wrote:
                >
                > On Feb 2, 2007, at 5:50 AM, hooyar66 wrote:
                > > --- In perl-beginner@yahoogroups.com, merlyn@ wrote:
                > >>>>>>> "hooyar66" == hooyar66 <pcbcad@> writes:
                > >>
                > >> hooyar66> Any ideas?
                > >>
                > >> About what? Looks like you solved it.
                > >>
                > >> --
                > >> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1
                503
                > >> 777 0095
                > >> <merlyn@> <URL:http://www.stonehenge.com/merlyn/>
                > >> Perl/Unix/security consulting, Technical writing, Comedy, etc.
                etc.
                > >> See PerlTraining.Stonehenge.com for onsite and open-enrollment
                > >> Perl training!
                > >>
                > >
                > > Hi Randal
                > >
                > > No still not solved it.
                > >
                > > The code below although it 'looks' correct is not being
                interpreted
                > > correctly:
                > >
                > > ###########
                > >
                > > The second single-quote in my substitution line is not being
                escaped
                > > causing all subsequent code - until the next single-quote - to be
                > > treated as a sting.
                > >
                > > They say 'a picture is worth a thousand words', the link below
                will
                > > show a screenshot of my text-editor which uses Perl syntax colour
                > > coding.
                > >
                > > http://tinyurl.com/yrja7g
                > >
                > > Thanks
                > > NJH
                >
                > Your problem is in thinking that this is a Perl issue. It's just
                > your editor. Mine handles this code just fine:
                > http://agileconsultingllc.com/single_quote.png
                >
                > -Rob
                >
                > Rob Biedenharn http://agileconsultingllc.com
                > Rob@...
                >

                Thanks Rob - time to change my editor ;-)
              Your message has been successfully submitted and would be delivered to recipients shortly.