1 package C4::Format; #asummes C4/Format
7 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
9 # set the version for version checking
13 @EXPORT = qw(&fmtstr &fmtdec);
14 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
16 # your exported package globals go here,
17 # as well as any optionally exported functions
19 @EXPORT_OK = qw($Var1 %Hashit);
22 # non-exported package globals go here
23 use vars qw(@more $stuff);
25 # initalize package globals, first exported ones
30 # then the others (which are still accessible as $Some::Module::stuff)
34 # all file-scoped lexicals must be created before
35 # the functions below that use them.
37 # file-private lexicals go here
41 # here's a file-private function as a closure,
42 # callable as &$priv_func; it cannot be prototyped.
47 # make all your functions, whether exported or not;
50 # format (space pad) a string
51 # $fmt is Ln.. or Rn.. where n is the length
52 my ($env,$strg,$fmt)=@_;
53 my $align = substr($fmt,0,1);
54 my $lenst = substr($fmt,1,length($fmt)-1);
56 $strg = substr((" "x$lenst).$strg,0-$lenst,$lenst);
57 } elsif ($align eq "C" ) {
59 substr((" "x(($lenst/2)-(length($strg)/2))).$strg.(" "x$lenst),0,$lenst);
61 $strg = substr($strg.(" "x$lenst),0,$lenst);
69 my ($env,$numb,$fmt)=@_;
70 my $curr = substr($fmt,0,1);
72 $fmt = substr($fmt,1,length($fmt)-1);
74 my $comma = substr($fmt,0,1);
76 $fmt = substr($fmt,1,length($fmt)-1);
79 my $left = substr($fmt,0,1);
80 if (length($fmt) == 1) {
83 $right = substr($fmt,1,1);
88 if (index($numb,".") == 0 ){
90 $tempdec = substr($numb,1,length($numb)-1);
92 if (index($numb,".") > 0) {
93 my $decpl = index($numb,".");
94 $tempint = substr($numb,0,$decpl);
95 $tempdec = substr($numb,$decpl+1,length($numb)-1-$decpl);
101 while (length($tempdec) > 3) {
102 $fnumb = ",".substr($tempint,-3,3).$fnumb;
103 substr($tempint,-3,3) = "";
105 $fnumb = substr($tempint,-3,3).$fnumb;
111 $fnumb = fmtstr($env,$curr.$fnumb,"R".$left+1);
116 $fnumb = fmtstr($env,$fnumb,"R".$left);
120 $tempdec = $tempdec.("0"x$right);
121 $tempdec = substr($tempdec,0,$right);
122 $fnumb = $fnumb.".".$tempdec;
127 END { } # module clean-up code here (global destructor)