Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Output split over two lines

by idsfa (Vicar)
on Dec 23, 2006 at 17:47 UTC ( #591462=note: print w/ replies, xml ) Need Help??


in reply to Output split over two lines

The variable $price contains all of your input, which includes the new line (Enter). When you print it out as a string in the last line, the new line is printed as well. This doesn't happen later in that line when the price in pounds is printed because you are printing the result of an arithmetic calculation, and the newline is silently dropped (from both $price and $yen) when they are treated as numbers instead of strings ... no they don't cancel out ;-).

There is a command in perl specifically for stripping the Enter key results from your input: chomp. Although it is related to chop, which shmem suggested, it is superior for this purpose because it will work on different platforms (Unix, Windows, Mac OS, etc). chop will not give you what you want in Windows (for example), where the enter key appends two characters.


The intelligent reader will judge for himself. Without examining the facts fully and fairly, there is no way of knowing whether vox populi is really vox dei, or merely vox asinorum. — Cyrus H. Gordon


Comment on Re: Output split over two lines
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://591462]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (9)
As of 2014-08-20 04:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (105 votes), past polls