NAME
Acme::Tie::Formatted - embed sprintf() formatting in regular print()
VERSION
This document describes Acme::Tie::Formatted version 0.03
SYNOPSIS
use Tie::Formatted;
print "The value is $format{$number, "%3d"} ",
"(or $format{$number, "%04x"} in hex)\n";
print "some numbers: $format{ 12, 492, 1, 8753, "%04d"}\n";
DESCRIPTION
This module creates a global read-only hash, %format
, for formatting data items with standard sprintf
format specifications. Since it's a hash, you can interpolate it into strings as well as use it standalone.
The hash should be "accessed" with two or more "keys". The last key is interpreted as a sprintf
format for each data item specified in the preceeding arguments. This allows you to format multiple items at once using the same format for each.
Alternate name
If you prefer, you can specify a different name for the magical formatting hash by supplying it as as argument when use
ing the module:
use Tie::Formatted qw(z);
This makes %z
the magic hash instead.
print "This is hex: $z{255, "%04x"}\n";
Tie::Formatted
currently supports only one format in the final argument; this may change if there is demand for it.
DIAGNOSTICS
You can only use %format by accessing it
-
You tried to store something in
%format
, check if an element exists in it, delete an element, empty out the hash, or access the key in it.None of these operations do anything; only reading elements of the ahsh works.
CONFIGURATION AND ENVIRONMENT
Tie::Formatted requires no configuration files or environment variables.
DEPENDENCIES
None.
INCOMPATIBILITIES
None reported.
BUGS AND LIMITATIONS
No bugs have been reported.
Please report any bugs or feature requests to bug-tie-formatted@rt.cpan.org
, or through the web interface at http://rt.cpan.org.
AUTHOR
Joe McMahon <mcmahon@cpan.org>
LICENCE AND COPYRIGHT
Copyright (c) 2006, Joe McMahon <mcmahon@cpan.org>
. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
DISCLAIMER OF WARRANTY
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
CREDITS
Sean Burke, for saying he wanted this.
Eric J. Roode, for Tie::Comma (which this is derived from).
Mark-Jason Dominus, for Interpolate.
"We are like dwarfs sitting on the shoulders of giants. We see more than they do, indeed even farther; but not because our sight is better than theirs or because we are taller than they. Our sight is enhanced because they raise us up and increase our stature by their enormous height." - Bernard de Chartes