Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2004
    Posts
    1

    Unanswered: Formatting in Perl

    Hi,

    I have a perl program as

    #!/usr/local/bin/perl
    $money = 5;
    select (STDOUT)
    $~="BLXFILE";
    write;



    format BLXFILE =
    @###
    $money


    Here i need the output to be displayed as 0005 instead of " 5", i.e, i want to change the number to be padded by zeros instead of spaces. Is this possible?

    Thanks,
    Mukundan

  2. #2
    Join Date
    Jan 2004
    Location
    Germany
    Posts
    167
    as a feed: perldoc -f sprintf
    Code:
    #! /usr/local/bin/perl
    
    use strict;
    
    my $money = 5;
    my $test = sprintf("%05i",$money);
    print $test,"\n";
    board.perl-community.de - The German Perl-Community

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •