If you haven't already, read perldoc perlipc for information of setting up signal handlers using %SIG. The HUP, USR1, and USR2 signals are good candiates. The usual idiom is to have the handler set a flag, and then you check that flag in your main loop.

my $reload_config = 0; $SIG{USR1} = sub { $reload_config = 1 }; ... while( $yadda_yadda_yadda ) { check_something( $something ); poll_for_widgets( $mywidgets ); if( $reload_config ) { reload_my_config( $config ); $reload_config = 0; } }

As for sending interrupts from the keyboard, you're pretty much limited to INT, QUIT, and TSTP as far as what you can send from the keyboard with a plain tty driver. Usually stty -a will give a list of what keys will send what particular signal. For example here's what I get on Linux (YDL 2.0 PPC):

speed 38400 baud; rows 30; columns 80; line = 0; intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = + ^W; ...

Ctrl-c will send SIGINT, Ctrl-\ will send SIGQUIT, and Ctrl-z sends SIGTSTP. You can't really send other signals (USR1, HUP, et al) easily from the keyboard, but you can always have your program write out its PID to a file and then use backticks in your shell to do kill -HUP `cat /var/run/myprog.pid`.

You may also want to look into Event or POE, both of which provide ways of triggering events in your program when signals are received.


In reply to Re: Using traps to autoincrement / decrement variables by Fletch
in thread Using traps to autoincrement / decrement variables by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.