On Tue, 8 Aug 2000 18:35:46 -0400, Michael Mathews wrote:

>I frequently use chomp in ways that have nothing to do with "reading from
>files" and I would bet this is true for everyone here too. For example:
>
>use CGI;
>$cgi = new CGI;
>$foo = $cgi->param('foo');
>
>#as part of doing stuff to the user input....
>chomp $foo;
>
>Are you suggesting that this should not be facilitated? I realize I could
>accomplish the same end by using regex but chomp has certain advantages I
>like.

What are you attempting? Is this from a HTML form with a TEXTAREA? You
want to remove a trailing CRLF?

Well, it's not enough. What if a user keeps down the return key for a
while: lots of returns. chomp() would remove only ONE. The rest would
still be there.

And I sure hope you got rid of your CR's first.

I think that most applications that use chomp() on data that isn't
coming from a filehandle (or a socket, same thing -- "everything is a
file" - Unix credo) is likely misguided: it will fix some things, but
not all.

        s/\s+$//;

There. All the trailing whitespace, blank lines, returns, newlines etc.
are removed, up to and including the ones attached to the last word.

chomp() is basically just a "postprocess data coming from a file"
command.

-- 
        Bart.

Reply via email to