grashopr has asked for the wisdom of the Perl Monks concerning the following question:

Whenever I execute the following...
print "Currency converter\n\nPlease enter the exchange rate: "; my $yen = <STDIN>; print "Please enter first price to convert"; my $price1 = <STDIN>; print $price1, "Yen is ", ($price1/$yen), " pounds\n"; I get... Currency converter Please enter the exchange rate: 100 Please enter first price to convert 100 100 Yen is 1 pounds I can't figure out why there is a new line created on line 6 after print and before $price1? Thanks, -John

Replies are listed 'Best First'.
Re: newline issue
by syphilis (Archbishop) on Apr 11, 2015 at 05:54 UTC
    I can't figure out why there is a new line created

    You think you entered "100", but you in fact entered "100\n". (Hitting the "Enter" button does that.)

    Just chomp $price1; straight after <STDIN> has been assigned to it and the newline will be removed.

    Cheers,
    Rob
Re: newline issue
by pme (Monsignor) on Apr 11, 2015 at 07:10 UTC
    BTW, you should also chomp $yen.
    chomp $yen;
    for more details, see chomp
Re: newline issue (ddumper)
by Anonymous Monk on Apr 11, 2015 at 07:26 UTC
Re: newline issue
by grashopr (Initiate) on Apr 11, 2015 at 15:05 UTC

    chomp worked perfectly! Thanks all. I feel it's a little of a cheat since we haven't learned chomp
    yet in the course I'm taking. But I'm glad it works.
    Learned something new!

    On to the next challenge!