Re: RFC 39 (v3) Perl should have a print operator
[email protected] (Nathan Wiger) Tue, 05 Sep 2000 17:46:58 -0700
| Newsgroups | perl.perl6.language.io |
|---|---|
| Organization | Sun Microsystems |
| Message-ID | <[email protected]> |
Jon Ericson wrote:
>
> I would want it to return @items:
>
> @sorted = sort print @items;
>
> I'd prefer a different name (tee?) and keep print as it is.
Pretty much all the stuff being discussed right now can be stuck in a
module:
package Print::Variations;
use Exporter;
@EXPORT = qw(printl println printj);
sub printl {
# return list as-is
print(@_) ? return @_ : return undef;
}
sub printj {
# return joined string
my $str = join '', @_;
print(@_) ? return $str : return undef;
}
sub println {
# add a newline and return T/F
print(@_, "\n");
}
#! perl -w
use Print::Variations;
# Make Bart and me happy
$formatted = printj $r->param('name'), " is $age years old.\n";
# Make Jon happy
@sorted = sort { $a <=> $b } printl "@items\n";
# Make the Pascal lovers happy
println "Hello, World!";
Is all this stuff cool? Maybe. Does it belong in core? Definitely not.
Is it important enough to warrant special operators? I remain
unconvinced.
Granted, these functions can't handle different filehandles, etc, but if
some of the RFC's get included that attempt to fix this it should be
trivial.
-Nate