in reply to Re: Chomp(<handle>)
in thread Chomp(<handle>)

The first error is because it can't choose between chomp SCALAR or chomp ARRAY usage.

No, the first error is because he's "passing" something to chomp() that can't be modified in place.

Try

chomp(" foo ");
It's clearly a SCALAR, yet it won't work.

Replies are listed 'Best First'.
Re^3: Chomp(<handle>)
by halley (Prior) on Jul 14, 2003 at 19:09 UTC
    $ perl -e 'chomp(" foo ");' Can't modify constant item in chomp at - line 1, near "" foo ")"
    $ perl -e 'chomp(<STDIN>);' Can't modify <HANDLE> in chomp at - line 1, near "<STDIN>)"
    Different error messages. In the first case, it complains about modifying a non-lvalue (a constant item). In the second case, it complains about modifying the results of reading from a file handle.

    I'll grant you that chomp SCALAR can't chomp a non-lvalue, if you'll grant that the ambiguous context of the syntax chomp <FOO> is another valid reason that the compiler gives a separate distinct message.

    --
    [ e d @ h a l l e y . c c ]

      In the second case, it complains about modifying the results of reading from a file handle.

      Care to place a small wager on that? I could be wrong. You might make a buck.

      I disagree. They are the same error message:

      Can't modify %s in %s

      (see perldoc perldiag, search for modify)

      chomp can only modify an lvalue, and neither a 'constant item' nor '<filehandle>' are lvalues, just as dws said.

      --
      3dan