Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Re: [substr] anomaly or mine?

by dpuu (Chaplain)
on Aug 20, 2002 at 01:37 UTC ( [id://191362]=note: print w/replies, xml ) Need Help??


in reply to Re: [substr] anomaly or mine?
in thread [substr] anomaly or mine?

Your first EXPECT does not fully distinguish the actual behaviour that feels anomalous:
my $s = 'ABCDE'; print substr($s,0,2)=''; # EXPECT 'CD' or 'CDE'?
The actual is 'CD'; intuition would expect 'CDE'

perhaps a better test case is

my $s = 'ABCDE'; print substr($s,0,2)='1'; # EXPECT '1C' or '1CDE'?
again, actual is "1C". --Dave

Replies are listed 'Best First'.
Re: Re: Re: [substr] anomaly or mine?
by Chmrr (Vicar) on Aug 20, 2002 at 01:47 UTC

    My intuition would expect:

    my $s = 'ABCDE'; print substr($s,0,2)='',$/; # EXPECT '', GET 'cd'? print substr($s,0,2)='foo',$/; # EXPECT 'foo', GET 'fo'?

    ..in parallel with all other assignments:

    my $s = 'ABCDE'; print $s='',$/; # EXPECT '' print $s='foo',$/; # EXPECT 'foo'

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://191362]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (None)
    As of 2024-04-19 00:00 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found