in reply to ilf - input line frequency time event visualization
Second, why not use the perl-internal time and date functions (or one of the many modules for manipulating date/time values and strings), instead of relying on an OS-dependent "date" shell command? (Yes, the "date" command could have different default output formats on different versions of unix.)
Third, that "whatchar" sub is kind of ugly and way too long. Here's how I would do it:
Note that in the OP code, a "$diff" value of zero had the effect of not changing the value of the global "$pchar". Was that intentional?sub whatchar { my $diff = shift; # pass a parameter rather than checking a globa +l my $char; # return this value rather than setting a global my @zeroto1 = qw/! @ # $ % ^ & * ( )/; # characters for values <1 # (the hash mark there will generate a warning, but it's okay) if ( $diff <= 0 ) { $char = ' '; # differs from OP code } elsif ( $diff < 1 ) { $char = $zeroto1[int( $diff * 10 )]; } elsif ( $diff < 10 ) { $char = ( $diff < 9 ) ? chr( int( $diff ) + ord( '1' )) : '0'; # are you sure "234567890" is better than "123456789" ?? # ... $char = chr( int( $diff ) + ord( '0' )) seems okay to me } elsif ( $diff <= 35 ) { $char = chr( int( $diff - 10 ) + ord( 'a' )); } else { $diff = 260 if ( $diff > 260 ); $char = chr( int( $diff/10 ) - 3 + ord( 'C' )); } return $char; }
Also, my version is written so that the caller doesn't need to do "int($diff)" before calling "whatchar()" (not that it matters, but it just makes more sense to me that way).
Other things can be done to clean up and simplify your code -- I'm just hitting the points that leaped out at me.
update: actually one more thing does jump out at me: fix the usage message; something like this:
Be a little less verbose and exhaustive in the examples, and more "schematic" and structured in the overview of args and options, to make it clear what the command line syntax is.Usage: $0 'command line' $0 -- commmand [args ...] $0 builtin {-D|-N|-S|-W} [options ...] "builtin" functions: -D 'command line' : track "command" output -N [-n[o]] : track output of lsof (network status) ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
| A reply falls below the community's threshold of quality. You may see it by logging in. |