User Tools

Site Tools


perl:index

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
perl:index [2009/08/13 09:56] – Links to command_line_options_with_usage changed to perl:command_line_options_with_usage tkbletscperl:index [2010/01/08 13:50] (current) tkbletsc
Line 1: Line 1:
-====== links ======+====== Perl code snippets ======
  
-  * [[:real_csv_parsing]] +  * [[Prototype class for OO]] 
-  * [[:ansi_color]] +  * [[Real CSV Parsing]] 
-  * [[:sets]] +  * [[ANSI color]] 
-  * [[:dns_stuff]] +  * [[Sets]] 
-  * [[:make_a_loop_parallel]] +  * [[DNS stuff]] 
-  * [[:command_line_options_and_usage_with_getopt_long]] +  * [[Make a loop parallel]] 
-  * [[:command_line_options_and_usage_with_getopts]] +  * [[Command line options and usage with Getopt Long]] 
-  * [[command_line_options_with_usage]] +  * [[Command line options and usage with getopts]] 
-  * [[for_each_file]] +  * [[command line options with usage]] 
-  * [[forking_server]]+  * [[For each file]] 
 +  * [[Forking server]]
   * [[kvpff]]   * [[kvpff]]
-  * [[loop_with_timekeeping]] +  * [[Loop with timekeeping]] 
-  * [[single_document_web_server]] +  * [[Single document web server]] 
-  * [[read_password_without_echo]]+  * [[Read password without echo]] 
 +  * [[Amazon preview leech]]
    
-====== blobs of code ======+====== Blobs of code ======
  
 <code perl> <code perl>
Line 24: Line 26:
 sub sum { my $r=0; for (@_) { $r += $_ }; return $r; } sub sum { my $r=0; for (@_) { $r += $_ }; return $r; }
 sub avg { return sum(@_)/@_; } sub avg { return sum(@_)/@_; }
 +sub stdev {
 + my $s=0;
 + my $avg = avg(@_);
 + foreach (@_){
 + $s += ($_ - $avg)**2;
 + }
 + return sqrt($s/(@_-1));
 +}
 sub limits { sub limits {
  my $lo = my $hi = $_[0];  my $lo = my $hi = $_[0];
Line 67: Line 77:
  '<undefined timestamp format>';  '<undefined timestamp format>';
 } }
 +
 +sub size_units {
 + my ($n) = @_;
 + if ($n>1024*1024*1024*1024) { return sprintf("%.1f T",$n/(1024*1024*1024*1024)); }
 + if ($n>     1024*1024*1024) { return sprintf("%.1f G",$n/    1024*1024*1024)); }
 + if ($n>          1024*1024) { return sprintf("%.1f M",$n/         1024*1024)); }
 + if ($n>               1024) { return sprintf("%.1f k",$n/              1024)); }
 + return $n;
 +}
 +
 +sub parse_size_units {
 + my ($s) = @_;
 + if ($s=~/^([.\d]+)([kmgt]?)$/i) {
 + if    ($2 eq 't' || $2 eq 'T') { return $1*1024*1024*1024*1024; }
 + elsif ($2 eq 'g' || $2 eq 'G') { return $1*1024*1024*1024; }
 + elsif ($2 eq 'm' || $2 eq 'M') { return $1*1024*1024; }
 + elsif ($2 eq 'k' || $2 eq 'K') { return $1*1024; }
 + else                           { return $1; }
 + } else {
 + return undef;
 + }
 +}
 +
  
  
perl/index.1250182606.txt.gz · Last modified: 2009/08/13 09:56 by tkbletsc

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki