in reply to pipe one function output to another

There's actually a general answer to this question, and that answer is yes. If you have two functions, func1 and func2 (forgive my startlingly clever and original naming convention) and func2 returns a list, and func1 operates on a list, Perl will work from right to left, and func1 will operate on the list you get from func2. Mostly. It'll violate your intuitive expectations a lot, though:
my @stuff=qw(foo bar baz); print join "\n",@stuff,"\n"; print "test!\n"; ------------ foo bar baz test!
because it joined (@stuff,"\n") (a perfectly legal list) using "\n" instead of joining @stuff and then putting one last \n on the end.

Replies are listed 'Best First'.
Re^2: pipe one function output to another
by johngg (Canon) on Aug 14, 2009 at 20:35 UTC
    print join "\n",@stuff,"\n";

    Your code results in a double newline at the end of the string being printed, which might not fit the requirement. Why not use parentheses so that join only operates on @stuff? Or why not make the last item being joined an empty string? Another way would be to modify the default list separator (see $LIST_SEPARATOR or $" in perlvar).

    $ perl -e ' > my @stuff = qw{ foo bar baz }; > > print join qq{\n}, @stuff, qq{\n}; > print qq{Tail of test 1\n}; > > print join( qq{\n}, @stuff ), qq{\n}; > print qq{Tail of test 2\n}; > > print join qq{\n}, @stuff, q{}; > print qq{Tail of test 3\n}; > > print do{ local $" = qq{\n}; qq{@stuff\n} }; > print qq{Tail of test 4\n};' foo bar baz Tail of test 1 foo bar baz Tail of test 2 foo bar baz Tail of test 3 foo bar baz Tail of test 4 $

    I hope this is of interest.

    Cheers,

    JohnGG

      Exactly. There are many ways to fix that, my point wasn't to fix it, my point was to show that it takes a bit of practice to train your intuition to operate on lists that way.