in reply to Re: Read two values from input
in thread Read two values from input

TJP: Your split is highly commendable -- because you considered the possibility that a user, entering two numbers on a single line might separate them with a space; a comma; or both. ++.

However, you may have heard the (boastful) observation "Perl makes hard things, easy." It seems to me you've done the reverse (or at least, unnecessarily complicated the code) by introducing the sub.

But how about keeping the code simple:

perl -e "my $inp = <>;@input = split /[\s,]+/, $inp; print \"$input[0] : $input[1]\";"

Replies are listed 'Best First'.
Re^3: Read two values from input
by TJPride (Pilgrim) on Nov 28, 2011 at 05:24 UTC
    Because the object is to make easily-readable and reusable code, not code this in the smallest number of characters? The getInput sub is a standard one I include in almost all of my command-line scripts, normally it would just be included via:

    use Library::General;

    Pasting it into the code was just for illustration.