in reply to Not a CODE reference … my 1st script

This:

push( @device_thread, threads->new( \&thread_job( $key, $device_ip{$key}, $index ) )->join ) ;
  1. Calls the function thread_job() passing some parameters;
  2. Then starts a thread to run a reference to the return value from the sub.

    Which obviously fails because the return value isn't a code reference, hence the error message.

  3. which it joins immediately,

    Meaning that the calling thread would block waiting for the child thread to complete. Which would be exactly equivalent, but much more expensive that calling the function inline.

  4. And then push the return value from the thread onto the array.

    Is that what you intended, or were you meaning to push the thread handles onto the array call @device_thread?

Your code is so confused, that it is hard to know quite what your intention was, but I suspect that you might want:

push( @device_thread, threads->new( \&thread_job, $key, $device_ip{$key}, $index ) ); ... $__>join for @threads;

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Not a CODE reference … my 1st script
by OneDreamCloser (Novice) on Apr 04, 2011 at 03:58 UTC
    many thanks to both of you. both solutions worked :)