From 04d666b12563dfde61714b0a22a39c0eb94d4f16 Mon Sep 17 00:00:00 2001 From: Rafael Garcia-Suarez Date: Thu, 30 Jan 2003 20:52:05 +0000 Subject: FAQ sync. p4raw-id: //depot/perl@18604 --- pod/perlfaq4.pod | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'pod/perlfaq4.pod') diff --git a/pod/perlfaq4.pod b/pod/perlfaq4.pod index f7215e2eef..b77567a2c6 100644 --- a/pod/perlfaq4.pod +++ b/pod/perlfaq4.pod @@ -1,6 +1,6 @@ =head1 NAME -perlfaq4 - Data Manipulation ($Revision: 1.39 $, $Date: 2003/01/03 20:06:21 $) +perlfaq4 - Data Manipulation ($Revision: 1.40 $, $Date: 2003/01/26 17:43:21 $) =head1 DESCRIPTION @@ -142,7 +142,7 @@ Using the CPAN module Bit::Vector: =item How do I convert from decimal to hexadecimal -Using sprint: +Using sprintf: $hex = sprintf("%X", 3735928559); @@ -811,9 +811,6 @@ values of a hash if you use a slice: =head2 How do I pad a string with blanks or pad a number with zeroes? -(This answer contributed by Uri Guttman, with kibitzing from -Bart Lateur.) - In the following examples, C<$pad_len> is the length to which you wish to pad the string, C<$text> or C<$num> contains the string to be padded, and C<$pad_char> contains the padding character. You can use a single @@ -828,13 +825,16 @@ right with blanks and it will truncate the result to a maximum length of C<$pad_len>. # Left padding a string with blanks (no truncation): - $padded = sprintf("%${pad_len}s", $text); + $padded = sprintf("%${pad_len}s", $text); + $padded = sprintf("%*s", $pad_len, $text); # same thing # Right padding a string with blanks (no truncation): - $padded = sprintf("%-${pad_len}s", $text); + $padded = sprintf("%-${pad_len}s", $text); + $padded = sprintf("%-*s", $pad_len, $text); # same thing # Left padding a number with 0 (no truncation): - $padded = sprintf("%0${pad_len}d", $num); + $padded = sprintf("%0${pad_len}d", $num); + $padded = sprintf("%0*d", $pad_len, $num); # same thing # Right padding a string with blanks using pack (will truncate): $padded = pack("A$pad_len",$text); @@ -958,13 +958,13 @@ Stringification also destroys arrays. print "@lines"; # WRONG - extra blanks print @lines; # right -=head2 Why don't my <EHERE documents work? Check for these three things: =over 4 -=item There must be no space after the << part. +=item There must be no space after the EE part. =item There (probably) should be a semicolon at the end. -- cgit v1.2.1