[% setvar title C changes. %]

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/


chomp() changes.


  Maintainer: Ted Ashton <ashted@southern.edu>
  Date: 7 Aug 2000
  Mailing List: perl6-language@perl.org
  Number: 58
  Version: 1
  Status: Developing


The current return value of chomp() is little-used and tends to confuse those learning perl. Here is presented a change to chomp()'s return value and to the while(<FILEHANDLE>) construction.


This RFC contains two proposed changes. First, as it is common to want to removed newlines upon reading a file,

  while (chomp(<FILEHANDLE>)) {
    . . .

should become the equivalent of

  while (<FILEHANDLE>) {
    . . .

or, to put it more explicitly,

  while (defined($_ = <FILEHANDLE>)) {
    chomp $_;
    . . .

where the various equivalent constructions would, of course, work as expected.

Second, as it seems common for someone learning perl to expect

  $without_newline = chomp($previous_form);

to put a copy of the text in $previous_form, sans newline, into $without_newline while not modifying $previous_form, Perl should do just that.

chomp() called in void context would remove the newline from the variable (or members of the list) upon which it was called. chomp() called in a scalar context would leave its argument variable untouched and instead return a chomp()ed version of that variable's contents. Likewise and furthermore for other contexts.


As I know little about perl5 internals and even less about perl6, I shall simply present the following notes:


  The Camel II, pp 53 and 149.