in reply to Re: "chomp" not working
in thread "chomp" not working

$var is taking input from an HTML text area. It goes something like this:

a,b,c,d e,f,g,h i,j,k,l

There is a carriage return at the end of each line. @arr1 before the chomp should like like above when printed out. However, I would expect that after the chomp that @arr1 would print like this:

a,b,c,d e,f,g,h i,j,k,l

But it doesn't, it prints like the first example.

Replies are listed 'Best First'.
Re^3: "chomp" not working
by JavaFan (Canon) on May 02, 2012 at 23:45 UTC
    There is a carriage return at the end of each line. @arr1 before the chomp should like like above when printed out.
    You are splitting on newlines. Why do you expect them to still be there?
Re^3: "chomp" not working
by AnomalousMonk (Archbishop) on May 02, 2012 at 23:57 UTC
    a,b,c,d
    e,f,g,h
    i,j,k,l

    @arr1 before the chomp should like like above when printed out.

    Why would you expect that?

    >perl -wMstrict -le "my $s = qq{a,b,c,d\ne,f,g,h\ni,j,k,l}; printf qq{$s}; printf qq{\n}; ;; my @ra = split /\n/, $s; printf qq{@ra}; printf qq{\n}; ;; chomp @ra; printf qq{@ra}; printf qq{\n}; " a,b,c,d e,f,g,h i,j,k,l a,b,c,d e,f,g,h i,j,k,l a,b,c,d e,f,g,h i,j,k,l