#! /opt/third-party/bin/perl use strict; use warnings; use Switch; use constant CONV_FACTOR => '1024'; sub num_to_letter { my $val = shift; my $notation; switch ($val) { case 1 { $notation = "K"; } case 2 { $notation = "M"; } case 3 { $notation = "G"; } else { $notation = "Error"; } } return $notation; } sub num_convert { my $val = shift; my $cnt = 1; while ( ($val / +CONV_FACTOR) > 1 ) { $val /= +CONV_FACTOR; $cnt++; } return $val . num_to_letter($cnt); } my $pipeCommand = "/bin/df -k |"; open(PIPE, $pipeCommand) or die "Unable to open PIPE command $pipeCommand\n"; while(<PIPE>) { if( $. == 1 ) { print; next; } my @arr = split(/ */); for( my $i = 1; $i <= 3; $i++ ) { $arr[$i] = num_convert($arr[$i]); } print "@arr"; } close(PIPE); exit(0);