The reason your multiChomp fails is because you are setting @out from $_, instead of from @_; it is the latter that holds the arguments to the function.
Just a couple of observations. One is that you don't need the loop in multiChomp; you can achieve the exact same results with chomp @out. Also, I don't see the utility of chomping the entire array and then returning only the first chomped element, which is what multiChomp does in scalar context. A more useful thing would be to return the concatenation of the chomped elements. Taken all this together, I would rewrite multiChomp like this:
sub multiChomp { my @out = @_; chomp @out; return wantarray ? @out : join '', @out; }
Or you could do this:
( my $text = do { local $/, @ARGV = 'foo.txt'; <> } ) =~ s/\n+//g;
the lowliest monk
In reply to Re: How to slurp files and join lines
by tlm
in thread How to slurp files and join lines
by alecclews
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |