Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: How to end "do" with Ctrl-C

by pfaut (Priest)
on Dec 02, 2008 at 22:33 UTC ( #727508=note: print w/replies, xml ) Need Help??


in reply to How to end "do" with Ctrl-C

You need to trap the INT signal.

our $stopit = 0; $SIG{INT} = sub { $stopit++; }; while (!$stopit) { system("netstat -an | grep $line"); sleep 10; }
90% of every Perl application is already written.
dragonchild

Replies are listed 'Best First'.
Re^2: How to end "do" with Ctrl-C
by kennethk (Abbot) on Dec 02, 2008 at 23:03 UTC
    Yeah, what pfaut said. As an additional note, your chomp removes the end line, so your test would always pass. If you really want to catch bad input, you could try:
    use strict; my $port = shift; our $stopit = 0; $SIG{INT} = sub { $stopit++; }; if (!$port or $port =~ /\D/) { print "usage: program port_num\n"; } else { while (!$stopit) { print system("netstat -an | grep $port"), "\n"; sleep 10; } }

    or whatever variant will get you what you want.

      print system("netstat -an | grep $port"), "\n";

      That should be

      system("netstat -an | grep $port");

      or

      print qx{netstat -an | grep $port};

      or

      print grep /$port/, qx{netstat -an};
      Thank you, works great!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://727508]
help
Chatterbox?
[james28909]: well i have officially wore my brains out on hash refs and array refs and hash of arrays
[james28909]: push @{$hash{$ref}}, $this, $that, $the_other;
[james28909]: for 0 .. 3 {print $hash{$ref}}$_;
[james28909]: or i guess that is a hash ref
[james28909]: hash of array ref <.<
[james28909]: im also about to embark on porting the discord api to perl, without having to have 400 dependencies...
[james28909]: would be nice to link doscord to irc and other services

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2017-05-01 03:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (544 votes). Check out past polls.