Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Is This Possible?

by jdlev (Scribe)
on Sep 13, 2013 at 12:05 UTC ( #1053904=perlquestion: print w/replies, xml ) Need Help??
jdlev has asked for the wisdom of the Perl Monks concerning the following question:

So I run my pl programs through my command prompt. Well, the amount of data it is processing is just ridiculous. It hasn't ever actually made it to the end of the program. Anyways, is there a way for perl to spit out the max values it finds when you terminate the program by pushing ctrl-c? TIA...
I love it when a program comes together - jdhannibal

Replies are listed 'Best First'.
Re: Is This Possible?
by Perlbotics (Canon) on Sep 13, 2013 at 12:13 UTC

    Use a signal handler (perlipc).

    use strict; use warnings; my $max; #-- set a signal handler $SIG{INT} = sub { print "Max: $max -- now leaving...\n"; exit 1; }; #-- main while (<>) { # do something that updates $max } print "Max: $max (finally)\n"; #-- normal termination (exit 0)

Re: Is This Possible?
by SuicideJunkie (Vicar) on Sep 13, 2013 at 14:10 UTC

    Why not print "Value so far: $maxVal\r" unless $. % 250; inside your loop?

    With the \r it will overwrite the previous text rather than scrolling madly, and give you a continual update. The $. % 250 keeps it from spending all its time printing. Adjust the variable and value depending on what you are looping over and how fast the loop spins.

      I decided to write to a log interval at interval. Seems to be working splendidly. :)
      I love it when a program comes together - jdhannibal
Re: Is This Possible?
by thezip (Vicar) on Sep 13, 2013 at 16:46 UTC

    You might also consider keeping track of the max value encountered so far, replacing it when a higher max value is found. When this event happens, print a message saying "A new max value of $MAX was found..."

    I would think that this would quickly stop reporting to the screen.


    What can be asserted without proof can be dismissed without proof. - Christopher Hitchens, 1949-2011
Re: Is This Possible?
by Marshall (Abbot) on Sep 13, 2013 at 13:52 UTC
    Your program is just "not working". You don't have any idea of how the algorithms are functioning.

    Take a small data set and process that and see what that does.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1053904]
Approved by Corion
help
Chatterbox?
[RonW]: Sounds like some system my employer has "It does exactly what we need it to do and can't afford to risk anything we can't prove is 100% compatible"
[marto]: choroba sounds interesting
[RonW]: james28909 Why not write a Perl program to do the task?
[choroba]: RonW Yes, but then, one day, they needed to switch from FTP to SFTP, and... but I can't give the whole talk away here :)
[RonW]: Tunnel FTP through stunnel?

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2017-05-22 21:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?