Re: Confusion About A Little Piece Of Code

  • From: "Humberto Rodriguez" <sub@xxxxxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Wed, 11 May 2011 20:43:40 -0400

Hello Jim:

I am certainly no expert, but in my experience, you should always use chomp 
when extracting the values of the elements of an array.  At any rate, it 
couldn't hurt, because it will remove only the new line character or \n at the 
end of the line, if any.

Humberto

  ----- Original Message ----- 
  From: Homme, James 
  To: programmingblind@xxxxxxxxxxxxx 
  Sent: Wednesday, May 11, 2011 10:11 AM
  Subject: Perl: Confusion About A Little Piece Of Code


  Hi,

  Maybe I'm not understanding this. Here is some code.

  print "Enter some numbers on separate lines: ";

  my $user_total = total(<STDIN>);

   

  I'm pretending that there's a subroutine that adds up the numbers.

   

  I'm thinking that I would enter the numbers from the keyboard on separate 
lines, and when I'm done, I'd press the key combination that signals end of 
input.

   

  When the program gets the array, I'm thinking that each line would have a new 
line on the end of it.

   

  Here's where the question comes in.

   

  Would the subroutine need to use the chomp function to get rid of the new 
lines before it adds up the numbers, or would it be happy with the line endings?

   

  Thanks.

   

  Jim

  Jim Homme,

  Usability Services,

  Phone: 412-544-1810.

   



------------------------------------------------------------------------------
  This e-mail and any attachments to it are confidential and are intended 
solely for use of the individual or entity to whom they are addressed. If you 
have received this e-mail in error, please notify the sender immediately and 
then delete it. If you are not the intended recipient, you must not keep, use, 
disclose, copy or distribute this e-mail without the author's prior permission. 
The views expressed in this e-mail message do not necessarily represent the 
views of Highmark Inc., its subsidiaries, or affiliates.

Other related posts: