Saturday, October 18, 2008

Learn PPI 2: exchange in condition

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!

Labels:

2 Comments:

Blogger 章亦春 (Agent Zhang) said...

merely some nit-picking in your english (well, I could be wrong as well ;)):

"it's less bugs." => "it's less buggy."

"I wrote another script today for fulfill the above request." => "I wrote another script today to fulfill the above request"

"I'm thinking to package the two scripts into modules then upload to CPAN." => "I'm thinking about packaging the two scripts into modules and uploading to CPAN."

10/18/2008 5:46 PM  
Blogger Fayland said...

thanks. corrected. my poor English.

10/18/2008 6:16 PM  

Post a Comment

Links to this post:

Create a Link

<< Home