in reply to Working in parallel

Something like this?

#! perl -slw use strict; use threads; use threads::shared; use Net::Telnet; my %data :shared; sub thread { my( $machine, $user, $pass, $cmd ) = @_; $t = new Net::Telnet ( Timeout => 10, Prompt => '>' ); $t->open( $machine ); $t->login( $user, $pass ); my @lines :shared = $t->cmd( $cmd ); $t->close; lock %data; $data{ $machine } = \@lines; return; } # AoA each sub array containing machineId, username, password and comm +and to run my @credentials = ...; my @threads = map threads->create( \&thread, @$_ ), @credentials; $_->join for @threads; ## Do something useful with the data gathered in %data.

Replies are listed 'Best First'.
Re^2: Working in parallel
by locked_user sundialsvc4 (Abbot) on Aug 20, 2010 at 19:34 UTC

    “Show off...”   ;-)

    Naww, seriously... that's what I love about Perl.   You can describe this big, hairy-looking task, and then “just whip it out” in a few dozen lines.

    Now, I’ll happily spend the next hour or so poring over what you just wrote.

      that's what I love about Perl. You can describe this big, hairy-looking task, and then “just whip it out” in a few dozen lines.

      Ditto. That is as good a description of what is good about Perl as I seen in a long time.

      It's just a shame that so many people want to turn it into Java; in the interests of "modernity".

        Well, we shall see what actually happens.   On the one hand, “that’s how the art always advances.”   On the other, despite the best of intentions, the process of reaching that critical mass ... well, it’s very hit-and-miss.   Seem to be a lot of good programmers working on it, though.   We’ll see.

Re^2: Working in parallel
by Anonymous Monk on Aug 20, 2010 at 11:40 UTC
    Tnx, it does what I want! ps. I guess $_->join for @threads; waits for all threads to finish?
      I guess $_->join for @threads; waits for all threads to finish?

      Correct. Though I have to say that subs::parallel might be even easier for your purpose.