Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2020-09-25 10:35 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (137 votes). Check out past polls.