beavis69 has asked for the wisdom of the Perl Monks concerning the following question:

I've a strange problem, i want to use the Schedule::Cron but it breaks the rest of my code ! in this example :
#!/usr/bin/perl -w use strict; #use Schedule::Cron; use Net::Ifconfig::Wrapper; my $mask=my $ip="0.0.0.0"; # get info for all interfaces my $Info = Net::Ifconfig::Wrapper::Ifconfig('list', '', '', ''); # get info for my interfaces eval { ($ip, $mask) = %{$Info->{"eth0"}{'inet'}}; }; warn $@ if $@; print "net::ifconfig eth0 addr is $ip\n";
If i remove the comment for use Schedule::Cron it doesnt work anymore !
It's the same if i use a filehandle to retrieve ifconfig output. Seems that use Schedule::Cron, does not let me access ifconfig anymore ?
if i run it without comment:
Can't use an undefined value as a HASH reference at ./test.pl line 15. net::ifconfig eth0 addr is 0.0.0.0
and with the comment runs like a charm
net::ifconfig eth0 addr is 192.168.0.1
anyone a clue ? Thanks
beav

Replies are listed 'Best First'.
Re: Strange problem with use
by davido (Cardinal) on Oct 17, 2003 at 17:48 UTC
    ...it doesnt work anymore ?!

    It would be helpful if you elaborated on "doesn't work".

    Update: Thanks for updating your parent node by adding the error message. Line 15 of what we see is a print statement, which as others have pointed out isn't the source of the problem.

    Update2: The POD for Net::Ifconfig::Wrapper suggests that the module uses the system's resident /sbin/ifconfig function. If Schedule::Cron is doing something with $SIG{CHLD} that tromps on the system's ifconfig function's ability to do its job, you've got a module-incompatibility problem.


    Dave


    "If I had my life to do over again, I'd be a plumber." -- Albert Einstein
      The misspelling in the print statement doesn't make any difference. It's not parsed by perl, just a string output. Doesn't make any difference in program execution at all.

      If it helps, I get the exact same error. Once I use Schedule::Cron, $Info comes back as undefined. Must be something that conflicts between those two modules.

      The eval doesn't help, btw. I assume you put it in to help debug, but the problem is prior to these lines.

      I'll keep trying things out, and let you know if I have any luck.

      Update: It seems that use'ing Schedule::Cron sets $SIG{CHLD}. This seems to be interfering with the Ifconfig module. I'd say it's a bug in the ifconfig module, the Schedule::Cron module, or both -- but here's a workaround.

      Save the old value of $SIG{CHLD}, then call Ifconfig, then restore $SIG{CHLD}. Or, get rid of the use line, and 'require' it below this call.

      my $oldsigchld = $SIG{CHLD}; $SIG{CHLD} = 'DEFAULT'; # get info for all interfaces + my $Info = Net::Ifconfig::Wrapper::Ifconfig('list', '', '', ''); $SIG{CHLD} = $oldsigchld if(defined $oldsigchld);
      or
      # get info for all interfaces + my $Info = Net::Ifconfig::Wrapper::Ifconfig('list', '', '', ''); require Schedule::Cron;
      If I do either of those things, it works fine. ;-)

      ~J

        Thanks, Think you've got it !
        I'd the same problem without the Net::Ifconfig::Wrapper if i use :
        sub getifip { my $ip = '0.0.0.0'; open(README,"/sbin/ifconfig $_[0] 2>&1 |"); while (<README>) { if ( /ad\w*:(\d+\.\d+\.\d+\.\d+)\s.*/ ) {$ip=$1} } close(README); #&slog("$_[0] has ip $ip","getifip"); return $ip; }
        i had the same problem in a program that forks. So i think bug is definitely in the Schedule::Cron module
        I'll try your workaround.
        Thanks a lot.
        Regards
        Beav
      Print statement is line 16, and it is not misspelled, it is juste a string...
      The problem appear on line 15 within the eval {}...
      Update : thank you for all yours answers.
      think you're right about SIG{CHILD}.
      regards
      beav
Re: Strange problem with use
by diotalevi (Canon) on Oct 17, 2003 at 17:47 UTC

    You forgot to describe the error.

      You're right, so i edited my original post and added the error.
      Thanks for replying
      Beav