Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Heard about Perl much longer ago but never thought about looking into it until one day, I did a search for a backup script and found this Perl program. So I installed Perl and downloaded the script and it worked very well. I started to become curious now, but it looked difficult, wtf are all those special characters doing...

Then came a time that I needed find and replace something in a file and since I had Perl on my computer now I gave it a shot and started testing.

I went back in my archives and here are the two little gems:

while (<>) { next if /^$/; print; }


$text = "A'B'C" ; $text = replacequote($text); print $text; sub replacequote { my $X=$_[0]; while ( $X =~ /\'/ ) { (my $l, my $r) = split ( /\'/, $X, 2); $X = "$l\\QUOTE$r"; } while ( $X =~ /\\QUOTE/ ) { (my $l, my $r) = split ( /\\QUOTE/, $X, 2); $X = "$l\\'$r"; } return $X; } sub replacequote_better { my $X=$_[0]; while ( $X =~ /[^\\]\'/ ) { #This line does not give the desired result that I have in mind (l rem +ains empty): (my $l, my $r) = split ( /[^\\]\'/, $X, 2); #print "left: $l\n"; #print "right: $r\n"; @array = split ( /[^\\]+\'/, $X, 2); print $_, "|" foreach @array; print "\n" ; $X = "$l\\'$r"; #print "new $X\n" ; } return $X; }

In reply to Re: Why did you become a Perl expert (or programmer)? by Veltro
in thread Why did you become a Perl expert (or programmer)? by QM

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (12)
    As of 2021-01-25 17:38 GMT
    Find Nodes?
      Voting Booth?