Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re (tilly) 3: (Golf) Strings-to-Array

by tilly (Archbishop)
on Sep 01, 2001 at 05:13 UTC ( #109590=note: print w/replies, xml ) Need Help??

in reply to Re: Re (tilly) 1: (Golf) Strings-to-Array
in thread (Golf) Strings-to-Array

In Perl 5.6.0 if you passed in literal strings, you got an error about, "Modification of a read-only value attempted". Recopying @_ fixed that.

And the time when $s and $s.0 are different in boolean context is when $s is "0". So when you remove those two characters, you get a bug.

An example that shows the bug:

print map "$_\n", r("0a1", "b0", "0");

Replies are listed 'Best First'.
Re: Re (tilly) 3: (Golf) Strings-to-Array
by demerphq (Chancellor) on Sep 01, 2001 at 18:27 UTC
    Hi Tilly.

    Ok so on that input it doesnt work.

    I guess now I'm being a pain, but japhy's spec *did* say make a function that takes any number of equal-length strings

    However I do believe in defensive programming, so I can see why you did that.

    Very interesting, and food for thought


    $\="\n"; $,=","; print r("0000", "0000", "0000"); #outputs #000,000,000,000
      And what happens if you call r('0000')?

      Any number includes 1. :-)

Re: Re (tilly) 3: (Golf) Strings-to-Array
by demerphq (Chancellor) on Sep 01, 2001 at 05:37 UTC
    Hmm, and I reran it with literal params (I was using an @array) and I got that warnings as well. Interesting. OST. It follows from the fact @_ alises not copies, but still somehow surprising.

    And it is also very interesting to learn that '00' evals to true. Definitely *not* what I expected. I was thinking that it would fall under the evals to 0 rule, but now I see not. Thanx.

    On the other hand I tested a bunch of cases with 0's in them and I couldnt see how it affected the solution?


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2020-08-12 09:35 GMT
Find Nodes?
    Voting Booth?
    Which rocket would you take to Mars?

    Results (65 votes). Check out past polls.