18 October 2008
This post may be outdated due to it was written on 2008. The links may be broken. The code may be not working anymore. Leave comments if needed.
as what I posted before, I want to convert
if ( $a eq 'a' ) {
to
if ( 'a' eq $a ) {

PBP encourages it because it's less buggy.

I wrote another script today to fulfill the above request.
http://fayland.googlecode.com/svn/trunk/script/learn_ppi/02ExchangeCondition.pl

things like
my $a = "a";
my $b = "'b'";
my $c = 'c';
my $d = qq~d~;
if ( $a eq "a" ) {
print "1";
} elsif ( $b eq 'b') {
print "2";
} elsif ( $c ne qq~c~) {
print "3";
} elsif ( $c eq q~d~) {
print '4';
} else {
print '5';
}
if ( $a eq $b ) {
print '6';
}
if ( $c eq '$d' ) {
print 7;
}
if ( $a =~ /$b/ ) {
print 8;
}
if ( $a == '$b' or $c == '$d' ) {
print 9;
}
will be converted into
my $a = "a";
my $b = "'b'";
my $c = 'c';
my $d = qq~d~;
if ( "a" eq $a ) {
print "1";
} elsif ( 'b' eq $b ) {
print "2";
} elsif ( $c ne qq~c~) {
print "3";
} elsif ( q~d~ eq $c ) {
print '4';
} else {
print '5';
}
if ( $a eq $b ) {
print '6';
}
if ( '$d' eq $c ) {
print 7;
}
if ( $a =~ /$b/ ) {
print 8;
}
if ( '$b' == $a or '$d' == $c ) {
print 9;
}

I know it's not perfect. it's just a start.

hmm, I'm thinking about packaging the two scripts into modules then uploading to CPAN.
but I can't find a good name(or namespace) for them.

I'll try later.

Thanks and Enjoy!


blog comments powered by Disqus