diff options
author | Andy Dougherty <doughera.lafayette.edu> | 1995-12-21 00:01:16 +0000 |
---|---|---|
committer | Andy Dougherty <doughera.lafayette.edu> | 1995-12-21 00:01:16 +0000 |
commit | cb1a09d0194fed9b905df7b04a4bc031d354609d (patch) | |
tree | f0c890a5a8f5274873421ac573dfc719188e5eec /pod/perldata.pod | |
parent | 3712091946b37b5feabcc1f630b32639406ad717 (diff) | |
download | perl-cb1a09d0194fed9b905df7b04a4bc031d354609d.tar.gz |
This is patch.2b1g to perl5.002beta1.
cd to your perl source directory, and type
patch -p1 -N < patch.2b1g
This patch is just my packaging of Tom's documentation patches
he released as patch.2b1g.
Patch and enjoy,
Andy Dougherty doughera@lafcol.lafayette.edu
Dept. of Physics
Lafayette College, Easton PA 18042
Diffstat (limited to 'pod/perldata.pod')
-rw-r--r-- | pod/perldata.pod | 59 |
1 files changed, 54 insertions, 5 deletions
diff --git a/pod/perldata.pod b/pod/perldata.pod index 648f0922e1..9b3798ffb1 100644 --- a/pod/perldata.pod +++ b/pod/perldata.pod @@ -1,6 +1,6 @@ =head1 NAME -perldata - Perl data structures +perldata - Perl data types =head1 DESCRIPTION @@ -60,8 +60,8 @@ of this, see L<perlref>. Names that start with a digit may only contain more digits. Names which do not start with a letter, underscore, or digit are limited to -one character, e.g. "$%" or "$$". (Most of these one character names -have a predefined significance to Perl. For instance, $$ is the +one character, e.g. C<$%> or C<$$>. (Most of these one character names +have a predefined significance to Perl. For instance, C<$$> is the current process id.) =head2 Context @@ -138,7 +138,7 @@ array. An undefined null scalar may become defined the first time you use it as if it were defined, but prior to that you can use the defined() operator to determine whether the value is defined or not. -To find out whether a given string is a valid non-zero number, it's usally +To find out whether a given string is a valid non-zero number, it's usually enough to test it against both numeric 0 and also lexical "0" (although this will cause B<-w> noises). That's because strings that aren't numbers count as 0, just as the do in I<awk>: @@ -147,6 +147,18 @@ numbers count as 0, just as the do in I<awk>: warn "That doesn't look like a number"; } +That's usually preferable because otherwise you won't treat IEEE notations +like C<NaN> or C<Infinity> properly. At other times you might prefer to +use a regular expression to check whether data is numeric. See L<perlre> +for details on regular expressions. + + warn "has nondigits" if /\D/; + warn "not a whole number" unless /^\d+$/; + warn "not an integer" unless /^[+-]?\d+$/ + warn "not a decimal number" unless /^[+-]?\d+\.?\d*$/ + warn "not a C float" + unless /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/; + The length of an array is a scalar value. You may find the length of array @days by evaluating C<$#days>, as in B<csh>. (Actually, it's not the length of the array, it's the subscript of the last element, since @@ -252,7 +264,8 @@ logical end of the script before the actual end of file. Any following text is ignored, but may be read via the DATA filehandle. (The DATA filehandle may read data only from the main script, but not from any required file or evaluated string.) The two control characters ^D and -^Z are synonyms for __END__ (or __DATA__ in a module). +^Z are synonyms for __END__ (or __DATA__ in a module; see L<SelfLoader> for +details on __DATA__). A word that has no other interpretation in the grammar will be treated as if it were a quoted string. These are known as @@ -471,3 +484,39 @@ or for using call-by-named-parameter to complicated functions: linebreak => 'true', labels => \%labels ); + +Note that just because a hash is initialized in that order doesn't +mean that it comes out in that order. See L<perlfunc/sort> for examples +of how to arrange for an output ordering. + +=head2 Typeglobs and FileHandles + +Perl uses an internal type called a I<typeglob> to hold an entire +symbol table entry. The type prefix of a typeglob is a C<*>, because +it represents all types. This used to be the preferred way to +pass arrays and hashes by reference into a function, but now that +we have real references, this is seldom needed. + +One place where you still use typeglobs (or references thereto) +is for passing or storing filehandles. If you want to save away +a filehandle, do it this way: + + $fh = *STDOUT; + +or perhaps as a real reference, like this: + + $fh = \*STDOUT; + +This is also the way to create a local filehandle. For example: + + sub newopen { + my $path = shift; + local *FH; # not my! + open (FH, $path) || return undef; + return \*FH; + } + $fh = newopen('/etc/passwd'); + +See L<perlref>, L<perlsub>, and L<perlmod/"Symbols Tables"> for more +discussion on typeglobs. See L<perlfunc/open> for other ways of +generating filehandles. |