summaryrefslogtreecommitdiff
path: root/pod/perlfaq4.pod
diff options
context:
space:
mode:
authorPerl 5 Porters <perl5-porters@africa.nicoh.com>1997-04-23 00:00:00 +1200
committerChip Salzenberg <chip@atlantic.net>1997-04-23 00:00:00 +1200
commit46fc3d4c69a0adf236bfcba70daee7fd597cf30d (patch)
tree3b70f4a42d2ccd034756c9786032a1e531569e62 /pod/perlfaq4.pod
parent10a676f83f541430b63a3192b246bf6f86d3b189 (diff)
downloadperl-46fc3d4c69a0adf236bfcba70daee7fd597cf30d.tar.gz
[inseparable changes from match from perl-5.003_97g to perl-5.003_97h]
BUILD PROCESS Subject: Fix up Linux hints for tcsh, and Configure patch Date: Tue, 22 Apr 1997 11:02:27 -0400 (EDT) From: Andy Dougherty <doughera@lafcol.lafayette.edu> Files: Configure hints/linux.sh Msg-ID: Pine.SOL.3.95q.970422101051.2506C-100000@fractal.lafayette.e (applied based on p5p patch as commit 1eb1b1cb9647b817d039bb17afa3e74940b5ef92) Subject: There is no standard answer to 'Use suidperl?' From: Chip Salzenberg <chip@perl.com> Files: hints/bsdos.sh hints/freebsd.sh hints/linux.sh hints/machten_2.sh CORE LANGUAGE CHANGES Subject: Support PRINTF for tied handles Date: Sun, 20 Apr 1997 18:26:13 -0400 From: Doug MacEachern <dougm@opengroup.org> Files: pod/perldelta.pod pod/perltie.pod pp_sys.c t/op/misc.t Msg-ID: 199704202226.SAA08032@postman.osf.org (applied based on p5p patch as commit e7c5525577c16ee25e3521e86aca2b5105dba394) CORE PORTABILITY Subject: Fix bitwise shifts and pack('w') on Crays From: Chip Salzenberg <chip@perl.com> Files: pp.c DOCUMENTATION Subject: FAQ udpate (23-apr-97) Date: Wed, 23 Apr 1997 12:22:55 -0600 (MDT) From: Nathan Torkington <gnat@prometheus.frii.com> Files: pod/perlfaq*.pod private-msgid: 199704231822.MAA05074@prometheus.frii.com OTHER CORE CHANGES Subject: Mondo Cool patch for buffer safety and convenience From: Chip Salzenberg <chip@perl.com> Files: XSUB.h doop.c dump.c ext/DynaLoader/dl_dlopen.xs ext/DynaLoader/dl_hpux.xs ext/DynaLoader/dl_next.xs ext/DynaLoader/dlutils.c ext/ODBM_File/ODBM_File.xs global.sym gv.c interp.sym mg.c op.c perl.c perl.h pod/perlguts.pod pp.c pp_ctl.c pp_hot.c pp_sys.c proto.h regcomp.c regexec.c sv.c toke.c util.c Subject: Problems with glob Date: Sun, 20 Apr 1997 02:44:32 -0400 (EDT) From: Ilya Zakharevich <ilya@math.ohio-state.edu> Files: op.c Msg-ID: 1997Apr20.024432.1941365@hmivax.humgen.upenn.edu (applied based on p5p patch as commit a1230b335277820e65b8a9454ab751341204cf4f) Subject: Fix scalar leak in closures From: Chip Salzenberg <chip@perl.com> Files: op.c scope.c Subject: Refine error messages re: anon subs' prototypes From: Chip Salzenberg <chip@perl.com> Files: op.c Subject: Outermost scope is void, not scalar From: Chip Salzenberg <chip@perl.com> Files: pp_ctl.c
Diffstat (limited to 'pod/perlfaq4.pod')
-rw-r--r--pod/perlfaq4.pod81
1 files changed, 73 insertions, 8 deletions
diff --git a/pod/perlfaq4.pod b/pod/perlfaq4.pod
index d3a7e8ccb9..7c57d58d7d 100644
--- a/pod/perlfaq4.pod
+++ b/pod/perlfaq4.pod
@@ -1,6 +1,6 @@
=head1 NAME
-perlfaq4 - Data Manipulation ($Revision: 1.17 $, $Date: 1997/03/25 18:16:24 $)
+perlfaq4 - Data Manipulation ($Revision: 1.18 $, $Date: 1997/04/23 18:04:37 $)
=head1 DESCRIPTION
@@ -10,6 +10,34 @@ data issues.
=head1 Data: Numbers
+=head2 Why am I getting long decimals (eg, 19.9499999999999) instead of the numbers I should be getting (eg, 19.95)?
+
+Internally, your computer represents floating-point numbers in binary.
+Floating-point numbers read in from a file, or appearing as literals
+in your program, are converted from their decimal floating-point
+representation (eg, 19.95) to the internal binary representation.
+
+However, 19.95 can't be precisely represented as a binary
+floating-point number, just like 1/3 can't be exactly represented as a
+decimal floating-point number. The computer's binary representation
+of 19.95, therefore, isn't exactly 19.95.
+
+When a floating-point number gets printed, the binary floating-point
+representation is converted back to decimal. These decimal numbers
+are displayed in either the format you specify with printf(), or the
+current output format for numbers (see L<perlvar/"$#"> if you use
+print. C<$#> has a different default value in Perl5 than it did in
+Perl4. Changing C<$#> yourself is deprecated.
+
+This affects B<all> computer languages that represent decimal
+floating-point numbers in binary, not just Perl. Perl provides
+arbitrary-precision decimal numbers with the Math::BigFloat module
+(part of the standard Perl distribution), but mathematical operations
+are consequently slower.
+
+To get rid of the superfluous digits, just use a format (eg,
+C<printf("%.2f", 19.95)>) to get the required precision.
+
=head2 Why isn't my octal data interpreted correctly?
Perl only understands octal and hex numbers as such when they occur
@@ -36,10 +64,12 @@ The POSIX module (part of the standard perl distribution) implements
ceil(), floor(), and a number of other mathematical and trigonometric
functions.
-The Math::Complex module (part of the standard perl distribution)
-defines a number of mathematical functions that can also work on real
-numbers. It's not as efficient as the POSIX library, but the POSIX
-library can't work with complex numbers.
+In 5.000 to 5.003 Perls, trigonometry was done in the Math::Complex
+module. With 5.004, the Math::Trig module (part of the standard perl
+distribution) implements the trigonometric functions. Internally it
+uses the Math::Complex module and some functions can break out from
+the real axis into the complex plane, for example the inverse sine of
+2.
Rounding in financial applications can have serious implications, and
the rounding method used should be specified precisely. In these
@@ -199,6 +229,9 @@ arbitrary expressions:
print "That yields ${\($n + 5)} widgets\n";
+See also "How can I expand variables in text strings?" in this section
+of the FAQ.
+
=head2 How do I find matching/nesting anything?
This isn't something that can be tackled in one regular expression, no
@@ -234,6 +267,9 @@ Use Text::Wrap (part of the standard perl distribution):
use Text::Wrap;
print wrap("\t", ' ', @paragraphs);
+The paragraphs you give to Text::Wrap may not contain embedded
+newlines. Text::Wrap doesn't justify the lines (flush-right).
+
=head2 How can I access/change the first N letters of a string?
There are many ways. If you just want to grab a copy, use
@@ -271,7 +307,7 @@ C<tr///> function like so:
$string = "ThisXlineXhasXsomeXx'sXinXit":
$count = ($string =~ tr/X//);
- print "There are $count X characters in the string";
+ print "There are $count X charcters in the string";
This is fine if you are just looking for a single character. However,
if you are trying to count multiple character substrings within a
@@ -289,6 +325,18 @@ To make the first letter of each word upper case:
$line =~ s/\b(\w)/\U$1/g;
+This has the strange effect of turning "C<don't do it>" into "C<Don'T
+Do It>". Sometimes you might want this, instead (Suggested by Brian
+Foy E<lt>comdog@computerdog.comE<gt>):
+
+ $string =~ s/ (
+ (^\w) #at the beginning of the line
+ | # or
+ (\s\w) #preceded by whitespace
+ )
+ /\U$1/xg;
+ $string =~ /([\w']+)/\u\L$1/g;
+
To make the whole line upper case:
$line = uc($line);
@@ -321,6 +369,11 @@ suggests (assuming your string is contained in $text):
}gx;
push(@new, undef) if substr($text,-1,1) eq ',';
+If you want to represent quotation marks inside a
+quotation-mark-delimited field, escape them with backslashes (eg,
+C<"like \"this\""). Unescaping them is a task addressed earlier in
+this section.
+
Alternatively, the Text::ParseWords module (part of the standard perl
distribution) lets you say:
@@ -368,6 +421,9 @@ substitution:
Which is bizarre enough that you'll probably actually need an EEG
afterwards. :-)
+See also "How do I expand function calls in a string?" in this section
+of the FAQ.
+
=head2 What's wrong with always quoting "$vars"?
The problem is that those double-quotes force stringification,
@@ -668,7 +724,7 @@ that's come to be known as the Schwartzian Transform:
@sorted = map { $_->[0] }
sort { $a->[1] cmp $b->[1] }
- map { [ $_, uc((/\d+\s*(\S+) )[0] ] } @data;
+ map { [ $_, uc((/\d+\s*(\S+)/ )[0] ] } @data;
If you need to sort on several fields, the following paradigm is useful.
@@ -900,7 +956,7 @@ they end up doing is not what they do with ordinary hashes.
Using C<keys %hash> in a scalar context returns the number of keys in
the hash I<and> resets the iterator associated with the hash. You may
need to do this if you use C<last> to exit a loop early so that when you
-reenter it, the hash iterator has been reset.
+re-enter it, the hash iterator has been reset.
=head2 How can I get the unique keys from two hashes?
@@ -938,6 +994,14 @@ it on top of either DB_File or GDBM_File.
Use the Tie::IxHash from CPAN.
+ use Tie::IxHash;
+ tie(%myhash, Tie::IxHash);
+ for ($i=0; $i<20; $i++) {
+ $myhash{$i} = 2*$i;
+ }
+ @keys = keys %myhash;
+ # @keys = (0,1,2,3,...)
+
=head2 Why does passing a subroutine an undefined element in a hash create it?
If you say something like:
@@ -1035,3 +1099,4 @@ Get the Business::CreditCard module from CPAN.
Copyright (c) 1997 Tom Christiansen and Nathan Torkington.
All rights reserved. See L<perlfaq> for distribution information.
+