[Israel.pm] Why am I not printing getting results? What am I missing

Shmuel Fomberg semuelf at 012.net.il
Tue Sep 18 09:42:07 PDT 2007


Hello there.

Maybe it is a context problems? You create the threads in list context, so
the run in that context, and the ping method returns array, while you
probably wanted scalar. 

Simply put, try replacing this line:
map {threads->create(\&single_ping, $host)} (1..$num_pings);
with this:
map {threads->create ({'context' => 'scalar'}, \&single_ping, $host)}
(1..$num_pings);

Shmuel.

>-----Original Message-----
>From: Levenglick Dov-RM07994 [mailto:dov at freescale.com]
>Sent: Tuesday, September 18, 2007 2:21 PM
>To: Perl in Israel
>Subject: Re: [Israel.pm] Why am I not printing getting results? What am
>Imissing
>
>This worked. Why can't I eliminate the $tmp in the subroutine?
>
>use strict;
>use warnings;
>
>use Net::Ping;
>use threads;
>
>my $num_pings = 10;
>my $host = "223.31.95.254";
>my $errors = 0;
>
>map {threads->create(\&single_ping, $host)} (1..$num_pings);
>map {$errors++ unless $_->join()} (threads->list());
>exit $errors;
>
>sub single_ping
>{
>	my $p = Net::Ping->new();
>	my $tmp = $p->ping(shift);
>	return $tmp;
>}
>
>
>
>Best Regards,
>Dov Levenglick
>SmartDSP OS Development Team,
>DevTech, Technology and System Organization
>Freescale Semiconductor Israel
>Tel. +972-9-952-2804
>The information contained in this email is classified as:
>[ ] Freescale General Business Information
>[ ] Freescale Internal Use Only
>[ ] Freescale Confidential Proprietary
>[x] Personal Memorandum
>
>-----Original Message-----
>From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On
>Behalf Of Chanan Berler
>Sent: Tuesday, September 18, 2007 14:08
>To: Perl in Israel
>Subject: Re: [Israel.pm] Why am I not printing getting results? What am
>Imissing
>
>try this first:
>
>use strict;
>use warnings;
>
>use Net::Ping;
>
>my $p = Net::Ping->new();
>       return $p->ping(223.31.95.254);
>
>check if it works....then apply the thread stuff.
>Also i think the shift is misplaced...i think you should use the $_
>in the subroutine, since i can't tell if it not changed when using
>my $p = Net::Ping->new();
>
>also did you try apply a simple ping from command line - see if it works
>
>Chanan
>
>
>
>On 9/18/07, Levenglick Dov-RM07994 <dov at freescale.com> wrote:
>> use strict;
>> use warnings;
>>
>> use Net::Ping;
>> use threads;
>>
>> my $num_pings = 10;
>> my $host = "223.31.95.254";
>>
>> threads->create(\&single_ping, $host) for (1..$num_pings);
>> map {print $_, $_->join(), "\n"} threads->list();
>>
>> sub single_ping
>> {
>>        my $p = Net::Ping->new();
>>        return $p->ping(shift);
>> }
>>
>>
>> Best Regards,
>> Dov Levenglick
>> SmartDSP OS Development Team,
>> DevTech, Technology and System Organization
>> Freescale Semiconductor Israel
>> Tel. +972-9-952-2804
>> The information contained in this email is classified as:
>> [ ] Freescale General Business Information
>> [ ] Freescale Internal Use Only
>> [ ] Freescale Confidential Proprietary
>> [x] Personal Memorandum
>> _______________________________________________
>> Perl mailing list
>> Perl at perl.org.il
>> http://perl.org.il/mailman/listinfo/perl
>>
>
>
>--
>===================
>----     Chanan Berler    ----
>===================
>_______________________________________________
>Perl mailing list
>Perl at perl.org.il
>http://perl.org.il/mailman/listinfo/perl
>_______________________________________________
>Perl mailing list
>Perl at perl.org.il
>http://perl.org.il/mailman/listinfo/perl
>
>
>--
>No virus found in this incoming message.
>Checked by AVG Free Edition.
>Version: 7.5.487 / Virus Database: 269.13.21/1012 - Release Date:
>16/09/2007 18:32





More information about the Perl mailing list