long time reader first time caller....
Anyway, i'm currently upgrading some legacy scripts to perl 5.10. There's a lib we've got that for some reason decided it'd be easier if arrays started at 1, so they've gone and set $[ = 1
They've done this in a module, in an init function. The code has previously run in 5.8.8, and i'm updating everything to use perl 5.10.
my test.pm example:
#!/usr/bin/env perl package test; sub Init { $[ = 1; } sub test { print "(\$[= $[) array has " . scalar @_ . " elements, last index += $#_\n"; } 1;
t1.pl:
#!/usr/bin/env perl use test; test::test(1,2,3,4); # test::Init(); test::test(1,2,3,4);
As it turned out, even without calling test::Init, the mere fact that that is in that function has somehow globally turned on that option...
in perl 5.8.8, i execute the t1.pl and get:
# perl 5.8.8 output ./t1.pl ($[= 1) array has 4 elements, last index = 4 ($[= 1) array has 4 elements, last index = 4
and in perl 5.10
# perl 5.10 $ ./t1.pl ($[= 0) array has 4 elements, last index = 3 ($[= 0) array has 4 elements, last index = 3
regardless of whether i call Init or not. I'm not sure why this happens, and it looks like it was a bug in perl 5.8.8 that wasn't listed as resolved in perl 5.10 but is...
It drove me crazy :| hopefully this information at least helps someone if they see the same thing - i've not seen it listed anywhere as a change or as something someone has tripped over. Can anyone else confirm this or is it just me? :|

In reply to fun with $[ by rolfy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.