Hello Sorry I am new to perl, I was reading the charter about package.
I tried to write the code below: use strict; use Net::Ping; package A; sub mytest { my $host = shift; my $p = Net::Ping->new(); unless ($p->ping($host)) { $p->close(); die "can't ping $host"; } } 1; package B; sub mytest { my $host = shift; my $p = Net::Ping->new(); unless ($p->ping($host)) { $p->close(); return 0; } } 1; package main; A::mytest('www.google.com'); print B::mytest('www.google.com'); When I run it, always get: $ perl test.pl can't ping www.google.com at test.pl line 12. Shouldn't I return die() in package's method? How do I let the caller know what happens when the method fails to run? Thanks in advance. Yours Maggie