> todays coding story

Pages: 1

........................................................................

Phillip_McCavity
#1 2007-10-29 22:52:09

todays coding story

Today I was assigned a bug. In a few minutes, I had traced it to some perl code that I had written months ago.

What I had wanted to do was take the string in $foo, convert it to lower case, then assign it to $bar, and so had:

$foo = "some string";
$foo =~ tr/A-Z/a-z/;
$bar = $foo;

except what actually got coded was:

$foo = "some string";
$bar = ($foo =~ tr/A-Z/a-z/);

See the problem?

........................................................................

Zathrus
#2 2007-10-30 00:15:28

Re: todays coding story

Just looking at perl makes me want to rip my eyes out. I can just see the designer of perl gigling maniacally as he changes the original design, something like this:

$bar = $foo.toUpperCase()

To:

$foo = "some string";
$foo =~ tr/A-Z/a-z/;
$bar = $foo;

........................................................................

Phillip_McCavity
#3 2007-10-30 04:38:35

Re: todays coding story

Do you see why after this:

$foo = "some string";
$bar = ($foo =~ tr/A-Z/a-z/);

$bar will be 0?

Not "some string"?

........................................................................

Zathrus
#4 2007-10-30 09:55:16

Re: todays coding story

Phillip_McCavity wrote:

Do you see why after this:


$bar will be 0?

Not "some string"?

No. In a proper language you'd get an error for trying to asisgn a number/boolean to s string. :)

Looks like you went out of your way to make it work. Wouldn't you have got an error if you hadn't put parahenses around the $bar=tr  stuff?

I guess basically you were doing:

$bar= (does $foo=tr stuff)

The right side is false, so it's $foo=0.

Also, aren't you getting a bit too fancy? Couldn't you have just put $foo in the tr thingy, without using the ~ ?

........................................................................

plucky_goatse
#5 2007-10-30 11:24:10

Re: todays coding story

  this morning i finally got rid of the "Click to activate this control" in > IE5 browsers for simple flash content in about  four odd web sites.

this plzDieIE.js file in the site root:

Code:

n=navigator.userAgent;
w=n.indexOf("MSIE");
if((w>0)&&(parseInt(n.charAt(w+5))>5)){
T=["object","embed","applet"];
for(j=0;j<3;j++){
E=document.getElementsByTagName(T[j]);
for(i=0;i<E.length;i++){
P=E[i].parentNode;
H=P.innerHTML;
P.removeChild(E[i]);
P.innerHTML=H;
}}}

then just call the script wif dis line before the ending </body> tag in any htm, asp, php, docs you wanna fix   

Code:

<script language="JScript" type="text/jscript" src="/plzDieIE.js"></script>

i dint even write the script.   krist i kin be a lazy bastid! 
   \
 

........................................................................

Phillip_McCavity
#6 2007-10-30 15:53:09

Re: todays coding story

Zathrus wrote:

No. In a proper language you'd get an error for trying to asisgn a number/boolean to s string. :)

Looks like you went out of your way to make it work. Wouldn't you have got an error if you hadn't put parahenses around the $bar=tr  stuff?

I guess basically you were doing:

$bar= (does $foo=tr stuff)

The right side is false, so it's $foo=0.

Also, aren't you getting a bit too fancy? Couldn't you have just put $foo in the tr thingy, without using the ~ ?

Its not a boolean.

tr is an operator. When you use it with =~, it string binds to the named variable. But if you use =, then it is interpreted in a scalar context, which means "return the count of all converted characters."

$q = "WhyDoesPluckyWriteJavaScript";
$a = $q =~ tr/A-Z/a-z/;

$1 will be 6, $q will be "whydoespluckywritejavascript"

........................................................................

shockeye
#7 2007-11-03 08:13:22

Re: todays coding story

from C, perl looks great (why not just use lib pcre?) but damn the 'treat me like whore i scream like i am in context' nonsence is not worth the wins in other areas like variable disambiguation at declaration. at least in programs > a few pages.

........................................................................

.
#8 2017-02-18 03:33:13

Re: todays coding story

damn, this was from 10 years ago

........................................................................

#9 2017-03-19 06:10:01

Re: todays coding story

. wrote:

damn, this was from 10 years ago

why didn't he just use lc?

........................................................................

#10 2017-03-20 04:44:29

Re: todays coding story

wrote:

why didn't he just use lc?

Phil?

........................................................................

#11 2017-03-21 02:41:27

Re: todays coding story

Great job, phildo! 

........................................................................

Pages: 1