CHOMP not working on some servers 
Author Message
 CHOMP not working on some servers

I have been coding perl for 9 months and obviously have had no
problems with CHOMP.  Just recently I moved some code from one
server to another - a daily thing for me - and the code would
not work at all.  After a bit of debugging I found that chomp
only took the last character off of the string and left some
{*filter*}(I thought that chomp took off all of the {*filter*}off the end
of a string?).

Any thoughts?

Chris



Sat, 13 Jan 2001 03:00:00 GMT  
 CHOMP not working on some servers

Quote:

> I have been coding perl for 9 months and obviously have had no
> problems with CHOMP.  Just recently I moved some code from one
> server to another - a daily thing for me - and the code would
> not work at all.  After a bit of debugging I found that chomp
> only took the last character off of the string and left some
> {*filter*}(I thought that chomp took off all of the {*filter*}off the end
> of a string?).

> Any thoughts?

Its difficult to give any useful advice without knowing what the {*filter*}was.
However, chomp() is normally preferred because it *only* gets rid of line
terminators at the end of a variable.  The older chop() - still found in
many scripts - will take off whatever the last character at the end is.  
True, it is often a line terminator, but chop() doesn't care.  If you have
extraneous "crap", that isn't a line terminator, perhaps you should use
the older call on this occasion.

Regards
Neil



Sat, 13 Jan 2001 03:00:00 GMT  
 CHOMP not working on some servers
Programming Perl 2nd Edition: chomp removes any line ending
corresponding to the current value of $/, and not just any last
character. If $/ is empty chomp removes all trailing newlines from the
selected string.

Quote:

> I have been coding perl for 9 months and obviously have had no
> problems with CHOMP.  Just recently I moved some code from one
> server to another - a daily thing for me - and the code would
> not work at all.  After a bit of debugging I found that chomp
> only took the last character off of the string and left some
> {*filter*}(I thought that chomp took off all of the {*filter*}off the end
> of a string?).

> Any thoughts?

> Chris

--
                        ****************************************
                        *    Tony Labbiento                    *
                        *    Infinity Online, Inc.             *
                        ****************************************


Sat, 13 Jan 2001 03:00:00 GMT  
 CHOMP not working on some servers

Quote:

> I found that chomp
>only took the last character off of the string and left some
>{*filter*}(I thought that chomp took off all of the {*filter*}off the end
>of a string?).

chomp() is supposed to remove the value of $/ from the end of the
string, if present. This is much like what it does:

        s[$/$][];

The "crap" you're talking about, is probably "\n", "\r"   or something
similar. It could be submitted by the browser.

The safest bet is to use this line instead of chomp:

        tr/\r\n//d;

HTH,
Bart.



Sat, 13 Jan 2001 03:00:00 GMT  
 CHOMP not working on some servers

Quote:

> After a bit of debugging I found that chomp
> only took the last character off of the string and left some
> {*filter*}(I thought that chomp took off all of the {*filter*}off the end
> of a string?).

If you want chomp to remove {*filter*}from the end of the string, you need to
do this first:

$/ = 'crap';

Note if you have a load of {*filter*}to remove from the end of the string, as
in 'poop excrement crapcrapcrap', this method will only remove the last
bit of crap, rather than all the crap.  You would need to do something
like s/(?:crap)+$// instead.

--


    /                                   http://www.*-*-*.com/ ~rjk/
        "It's funny 'cause it's true ... and vice versa."



Sat, 13 Jan 2001 03:00:00 GMT  
 CHOMP not working on some servers

Quote:

> If you want chomp to remove {*filter*}from the end of the string, you need to
> do this first:

> $/ = 'crap';

> Note if you have a load of {*filter*}to remove from the end of the string, as
> in 'poop excrement crapcrapcrap', this method will only remove the last
> bit of crap, rather than all the crap.  You would need to do something
> like s/(?:crap)+$// instead.

:D

You're killing me!  This is better than stand-up.

ROTFLOL!
-Sneex-
__________________________________________________________________
Bill Jones | FCCJ Webmaster | Life is a 'Do it yourself' thing...
              http://www.*-*-*.com/



Sun, 14 Jan 2001 03:00:00 GMT  
 CHOMP not working on some servers
[cc'd to cd]

It sounds to me like that server has Perl 4 installed (no chomp
function). I have heard of such Precambrian servers still around, but
they should have been extinct long ago.

Cameron

Quote:

> I have been coding perl for 9 months and obviously have had no
> problems with CHOMP.  Just recently I moved some code from one
> server to another - a daily thing for me - and the code would
> not work at all.  After a bit of debugging I found that chomp
> only took the last character off of the string and left some
> {*filter*}(I thought that chomp took off all of the {*filter*}off the end
> of a string?).

> Any thoughts?

> Chris



Sun, 14 Jan 2001 03:00:00 GMT  
 CHOMP not working on some servers


Quote:
> I have been coding perl for 9 months and obviously have had no
> problems with CHOMP.  Just recently I moved some code from one

it's chomp.

Quote:
> server to another - a daily thing for me - and the code would
> not work at all.  After a bit of debugging I found that chomp

'not work'? Can you get any more vague?

Quote:
> only took the last character off of the string and left some
> {*filter*}(I thought that chomp took off all of the {*filter*}off the end
> of a string?).

# perldoc -f chomp
This is a slightly safer version of L</chop>.  It removes any
line ending that corresponds to the current value of C<$/> (also known as
$INPUT_RECORD_SEPARATOR in the C<English> module).

What is ambiguous about that? If you set $/ to 'blafoobarnana', chomp
will remove that, and exactly that from the end of a scalar. Normally
it is set to newline, and chomp will remove exactly that from your
scalar. if you want it to remove 'crap', whatever that is, you'll have
to tell it. But I would investigate where that 'crap' is coming from.

Martien
--
Martien Verbruggen                      |
Webmaster www.tradingpost.com.au        | "In a world without fences,
Commercial Dynamics Pty. Ltd.           |  who needs Gates?"
NSW, Australia                          |



Mon, 15 Jan 2001 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Send mail script not working in 2nd server but working in 1st server

2. Send mail script not working in 2nd server but working in 1st server

3. chomp not working

4. CHOMP not working

5. Open file works under DOS, not under server

6. Open file works under DOS, not under server

7. server example does not work on IRIX 5.3

8. Unlink Not Working On Windows Server

9. Socket client/server example not working on Windows 2K

10. Need help with simple code not working on my ISP's server

11. perl book socket server example does not work

 

 
Powered by phpBB® Forum Software