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')


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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.