in reply to Re: print command runs after call to subroutine
in thread print command runs after call to subroutine

The alternative you suggest for the display subroutine makes sense. So I guess it's good practice to always have a sub return a value and have that display in the "main" portion of the code rather than print anything within the sub itself (unless of course there is a specific need for that to happen)?

As for your other recommendations, to address those, I was just trying to write a sub that can accept any number of parameters rather than a fixed amount. I would imagine that in a more concrete scenario, a fixed number more likely be used.

Thank you for the help.
  • Comment on Re^2: print command runs after call to subroutine

Replies are listed 'Best First'.
Re^3: print command runs after call to subroutine
by Corion (Patriarch) on Oct 19, 2016 at 13:12 UTC

    Personally, I've found that in most situations I don't want subroutines to print out stuff, because having them print stuff makes it harder to suppress that output later, when rewriting the script.

    Perl does not enforce the number of parameters anyway, so you can always write the following:

    sub display { ... }; display(1,2); display(1,2,3,4);