Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are many many problems with this code (from major ones like not being compilable, so I don't even know how you get the runtime errors), to minor stylistic issues.</p> <p>However, since you talk about variable passing, I will zero in on that piece.</p> <hr> <p>Here's where you call your functions:</p> <pre><code>my @array = &amp;function1(); my $arrayvalue = &amp;function2(); &amp;function1($search); &amp;function2(@array); </code></pre> <p>So, you FIRST call <code>function1</code> with no arguments (which will presumably run incorrectly, as you didn't pass the search string - and resulted in <code>uninitialized value $search in concatenation</code> error you mentioned in the comment), and assign an empty array results into <code>@array</code>.</p> <p>THEN, you call <code>function1</code> <strong>again</strong>, this time correctly (passing $search parameter), but ignore the return value (so <code>@array</code> will remain empty from first call). </p> <p>Same problems for second function.</p> <p>This should have been:</p> <pre><code>my @array = function1($search); my $arrayvalue = function2(@array); </code></pre> <hr> <p>Second big problem is that you are passing along the data as an array to a second function, but inside the function assigning it as a scalar (presumably as if you passed an array reference). </p> <p>Your code:</p> <pre><code># Called via "function2(@array)"; my @array = $_[0]; </code></pre> <p>If you intend to pass an array, you need to process the parameter array as a whole array:</p> <pre><code># Called via "function2(@array)"; my @array = @_; </code></pre> <p>Whereas if you intend to pass-by-reference, as a single array reference parameter (which is more advanced of a technique but stongly recommended over passing an array for a variety of reasons):</p> <pre><code># Called via "function2(\@array)"; # Notice the "\" in front of "@" - this is a "take a reference" operator my $arrayRef = $_[0]; # We only take 1 parameter, the array reference, now my @array = @$arrayRef; # Dereference array ref into an array. # You can also use arrayref directly instead once you learn about data structures </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload