in reply to Formatting in Perl

You didn't show us any code that might give us some indication as to what you're doing wrong. You should post somewhere less than ten lines of code (in this case) that mimicks the problem. (10 is an arbitrary number, but for such a simple problem is probably sufficient).

If you want me to guess, I'll say your problem is that you are accepting the number of days as input, and forgetting to chomp that input. When the user types "1<enter>", that is captured into the recipient variable as "1\n" (in other words, enter is preserved as a \n (newline) character). chomp the input and the problem will go away, if my guess as to what you are doing wrong is correct.

As for figuring out how to print all that:

print "[$days] day", ($days != 1) ? 's' : '', ' = [', $days * 24 * 60 * 60, "] seconds.\n";

...should do the trick.


Dave

Replies are listed 'Best First'.
Re^2: Formatting in Perl
by tachyon (Chancellor) on Oct 01, 2004 at 03:28 UTC

    printf makes this sort of thing so much more readable....

    printf "[$days] day%s = [%d] seconds.\n", ($days!=1)?'s':'', $days*24* +60*60,
      How do you get your code to look like code when you post?
        Two nodes for you to look at:

        Writeup Formatting Tips is a good introduction.

        This is where you'll find the answer to your question above: the CODE tag

        Another good node for learning shortcuts is: Shortcuts

        Trek