in reply to Super newbie array question

Just push the anonymous arrays onto your array without quoting them. Otherwise you have an array of strings.

my @ranges = (); push @ranges, [172,178]; push @ranges, [183,189]; push @ranges, [201,208];
Note that if you used strict (you should always use strict), Perl would have told you what the problem was: Can't use string ("[172,178]") as an ARRAY ref while "strict refs" in use.

Hope this helps!


update: clarified terminology

The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: Super newbie array question
by Anonymous Monk on May 22, 2023 at 22:08 UTC
    Aha! I see, that did the trick! And, if I may ask one more thing: if I have $var1 = 172 and $var2=178 instead of the raw numbers themselves, how can I do the push then?
      Interesting, it seemed to work:
      push @ranges, [$var1,$var2];