Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Why did you become a Perl expert (or programmer)?

by Veltro (Hermit)
on Jun 26, 2018 at 16:59 UTC ( #1217445=note: print w/replies, xml ) Need Help??

in reply to Why did you become a Perl expert (or programmer)?

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; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1217445]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2021-01-25 16:21 GMT
Find Nodes?
    Voting Booth?