Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: How's your Perl? (II)

by Errto (Vicar)
on Jul 22, 2004 at 03:59 UTC ( [id://376456]=note: print w/replies, xml ) Need Help??


in reply to How's your Perl? (II)

Update:modified slightly.

6:
my @foo = (0); $[ = -1;

Replies are listed 'Best First'.
Re^2: How's your Perl? (II)
by eric256 (Parson) on Jul 22, 2004 at 04:07 UTC

    That doesn't seem to work here.


    ___________
    Eric Hodges
      I modified it slightly. I'm running: This is perl, v5.8.3 built for i386-linux-thread-multi
Re^2: How's your Perl? (II)
by mauke (Novice) on Jul 22, 2004 at 06:26 UTC

    Confirmed on 5.6.1, 5.8.0, 5.8.1, 5.8.3. Doesn't work on 5.8.4 and 5.8.5.
    And I think it should not work, because $foo[$[] is the first element and $foo[$[+1] is the second; I don't see how $[ and $[+1 can refer to the same element.

    All exercises have been tested with perl 5.8.*, and solutions do not necessarily have to work with any other version.

    I take this to imply that solutions should work with all 5.8.* perls.

      Hm, strange.. I actually wrote $foo[$[] in the assuption this would prevent any $[-fiddling and force the real solution, but it seems $[ really doesn't work properly in perl: perl -le '$[ = -1; @x = (42); $y = 0; print $x[$y]' prints 42 for me on 5.8.3 and 5.8.4...

      I'll add a note to the exercise that the intention is to solve it without diddling $[

      Fair enough. My only excuse is that 5.8.3 is the only version I have, and that the other way seemed too similar to one of the solutions from last time around so I wanted to try something different :) I was trying to use the fact that $foo[-1] is the last element in the array, so if the array only has one element ...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-26 04:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found