LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 11-20-2006, 07:12 AM   #1
noir911
Member
 
Registered: Apr 2004
Location: Baltimore, MD
Posts: 681

Rep: Reputation: Disabled
[Perl] basic byte conversion script


I am very new to Perl and wrote this very simple to convert bytes to KB to MB to GB. So far it's working fine. But I tried to use "%g" in place of "%f" - which according to Learning Perl 4th ed. automatically
chooses float, integer etc. But it was not giving desired output. If anyone could tell me why I can't seem to use %g and also make some comments on the current code then that would be much appreciated.
Here's the code

Code:
#!/usr/bin/perl
use strict;
use warnings;
print "enter the value\n";
chomp (my $value=<STDIN>); 
my $kilo = $value/1024;
my $mega = $kilo/1024;
my $giga = $mega/1024;
print "the value is $value\n";
printf "%0.2f KB\n", $kilo;
printf "%0.2f MB\n", $mega;
printf "%0.2f GB\n", $giga;
 
Old 11-21-2006, 02:01 AM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
I think you'll find this page more informative: http://perldoc.perl.org/functions/sprintf.html
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginner on Scilab, matlab script conversion munichtexan Linux - Software 6 12-08-2005 07:42 PM
Converting a Windows Perl script to a Linux Perl script. rubbercash Programming 2 07-19-2004 11:22 AM
ASP using VBScript conversion to Perl Dewar Linux - Software 1 06-24-2004 01:46 PM
ASP using VBScript conversion to Perl Dewar Programming 0 06-24-2004 01:45 PM
Including methods from a perl script into another perl script gene_gEnie Programming 3 01-31-2002 06:03 AM


All times are GMT -5. The time now is 11:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration