Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: I got two questions, please see here:)

by atcroft (Monsignor)
on Feb 18, 2011 at 04:07 UTC ( #888841=note: print w/replies, xml ) Need Help??

in reply to I got two questions, please see here:)

For both questions, I would suggest reviewing perlipc, the perl documentation on inter-process communications. The section on signal handling mentions both Ctrl-C and Ctrl-Z (from question 1), while the section "Using open() for IPC" would be a good place to start for question 2.

Hope that helps.

Update: (2011-02-17)

For reference, I believe (after a quick search) that Ctrl-C sends SIGINT (INT), and Ctrl-Z sends SIGTSTP (TSTP).

Update: (2011-02-17)

The example from the section on signal handling can be modified as follows to illustrate handling the INT and TSTP signals:

#!/usr/bin/perl use strict; use warnings; sub catch_zap { my $signame = shift; die "Somebody sent me a SIG$signame"; } $SIG{INT} = \&catch_zap; # best strategy $SIG{TSTP} = \&catch_zap; # best strategy my $t = time; $t += 30; while ( time < $t ) { print scalar localtime, qq{\n}; sleep 1; }

A modification of the second code example in the section mentioned for question two uses open() to retrieve interface IP information using the ifconfig command:

#!/usr/bin/perl use strict; use warnings; my $interface; open( CMD, "/sbin/ifconfig |" ) || die "can't fork: $!"; while (<CMD>) { if (/^(\S+)/) { $interface = $1; } next if !/(inet\d?)\s+addr:\s?(\S+)/; print $interface, q{ }, $1, q{: }, $2, qq{\n}; } close CMD || die "bad cmd: $! $?";

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://888841]
[Eily]: what's your perl version Discipulus ?
[karlgoethebier]: Eily, Discipulus : IMHO it's worth to ask in SoPW
[Discipulus]: dunno, it is the damned doublequote issue, i think
[karlgoethebier]: Eily: ah, i have v5.24.1
Discipulus is distracted by work..

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (9)
As of 2017-07-21 08:41 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (319 votes). Check out past polls.