>>>>> "MM" == Michael Mathews <[EMAIL PROTECTED]> writes:
>> >What about a > chomp($foo, '\r\n'); > # or > chomp(<FH>, '\r\n');
>> >syntax.
>>
>> Looks an awful lot like: s/\r\n//; to me...
MM> Yep. It should-- that's all chomp does afterall. The difference is
MM> that the proposed chomp should be smarter than a regex, since it
MM> will assume certain defaults, that is: "chomp;" should act like
MM> "chomp($_, $/)"; If, however you wanted to explicitly say
MM> something different you could.
but chomp is faster as it is not a compiled regex, it is anchored to the
end of the string. so all it has to do is a simple rindex and if it
matches the line (or paragraph) terminator there, chomp at that
point. since chomp traditionally modifies its argument (as i think it just
changes the internal length of the string) it is faster there compared
to s///.
so here is my full take:
bare chomp:
uses the global default $/. (or maybe the $/ of STDIN or the magic <>)
if a scalar string arg, it chomps and returns the new (possibly shorter)
string.
if a ref to a scalar, it chomps in place. return the ref? the chomped
char count?
2nd arg chomp:
that extra arg specifies the string to be chomped.
OO chomp:
this is a method of a filehandle object. the string to chomp is take
from the filehandle or the global default $/. if a second arg is passed
or the main arg is a ref, then the above behaviors work as well.
i think that sums it up well.
uri
--
Uri Guttman --------- [EMAIL PROTECTED] ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com