arunhorne has asked for the wisdom of the Perl Monks concerning the following question:

Hi, i say chomp($data); where data contains a string, in return I get 00 or 01 10 or some other binary rather than a string with no \n's etc. Can anyone shed some light.

Replies are listed 'Best First'.
Re: Chomp Anomaly?
by ariels (Curate) on May 09, 2002 at 12:08 UTC

    chomp modifies its arguments, but returns the number of characters removed from its arguments. What you mean by "some other binary" is unclear; in any case, as per documentation,

    print chomp($x = "A string\n"),"\n"; print "|$x|\n"
    prints
    1
    |A string|
    

Re: Chomp Anomaly?
by broquaint (Abbot) on May 09, 2002 at 12:09 UTC
    This is because chomp() modifies the arguments it is passed, so $/ is removed inplace (which would be \n in your case). The return you're seeing is the total number of characters removed from all it's arguments (perhaps you're calling it in an iterative context?).
    HTH

    _________
    broquaint