From perldoc -f vec it says:

vec EXPR,OFFSET,BITS Treats the string in EXPR as a bit vector made up of elements +of width BITS, and returns the value of the element specified by OFFSET as an unsigned integer.

You're doing nasty stuff with references to variable names, which would flail with use warnings so you code like this at your own peril.

First, line 16, change from

for (@{$domains[$i]}) { vec($scratch,$_,1) = 1}
to
for (@{$domains[$i]}) { vec($$scratch,$_,1) = 1}

Next, the ending for loop, should written as follows:

for ( $j = 0; $j <= 5; $j++ ) { my $scratch = "domains$j"; for ( $i = -100 ; $i <= 2000 ; $i++ ) { if (vec($$scratch,$i,1)){ print "\t $i recognised as part of the 1st domain using the ne +w method\n"; } } }
Note the second for loop, and the use of the scratch variable.

I would never personally code like this, but hopefully it is of some assistance to you.

Update: fixed a mis typed code tag.


In reply to Re: Using vec to search an array by monarch
in thread Using vec to search an array by b_hall

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.