RE: Confusion About A Little Piece Of Code

  • From: PRAKASH P <P.Prakash@xxxxxxx>
  • To: "programmingblind@xxxxxxxxxxxxx" <programmingblind@xxxxxxxxxxxxx>
  • Date: Thu, 12 May 2011 13:37:43 +0000

Normally when you read from  stdin  kind of input where end of line  markers 
are used to   end the current input,  the new line markers  are not read in  to 
the field.  So  experiment  before you  begin "chomping: on it unnecessarily.

This can get expensive depending on the  size of the array.
Prakash


From: programmingblind-bounce@xxxxxxxxxxxxx 
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Humberto Rodriguez
Sent: Wednesday, May 11, 2011 8:44 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: Re: Confusion About A Little Piece Of Code

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<mailto:james.homme@xxxxxxxxxxxx>
To: programmingblind@xxxxxxxxxxxxx<mailto: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.

This email and any attachments are intended solely for the use of the 
individual or entity to whom it is addressed and may be confidential and/or 
privileged.

If you are not one of the named recipients or have received this email in error,

(i) you should not read, disclose, or copy it,

(ii) please notify sender of your receipt by reply email and delete this email 
and all attachments,

(iii) Dassault Systemes does not accept or assume any liability or 
responsibility for any use of or reliance on this email.

For other languages, go to http://www.3ds.com/terms/email-disclaimer

Other related posts: