Mailinglist Archive: opensuse (2532 mails)

< Previous Next >
[opensuse] Quick Perl Question #2 - Why does chomp($float); = "1"?
  • From: "David C. Rankin" <drankinatty@xxxxxxxxxxxxxxxxxx>
  • Date: Sat, 03 May 2008 15:13:02 -0500
  • Message-id: <481CC74E.6060002@xxxxxxxxxxxxxxxxxx>
Listmates,

Perl Q # 2 - and counting. Working with perl, I can't figure out why if I read a number (floating point) from STDIN and then chomp($float); it returns 1. Seems crazy. I can remove the new-line by dividing by 1.0, but that just seems like a hack. What say the gurus? Here is the script:

#!/usr/bin/perl
use warnings;
use strict;

my $TEMPC;
my $TEMPF;

print "Please enter a temperature in degrees C: \n";

$TEMPC=<STDIN>;

print "\$TEMPC before chomp; $TEMPC\n";

$TEMPC=($TEMPC/1.0); # Works! Removes New Line from Number
#$TEMPC=chomp($TEMPC); # Does not work, returns $TEMPC as "1", why?

print "\$TEMPC after chomp; $TEMPC\n";

$TEMPF=($TEMPC * 9 / 5 + 32);

print qq($TEMPC deg. C = $TEMPF def. F\n);

exit 0

--
David C. Rankin, J.D., P.E.
Rankin Law Firm, PLLC
510 Ochiltree Street
Nacogdoches, Texas 75961
Telephone: (936) 715-9333
Facsimile: (936) 715-9339
www.rankinlawfirm.com
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx

< Previous Next >