http://qs1969.pair.com?node_id=11121788


in reply to Re^3: What esteemed monks think about changes necessary/desirable in Perl 7 outside of OO staff
in thread What esteemed monks think about changes necessary/desirable in Perl 7 outside of OO staff

Yes I did not know about wantarray. Sorry about that. That can be used to distinguish between function and sub calls. Thank you.
wantarray

Returns true if the context of the currently executing subroutine or eval is looking for a list value. Returns false if the context is looking for a scalar. Returns the undefined value if the context is looking for no value (void context).

FYI instead of $line =~ s/\s+$//; # rtrim() in Perl you can use AWK hack in split function:

($line)=split(' ',$line,1)
It is marginally faster. Use of regex for trimming white space reminds me an anecdote about general who sent a tank division to capture an unarmed village with natives. IMHO, this is too heavy instrument unless regex engine is really sophisticated and optimize such case into tr/ //d style implementation. Just look at the overhead on a million lines file:

[0] # time perl -e 'for (1..1000000) { $line=" aaa bbb ccc ddd eee +fff "; $line =~ s/\s+$//; $line =~ s/\s+$//;}' real 0m3.526s user 0m3.510s sys 0m0.000s

so we are talking about real money here (without regex time is 0.14).

May be extending tr to stop after the first symbol which is not in set1 would also be beneficial and faster.

In my use of Perl I would prefer an option in the open statement that would do the job for all lines read, as this is the most common use case. Something like open(file,'<t(rln)','test')