note
likbez
Yes I did not know about wantarray. Sorry about that. That can be used to distinguish between function and sub calls. Thank you.
<blockquote>
wantarray
<p>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).
</blockquote>
<p>
FYI instead of $line =~ s/\s+$//; # rtrim() in Perl you can use AWK hack in split function:
<p><code>
($line)=split(' ',$line,1)
</code>
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:
<p><code>
[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
</code>
<p>so we are talking about real money here (without regex time is 0.14).
<p>May be extending tr to stop after the first symbol which is not in <b>set1</b> would also be beneficial and faster.
<p>
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')
11121538
11121782