http://www.perlmonks.org?node_id=103398


in reply to Re: (Golf) Let's go bowling
in thread (Golf) Let's go bowling

I'm still choking on the map {} @_; ... I've got use 5.6.0; as my first line, so I know I'm not running 5.00x. But, if I change the map to:
@b=@_; map {s#[X/]#10#} @b; @_=@b;
Then, it works just fine. The error I'm getting is "Cannot modify a read-only variable." What's the about?

------
/me wants to be the brightest bulb in the chandelier!

Vote paco for President!

Replies are listed 'Best First'.
Re: Re: Re: (Golf) Let's go bowling
by abstracts (Hermit) on Aug 09, 2001 at 18:08 UTC
    Hello

    I'm using 5.6.2 and got that same error. I fixed it by doing:

    @b=@_;@_=@b; # then preceed as usual
    I bet the problem is that you are calling the function as
    score(qw/X 6 5 7 9 ...../);
    instead of:
    @arr = qw/X 4 5 6 .../; score(@arr);
    Map is modifying the content of the list (using s#...#10#). Passing a list (constant) to the sub makes @_ elements aliases to the values passed. This is just like saying
    "helo" =~ s/l/ll/;
    which does not make sense.

    Did I make myself clear? Does it make sense?

    Aziz,,,

      Yes, you are correct! Wow, I didn't realize that could be an issue, though it makes perfect sense, once it's put into those terms.

      Thanks! :)

      ------
      /me is slowly becoming the brightest bulb in the chandelier! (though others are kW bulbs...)

      Vote paco for President!