in reply to [substr] anomaly or mine?

The first is a special behavior of 4-argument substr which is rather handy. The second is just the way assignments work (what value they themselves return). Just like:

my $x= "foo"; print $x= "bar";
prints "bar".

Update: Actually, I expected substr(...)= expr to return expr. Rereading, I see that it isn't. I'd call that a bug.

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
Re: (tye)Re: [substr] anomaly or mine?
by Chmrr (Vicar) on Aug 19, 2002 at 23:57 UTC

    Using that logic, then, you would expect:

    print substr($s,0,4)='',$s;

    ..to print:

    |k brown fox jumps over the lazy dog

    ..as it would return what it was just set to.

    perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'

      Thankyou.


      What's this about a "crooked mitre"? I'm good at woodwork!
Re: (tye)Re: [substr] anomaly or mine?
by BrowserUk (Patriarch) on Aug 20, 2002 at 00:25 UTC

    If it's a bug, will it be picked up automatically as its been mentioned here or should I report it? If so, where?

    Or will you or one of the backroom guys here?


    What's this about a "crooked mitre"? I'm good at woodwork!
Re^2: [substr] anomaly or mine?
by tadman (Prior) on Aug 20, 2002 at 08:21 UTC
    Re-re-reading it, you'd expect substr(...)=expr to return what the substr was set to. In this case, it returns the value of the substr after the operation was complete. Your 4-argument, err, argument does seem to be the most persuasive.

    Bug? Feature? Undefined behavior? I think a case could be made for the validity of either mode of operation.
Re: (tye)Re: [substr] anomaly or mine?
by bart (Canon) on Aug 20, 2002 at 10:28 UTC
    I agree with your update.