[% setvar title Perl should have a print operator %]

This file is part of the Perl 6 Archive

Note: these documents may be out of date. Do not use as reference!

To see what is currently happening visit http://www.perl6.org/


Perl should have a print operator


  Maintainer: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
  Date: 5 Aug 2000
  Last Modified: 20 Sept 2000
  Mailing List: perl6-language-io@perl.org
  Number: 39
  Version: 4
  Status: Retracted


Perl supplies an operator for line input - angle brackets. This is no analogous operator for output. I propose "inverse angle brackets":

    >"Print this line.\n"<;


It seems that I am alone in loving the proposed syntax. It's short, it works the way I want, it fits into my brain. As a matter of fact, I've found myself trying to use it in code that I am currently working on. But this RFC suffers a fatal flaw - perl already has a perfectly good print operator. Perl is a language designed to be spoken by people, so it should be comfortable to people (even if they don't think exactly like me :).


Easy things should be easy

Output is already easy in Perl, but it could be easier. For one thing, it doesn't nest well in statements:

    while (<>){
      push @line, $_;

This could be written:

    push @line, >$_< while <>;

Printing to STDOUT and some other file ala tee(1):

    print $fh >"This also goes to stdout.\n"<;

Another problem with print is that the ()s are optional. perlop points out the following traps:

    print $foo, exit;
    print ($foo & 255) + 1, "\n";

They could be correctly written as:

    >$foo<, exit;
    >($foo & 255) + 1, "\n"<;

Ugly as a virtue

A representative comment of this RFC is "Ick!" -- Jonathan Scott Duff <duff@cbi.tamucc.edu> This RFC doesn't mind (nor does its maintainer). The print operator should be quick and dirty - used as an afterthought or side-effect. When you are looking for it, the print operator should stick out. When you are looking for something else (and have gotten used to the syntax), it should blend into the sea of punctuation. Do you remember when you first saw <FH>, or i++ (in C)? Compact syntax with side-effects, such as the print operator, should be ugly.

This operator _will_ be misused, just as `STRING` (qx/STRING/) is misused. It will cause confusion just as the conditional operator (?:) causes confusion. It will be as jarring as =~ is to those who have never seen it. Perl is operator rich whether you like it or not.

print will still be there

Not all output is suited for inverse angle brackets. Most output will still go through print. Prints to files should use 'print FH LIST' so that the return value can be checked (and the filehandle specified). Long documents should be printed with the expanded form on their own lines so that they are emphasised. 'print "Hello world\n";' should remain the canonical 'first Perl script'. We still need print for practical and stylistic reasons.




print LIST to the default output filehandle (normally STDOUT) and return LIST. It should have the same precedence as other list operators

Migration from Perl 5

Inverse angle brackets are currently a syntax error, so no translation will be needed.



RFC 2: Request For New Pragma: Implicit

RFC 34: Angle brackets should not be used for file globbing

RFC 51: Angle brackets should accept filenames and lists



perldebug/"Debugger Commands"/{p,x}