Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
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

Comment on Is This Possible?
Re: Is This Possible?
by Perlbotics (Abbot) 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 Marshall (Prior) 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.

Re: Is This Possible?
by SuicideJunkie (Priest) 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

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?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2014-09-23 00:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (208 votes), past polls