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; }
and
$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
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |