in reply to Assigning the result of a chomp to the chomped var itself.

while my old 5.8.8 returns (1,1,1) newer strawberry one returns all 0,1,1
general>check_perl_distro c:/scripts/ideone-choroba.pl ----------------------------------------······· | (0,1,1). --------------------------------------------------------------------- +--······· [OK] C:\ulisse\strawberry\perl\bin\perl.exe ----------------------------------------······· | (0,1,1). --------------------------------------------------------------------- +--······· [OK] C:\ulisse\straw5.20-32b\perl\bin\perl.exe ----------------------------------------······· | (0,1,1). --------------------------------------------------------------------- +--······· [OK] C:\ulisse\straw64\perl\bin\perl.exe
UPDATE: docs say also It returns the total number of characters removed from all its arguments. but i see another thing:
perl -e "$a=qq(AA\n\n);$res = chomp $a; print qq(>$a< removed $res\n)" >AA < removed 1 ## maybe it means another thing: perl -e "$a=qq(AA\n\n);$b=qq(BB\n\n);$res = chomp ($a,$b); print qq(>$ +a< removed $res\n>$b< removed $res )" >AA < removed 2 >BB < removed 2
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^2: Assigning the result of a chomp to the chomped var itself.
by parv (Parson) on Nov 26, 2014 at 11:24 UTC
    chomp ... It returns the total number of characters removed from all its arguments. It's often used to remove the newline from the end of an input record when you're worried that the final record may be missing its newline. When in paragraph mode ("$/ = """), it removes all trailing newlines from the string. When in slurp mode ("$/ = undef") or fixed-length record mode ($/ is a reference to an integer or the like; see perlvar) chomp() won't remove anything.

    So ...

    perl -e '$/ = "" ; $a = qq(AA\n\n); $b = qq(BB\n\n); $res = chomp ($a, +$b); print qq(>$a< removed $res\n>$b< removed $res\n)' >AA< removed 4 >BB< removed 4
Re^2: Assigning the result of a chomp to the chomped var itself.
by Anonymous Monk on Nov 26, 2014 at 11:14 UTC

    UPDATE: docs say also It returns the total number of characters removed from all its arguments. but i see another thing:

    What is that?

    $ perl -MData::Dump -e " $g=$f=qq{a\n}; dd( chomp( $f, $g ) ) ; dd( $ +f, $g )" 2 ("a", "a")
      removes any trailing string that corresponds to the current value of $/
      Maybe this is problem due to my poor english but with 'any' i supposed to be 'all accurences' not the last one.
      $ perl -MData::Dumper -e ' $g=$f=qq{a\n}; print Dumper( chomp( $f, $g + ) ) ; print Dumper( $f, $g )' $VAR1 = 2; $VAR1 = 'a'; $VAR2 = 'a'; $perl -MData::Dumper -e ' $g=$f=qq{a\n\n}; print Dumper( chomp( $f, $ +g ) ) ; print Dumper( $f, $g )' $VAR1 = 2; $VAR1 = 'a '; $VAR2 = 'a ';
      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

        removes any trailing string that corresponds to the current value of $/ Maybe this is problem due to my poor english but with 'any' i supposed to be 'all accurences' not the last one.

        ok, I see where you're coming from :) this is one of the deals with documentation as free form prose ... its free form prose :)

        The current value of $/ is "\n" it is not "\n\n", does that make sense to you? with a valid $/ chomp only chomps once

        Consider this as chomp documentation :) 2,4,4,0,0 :)

        use Data::Dump qw/ dd /; $f = $g = "a\n\n"; dd( chomp( $f, $g ) ); dd( $f, $g ); $/ = "\n\n"; $f = $g = "a\n\n"; dd( chomp( $f, $g ) ); dd( $f, $g ); $/ = ""; $f = $g = "a\n\n"; dd( chomp( $f, $g ) ); dd( $f, $g ); $/ = undef; $f = $g = "a\n\n"; dd( chomp( $f, $g ) ); dd( $f, $g ); $/ = \333; $f = $g = "a\n\n"; dd( chomp( $f, $g ) ); dd( $f, $g ); __END__ 2 ("a\n", "a\n") 4 ("a", "a") 4 ("a", "a") 0 ("a\n\n", "a\n\n") 0 ("a\n\n", "a\n\n")