Sponsored Content
Full Discussion: Pausing function with Perl
Top Forums Shell Programming and Scripting Pausing function with Perl Post 302262275 by milo on Thursday 27th of November 2008 12:47:20 AM
Old 11-27-2008
Below is what I've tried. However, I use ^C to interrupt (don't know how to use ^P) and a select menu to resume couting time.

Code:
#!/usr/bin/perl
# The script is to couting time (show clock) and support Ctrl-C to pause clock
# then choose a key to continue couting or exit.

use strict 'vars';

$SIG{'INT'} = 'Pause';	# use signal handling, if press ^C, will interrupt and call sub Pause.

print "Press Ctrl-C to pause couting time \n";

our ($hour,$min,$sec) = ();
($hour,$min,$sec) = clock (0,0,0); # start couting with at 00:00:00

sub Pause {
  print "\nCaught ^C\n";
  print "Press \"c\" to continue, \"e\" to exit: ";
  while (1) {
    my $input = lc(getc());
    chomp ($input);
    if ($input eq 'c') {
      clock($hour,$min,$sec);
    }
    elsif ($input eq 'e') {
      exit 1;
    }
  }
}

# sub clock is to count time
sub clock {
  our ($hour, $min, $sec) = @_;	# declare as the global variables
  while (1) {
      sleep 1;	# get clock of system for each one second
      $sec++;
      if ($sec == 60) {
	$sec = 0;
	$min++;
	if ($min == 60) {
          $min = 0;
	  $hour++;
	  $hour = 0 if ($hour == 24)
	}
      }
      printf ("%2d:%2d:%2d\n",$hour,$min,$sec);
  }    
  return ($hour,$min,$sec);
}

The output looks like:

Code:
C:\Program Files\Perl\mine>pause_func.pl
Press Ctrl-C to pause couting time
 0: 0: 1
 0: 0: 2
 0: 0: 3

Caught ^C
Press "c" to continue, "e" to exit: c
 0: 0: 4
 0: 0: 5

Caught ^C
Press "c" to continue, "e" to exit: e

C:\Program Files\Perl\mine>

If you know how to have ^P to interrupt counting and other method to get this done, that would be great.

Thanks,
Milo
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

pausing a script

hello all, I have a script (Solaris v8 ksh) monitoring an inbound directory for reports. The script will then capture the report based on a set of circumstances. However I am unable to capture a report larger then 2-Gig in size due to program limitations. What I need to do is pause the monitor... (6 Replies)
Discussion started by: gozer13
6 Replies

2. Shell Programming and Scripting

Pausing a Grep output

I am writing a small script which allows users to grep multiple log files across multiple directories, and often the output produced by the grep statements is quite lengthy. It would be nice if the output to the screen could be "paused" when it reaches a certain length (say, the length of the... (5 Replies)
Discussion started by: mharley
5 Replies

3. Shell Programming and Scripting

PERL function problem

I have perl script as follow. ------------------------------------------------------------------------ #! /usr/bin/env perl use strict; sub printLines { print "Inside the function.............\n"; my (@file , $count , $key ) = $_; print $count , $ key ; #... (2 Replies)
Discussion started by: avadhani
2 Replies

4. Shell Programming and Scripting

Pausing between two executions in a shell script

HI, Please help me on this. I have to execute 100 scripts which i have redirected in to a file . I want to pause the script after first execution and once i say enter key word it has to go to next execution. My looks like for RUNFILES in `cat ${SOURCEFILES}/scripts` do echo $RUNFILES; ... (1 Reply)
Discussion started by: srichunduru
1 Replies

5. Shell Programming and Scripting

Help !! perl open function

Help Please perl Gurus, I am trying to add ungrouped passengers in a group and I creating a script however it fails on first step only I tried all the options it returns following error. syntax error at junki line 4, near "open " Execution of junki aborted due to compilation errors. ... (2 Replies)
Discussion started by: dynamax
2 Replies

6. Shell Programming and Scripting

perl function enquery

Dear all, I find a perl script that contains the following codes. Does anybody know the meaning of codes highlight. ..... @field = parse_csv($file); chomp(@field); ........ ........ sub parse_csv { my $text = shift; my @new = (); push( @new, $+ ) while $text =~ m{... (9 Replies)
Discussion started by: eldonlck
9 Replies

7. UNIX for Dummies Questions & Answers

Pausing and resuming process on laptop

Hi, I'm wondering if it's possible to pause a process I'm running in the background, close my laptop (I need to leave the office), and continue the process (when I get home). I've been running a process for a really long time and I don't want to have to start it over. Thanks in advance! (9 Replies)
Discussion started by: ShiGua
9 Replies

8. Shell Programming and Scripting

Read not prompting/ pausing for input

Heya people, So my script is one of those make-user-scripts, making a bunch of directories in the home folder and copying some files over into the new directories. However, part of the thing my script need to do is check the home folder if a username matches with a directory which already exists.... (6 Replies)
Discussion started by: Cloudy_Cat
6 Replies

9. Shell Programming and Scripting

Pausing a cron job

Hi All, I have a cronjob which runs a script every 5 mins. My problem is before the script is completed the cron job starts again after 5 mins. How can I put this second cron job to wait unless the first script has completed. Could you please help me on that (7 Replies)
Discussion started by: prats_7678
7 Replies

10. Shell Programming and Scripting

Converting shell to Perl I run into shell built in function trap and need alternative in Perl

I am working on converting shell to Perl script. In shell we have built in function trap Do you know alternative in Perl or actually we don't need it? Thanks for contribution (3 Replies)
Discussion started by: digioleg54
3 Replies
SOAPSH(1p)						User Contributed Perl Documentation						SOAPSH(1p)

NAME
SOAPsh - Interactive shell for SOAP calls SYNOPSIS
perl SOAPsh http://services.soaplite.com/examples.cgi http://www.soaplite.com/My/Examples > getStateName(2) > getStateNames(1,2,3,7) > getStateList([1,9]) > getStateStruct({a=>1, b=>24}) > Ctrl-D (Ctrl-Z on Windows) or # all parameters after uri will be executed as methods perl SOAPsh http://soap.4s4c.com/ssss4c/soap.asp http://simon.fell.com/calc doubler([10,20,30]) > Ctrl-D (Ctrl-Z on Windows) DESCRIPTION
SOAPsh is a shell for making SOAP calls. It takes two parameters: mandatory endpoint and optional uri (actually it will tell you about it if you try to run it). Additional commands can follow. After that you'll be able to run any methods of SOAP::Lite, like autotype, readable, encoding, etc. You can run it the same way as you do it in your Perl script. You'll see output from method, result of SOAP call, detailed info on SOAP faulure or transport error. For full list of available methods see documentation for SOAP::Lite. Along with methods of SOAP::Lite you'll be able (and that's much more interesting) run any SOAP methods you know about on remote server and see processed results. You can even switch on debugging (with call something like: "on_debug(sub{print@_})") and see SOAP code with headers sent and received. COPYRIGHT
Copyright (C) 2000 Paul Kulchenko. All rights reserved. AUTHOR
Paul Kulchenko (paulclinger@yahoo.com) perl v5.12.4 2010-06-03 SOAPSH(1p)
All times are GMT -4. The time now is 01:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy