Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   very strange behaviour (http://www.velocityreviews.com/forums/t895329-very-strange-behaviour.html)

fedeabascal@yahoo.es 11-24-2005 03:02 PM

very strange behaviour
 
Dear all,

I'm finding a very strange behaviour of perl when trying to print
something. Look at this code:

print " Number of informative (entropy < ",$fields{'ENTROPY'}," and
gaps < ",$fields{'GAPS'},") columns : $ok_columns\n",
print " Number of columns considered poorly informative
: ", scalar(keys(%discarded_columns)), "\n";

The result is that the second "print" prints before the first "print".
Always. Look at the output:


Number of columns considered poorly informative : 33
Number of informative (entropy < 4.2 and gaps < 0.2) columns : 214
1


Additionally, after both "prints" are printed a newline with just a "1"
is printed.

Both things happen with different operative systems. If I replace both
lines with:

print "hello\n";
print "bye\n";

then, everything works as expected. The output is:

hello
bye


I can't imagine why this happens!!

Best,
Federico


fedeabascal@yahoo.es 11-24-2005 03:16 PM

Re: very strange behaviour
 
je,je,je... I've been trying to solve this error for long time having
some headache and now, just when I send it to the group I have noticed
what was the problem. If you would like to find yourself do not
continue reading. The solution is.....

....


.....


.....

After the first print there is not a semicolon (";") but a comma (",").

Federico


Anno Siegel 11-24-2005 03:38 PM

Re: very strange behaviour
 
<fedeabascal@yahoo.es> wrote in comp.lang.perl.misc:
> je,je,je... I've been trying to solve this error for long time having
> some headache and now, just when I send it to the group I have noticed
> what was the problem. If you would like to find yourself do not
> continue reading. The solution is.....
>
> ...
>
>
> ....
>
>
> ....
>
> After the first print there is not a semicolon (";") but a comma (",").


The way your code is formatted makes the mistake specially hard to
spot.

print " Number of informative (entropy < ",$fields{'ENTROPY'}," and
gaps < ",$fields{'GAPS'},") columns : $ok_columns\n",
print " Number of columns considered poorly informative
: ", scalar(keys(%discarded_columns)), "\n";

Use white space for indentation and otherwise to make clear
where each print statement and each of its parameters begin and end:


print " Number of informative (entropy < ",
$fields{'ENTROPY'},
" and gaps < ",
$fields{'GAPS'},
") columns : $ok_columns\n",

print " Number of columns considered poorly informative : ",
scalar(keys(%discarded_columns)),
"\n";

That takes a few more lines, but now the misplaced comma stands
out like a sore thumb. That is why proper formatting is important
in programming. It's not just because it looks nicer, though that's
a valid reason too.

Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.


All times are GMT. The time now is 10:45 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.