Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Lots of room for improvement here. First off, why do you abandon sensible line-breaks and indenting in those initial "if" blocks (just before the "while" loop)? It would be better if those were more legible. (And I'll bet it would be easier to find ways to eliminate some redundant coding there.)

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:

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; }
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?

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:

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) ...
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.

In reply to Re: ilf - input line frequency time event visualization by graff
in thread ilf - input line frequency time event visualization by cider

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (4)
    As of 2020-06-05 04:16 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Do you really want to know if there is extraterrestrial life?



      Results (35 votes). Check out past polls.

      Notices?