in reply to Can't I chop the lvalue of join?

Can I ask why you're using join(',', keys %$c) in your code, but you're not using join(',', map '?', keys %$c)?

Anyway, since chop() modifies its argument, it must be a variable. But do what I said above.

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
Re: Re: Can't I chop the lvalue of join?
by DapperDan (Pilgrim) on Sep 28, 2002 at 14:33 UTC
    I hadn't used join with an in-lined map before. You're right, it's so damned obvious given the way i used join with keys, but I just couldn't see that until it was pointed out to me.

    Thanks a lot japhy.

    PS: not that it really matters any more, but is there a reason *why* chop only works on a variable rather than any scalar lvalue?

      It does work on lvalues. But the return value of join() is not an lvalue. You can't assign to it. join('x', qw( a b c )) = "foo"; is a syntax error, whereas substr($x, 2, 4) = "ouch"; is not, so you can say chop(substr($x, 2, 4)).

      _____________________________________________________
      Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
      s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

        (Which, of course, is in this case a silly way to say the same as:)
        substr($x, 4, 1) = ''; # or substr($x, 4, 1, '');

        Makeshifts last the longest.