Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: A little golf anyone?

by petral (Curate)
on Oct 31, 2002 at 00:00 UTC ( [id://209285]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    perl -pe's/(^|\s)((\d?\d)?(\d)(\d)\d{5}|(\d?\d)?(\d)(\d)\d\d|\d{1,3})(
    +?=\s|$)/$1.($3?"    $3$4G":$4?"  $4.$5G":$6?" $6$7M":$7?" $7.$8M":$2)
    +/ge'
    
  2. or download this
    /dev/dsk/c0t1d0s1       1.2G    814M    391M    68%    /usr
    /dev/dsk/c0t1d0s3       245M     44M    176M    21%    /var
    /dev/dsk/c0t1d0s0       424M    187M    194M    49%    /home
    
  3. or download this
    perl -pe's/(^|\s)((\d*?)\d)(\d)\d\d(\d{3})?(?=\s)/$1.($5&&"   ").($3?"
    +  $2":"$2.$4").($5?"G":"M")/sge'
    
  4. or download this
    $ echo \
    1234 12 12345 123456 1234567 12345678 123456789 | perl -pe'. . .'
    1.2M 12   12M   123M    1.2G      12G      123G
    
  5. or download this
    perl -pe's/(^|\s)((\d*?)\d)(\d)(\d)\d(\d{3})?(?=\s)/$1.($6&&"   ").($3
    +?"  ".($2+($4>4)):$2+($4+($5>4))/10).($6?"G":"M")/ges'
    
  6. or download this
    perl -pe's/((\d*?)\d)(\d)\d\d(\d{3})? /$1.($2?"  ":".$3").($4?"   G ":
    +"M ")/ge'
    
  7. or download this
    $ echo '
    1234 12 123 12345 123456 7654321 12345678 123456789 ' | perl -pe'... 
    1.2M 12 123 12  M 123  M 7.6   G 12     G 123     G
    
  8. or download this
    perl -pe's!(^|\s)((\d*?)\d)(\d)\d\d((\d{3})*)(?=\s)!$"x($x=length$5).$
    +1.($3?"  $2":"$2.$4").qw(K M G T)[$x/3]!ges'
    
  9. or download this
    $ echo \
    1234 1234567 123456789012 1234567890123 123456789012345 | perl ...
    1.2K    1.2M         123G          1.2T            123T
    
  10. or download this
    perl -pe's!\d{4,}(?=\s)!sprintf"   "x($x=(-4+length$&)/3).($x*3%3?"  %
    +.0f":"%.1f").qw(M G T)[$x],$&/1024**int$x+1!ge'
    
  11. or download this
    $ echo '
    321 4321 654321 87654321 9876543210 98765432101 987654321012 '|perl...
    321 4.2M   639M      84G       9.2T         92T         920T
    
  12. or download this
    perl -pe's!(^|\s)(\d{4,})(?=\s)!sprintf"$1%s".(($x=-4+length$2)%3?"  %
    +.0f":"%.1f").(qw(M G T))[$x/=3],"   "x$x,$2/1024**int$x+1!ges'
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://209285]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-12-08 15:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which IDE have you been most impressed by?













    Results (51 votes). Check out past polls.