LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 06:12 AM   #1
noir911
Member
 
Registered: Apr 2004
Posts: 682

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, 01:01 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

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


Reply



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 06:42 PM
Converting a Windows Perl script to a Linux Perl script. rubbercash Programming 2 07-19-2004 10:22 AM
ASP using VBScript conversion to Perl Dewar Linux - Software 1 06-24-2004 12:46 PM
ASP using VBScript conversion to Perl Dewar Programming 0 06-24-2004 12:45 PM
Including methods from a perl script into another perl script gene_gEnie Programming 3 01-31-2002 05:03 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:07 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
Open Source Consulting | Domain Registration