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

I have this simple line of code (its all on one line)
print " The product of the first number:$firstNum and second number:$secNum is:$product\n";
I expect to see the output all on one line, but I get line brakes, why do I get line brakes ?
The real output is:
The product of the first number:7
and second number:5
is:35

Replies are listed 'Best First'.
Re: User Output
by borisz (Canon) on Feb 16, 2005 at 00:25 UTC
    I guess your vars contain linefeeds. Try
    chomp ( $firstNum, $secNum ); print " The product of the first number:$firstNum and second number:$s +ecNum is:$product\n";
    Boris
Re: User Output
by leriksen (Curate) on Feb 16, 2005 at 00:31 UTC
    Prabably because $firstNum is actually the string "7\n", that is, a 7 followed by a newline. You probably got these interactively by reading from a terminal, or you read it as a line from a file, and didnt trim the newline off

    Try doing a chomp($firstNum);

    And guessing you aren't a native english speaker, it is a line break. A brake is what you use on your car to stop. English is such a pain with these type of things, called homophones (meaning same-sounding). You try these ones that are all pronounced the same

    toe tow

    bear bare

    pour paw poor pore

    not knot

    ...it is better to be approximately right than precisely wrong. - Warren Buffet

Re: User Output
by perlsen (Chaplain) on Feb 16, 2005 at 11:03 UTC

    If you are reading the inputs thru user by <STDIN> then you should
    use chomp command to remove the newline charecter.
    then you can see you are output.

    chomp($firstNum=<STDIN>); #$firstNum="7"; $secNum="5"; $product="35"; print " The product of the first number:$firstNum and second number:$s +ecNum is:$product\n";

    thanks

    A reply falls below the community's threshold of quality. You may see it by logging in.