Perl6 RFC Librarian wrote:
> The new C<$DEFIN> accomplishes a similar thing, but with
> input. Currently, the special <> filehandle acts on one of
> two things, either C<@ARGV> or <STDIN> (if C<@ARGV> is
> empty).

This is not strictly true.  <> is shorthand for <ARGV>.  ARGV is the
special filehandle that opens each file in @ARGV.  If @ARGV is empty,
$ARGV[0] is set to '-'.  perlop/"I/O Operators" has a detailed
explanation.  RFC 51 (v3 coming soon) is an attempt to simplify and
generalize this behavior.  

> With C<$DEFIN>, the sequence is instead C<@ARGV> or
> C<$DEFIN>. This adds valuable functionality:
> 
>    # Figure out our input source based on what's open
>    $DEFIN = $infile || $instream || $STDIN;
>    @data = <>;
> 
> This allows valuable compartmentalization of code. The
> simple <> construct is now a synonym for C<$DEFIN>. This
> means that you can place something like the C<@data = <>>
> line in a module, and allow the top-level code to change
> the data source based on a simple assignment. You no
> longer have to pass filehandles into functions or do
> complex C<tie> manuevers to gain this ability.

  @ARGV = ('filename');
  # code passes
  @data = <>;

> Plus, with C<$DEFIN>, if you have a routine that must
> read from C<$STDIN>, you can still do so easily by
> explicitly saying:
> 
>    $yes_or_no = <$STDIN>;   # explicitly from $STDIN
>    @data = <>;              # read from $DEFIN
> 

  $yes_or_no = <STDIN>; # read from STDIN
  @data = <>;           # read from ARGV

Jon
-- 
Knowledge is that which remains when what is
learned is forgotten. - Mr. King

Reply via email to