Skip to content

Commit c9c5e76

Browse files
karenetheridgejkeenan
authored andcommitted
cpan/perlfaq - Update to version 5.20230812
5.20230812 2023-08-12 21:30:12Z * some typo fixes to perlfaq4 (PR #103 and PR#104, brian d foy) * some wording improvements to perlfaq4 for "Why doesn't & work the way I want it to?" (PR#104, resolves issue #101, brian d foy) * some updates to perlfaq2 for perl magazines (PR#105, brian d foy)
1 parent 03dbf5c commit c9c5e76

13 files changed

+83
-43
lines changed

Porting/Maintainers.pl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,8 @@ package Maintainers;
918918
},
919919

920920
'perlfaq' => {
921-
'DISTRIBUTION' => 'ETHER/perlfaq-5.20230701.tar.gz',
921+
'DISTRIBUTION' => 'ETHER/perlfaq-5.20230812.tar.gz',
922+
'SYNCINFO' => 'jkeenan on Wed Aug 16 18:13:51 2023',
922923
'FILES' => q[cpan/perlfaq],
923924
'EXCLUDED' => [ qr/^inc/, qr/^xt/, qr{^t/00-} ],
924925
},

cpan/perlfaq/lib/perlfaq.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ use strict;
22
use warnings;
33
package perlfaq;
44

5-
our $VERSION = '5.20230701';
5+
our $VERSION = '5.20230812';
66

77
1;

cpan/perlfaq/lib/perlfaq.pod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ perlfaq - Frequently asked questions about Perl
44

55
=head1 VERSION
66

7-
version 5.20230701
7+
version 5.20230812
88

99
=head1 DESCRIPTION
1010

cpan/perlfaq/lib/perlfaq1.pod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ perlfaq1 - General Questions About Perl
44

55
=head1 VERSION
66

7-
version 5.20230701
7+
version 5.20230812
88

99
=head1 DESCRIPTION
1010

cpan/perlfaq/lib/perlfaq2.pod

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
=pod
2+
3+
=encoding UTF-8
4+
15
=head1 NAME
26

37
perlfaq2 - Obtaining and Learning about Perl
48

59
=head1 VERSION
610

7-
version 5.20230701
11+
version 5.20230812
812

913
=head1 DESCRIPTION
1014

@@ -172,12 +176,16 @@ There are many good L<books on Perl|http://www.perl.org/books/library.html>.
172176

173177
=head2 Which magazines have Perl content?
174178

175-
There's also I<$foo Magazin>, a German magazine dedicated to Perl, at
176-
( L<http://www.foo-magazin.de> ). The I<Perl-Zeitung> is another
177-
German-speaking magazine for Perl beginners (see
178-
L<http://perl-zeitung.at.tf> ).
179+
There are no current magazines that focus on Perl, although you sometimes
180+
will find Perl content in more general interest programming titles.
181+
182+
In the distant past, there have been a few Perl magazines. The first was I<The Perl
183+
Journal>, published by Jon Orwant. After that, there was I<The Perl Review>,
184+
published by brian d foy, and I<$foo Magazin>, published by Renée Bäcker
185+
(L<http://www.foo-magazin.de>).
179186

180-
Several Unix/Linux related magazines frequently include articles on Perl.
187+
The closest you might find today is Perl Weekly, (L<https://perlweekly.com>),
188+
an online newsletter with a magazine-like format.
181189

182190
=head2 Which Perl blogs should I read?
183191

cpan/perlfaq/lib/perlfaq3.pod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ perlfaq3 - Programming Tools
44

55
=head1 VERSION
66

7-
version 5.20230701
7+
version 5.20230812
88

99
=head1 DESCRIPTION
1010

cpan/perlfaq/lib/perlfaq4.pod

Lines changed: 57 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ perlfaq4 - Data Manipulation
44

55
=head1 VERSION
66

7-
version 5.20230701
7+
version 5.20230812
88

99
=head1 DESCRIPTION
1010

@@ -277,32 +277,63 @@ are left as an exercise to the inclined reader.
277277

278278
=head2 Why doesn't & work the way I want it to?
279279

280-
The behavior of binary arithmetic operators depends on whether they're
281-
used on numbers or strings. The operators treat a string as a series
282-
of bits and work with that (the string C<"3"> is the bit pattern
283-
C<00110011>). The operators work with the binary form of a number
284-
(the number C<3> is treated as the bit pattern C<00000011>).
280+
Perl's C<&> bitwise operator works on both numbers and strings,
281+
sometimes producing surprising results when you expected a number
282+
but received a string. You probably expected perl to automatically
283+
convert the operands to numbers like the mathematical operators would.
284+
Instead, perl treats string operands as bitvectors.
285285

286-
So, saying C<11 & 3> performs the "and" operation on numbers (yielding
287-
C<3>). Saying C<"11" & "3"> performs the "and" operation on strings
288-
(yielding C<"1">).
286+
Consider the bitwise difference between the number 3 and the bitvector
287+
represented by "3". A number has the bit pattern for its magnitude. The
288+
number 3 is 0b11 (a 2 and a 1). The bitvector has the bit pattern that
289+
is the ordinal value for each octet, and that value is unrelated to any
290+
numeric value that the digit represents. The character "3" is the
291+
bitvector 0b0011_0011.
289292

290-
Most problems with C<&> and C<|> arise because the programmer thinks
291-
they have a number but really it's a string or vice versa. To avoid this,
292-
stringify the arguments explicitly (using C<""> or C<qq()>) or convert them
293-
to numbers explicitly (using C<0+$arg>). The rest arise because
294-
the programmer says:
293+
These operations have different results even though you might think they
294+
look like the same "number":
295295

296-
if ("\020\020" & "\101\101") {
297-
# ...
298-
}
296+
11 & 3; # 0b0000_1011 & 0b0000_0011
297+
# -> 0b0000_0011 (number 3)
298+
"11" & "3"; # 0b0011_0001_0011_0001 & 0b0011_0011
299+
# -> 0b0011_0001 (ASCII char "1")
299300

300-
but a string consisting of two null bytes (the result of C<"\020\020"
301-
& "\101\101">) is not a false value in Perl. You need:
301+
Note that if any operand has a numeric value, perl uses numeric
302+
semantics (although you should not count on this):
302303

303-
if ( ("\020\020" & "\101\101") !~ /[^\000]/) {
304-
# ...
305-
}
304+
my($i, $j) = ( 11, 3 ); # $i & $j # 11 & 3 -> 3
305+
my($i, $j) = ("11", 3 ); # $i & $j # 11 & 3 -> 3
306+
my($i, $j) = ("11", "3"); # $i & $j # "11" & "3" -> 1
307+
308+
Remember that a perl scalar can have both string and numeric values at
309+
the same time. A value that starts as a string and has never encountered
310+
a numeric operation has no numeric value yet. Perl does this to save
311+
time and work so it doesn't have to decide a numeric value for a scalar
312+
it might never use as a number. In that case, string semantics wins. But,
313+
if there is a numeric value already, numeric semantics win. Force perl
314+
to compute the numeric value by adding 0:
315+
316+
my($i, $j) = ("11", "3"); $j += 0 # $i & $j # "11" & 3 -> 3
317+
318+
However, this is not a documented feature, or as L<perlop> says, it "is not
319+
well defined". One way to fix ensure numeric semantics is to explicitly
320+
convert both of values to numbers:
321+
322+
(0+$i) & (0+$j)
323+
324+
To fix this annoyance, Perl v5.22 separated the string and number
325+
behavior. The C<bitwise> feature introduced four new operators that
326+
would work with only string semantics: C<&.>, C<|.>, C<^.>, and C<~.>.
327+
The original operators, C<&>, C<|>, C<^>, and C<~>, would then apply
328+
only numeric semantics.
329+
330+
Enable this feature explicitly with L<feature>:
331+
332+
use feature qw(bitwise);
333+
334+
Or, as of v5.28, require the minimum version of perl with C<use>:
335+
336+
use v5.28; # bitwise feature for free
306337

307338
=head2 How do I multiply matrices?
308339

@@ -432,7 +463,7 @@ To get the day of year for any date, use L<POSIX>'s C<mktime> to get
432463
a time in epoch seconds for the argument to C<localtime>.
433464

434465
use POSIX qw/mktime strftime/;
435-
my $week_of_year = strftime "%W",
466+
my $week_of_year = strftime "%j",
436467
localtime( mktime( 0, 0, 0, 18, 11, 87 ) );
437468

438469
You can also use L<Time::Piece>, which comes with Perl and provides a
@@ -1365,8 +1396,8 @@ by a comma:
13651396
Since you're assigning to a scalar, the righthand side is in scalar
13661397
context. The comma operator (yes, it's an operator!) in scalar
13671398
context evaluates its lefthand side, throws away the result, and
1368-
evaluates it's righthand side and returns the result. In effect,
1369-
that list-lookalike assigns to C<$scalar> it's rightmost value. Many
1399+
evaluates its righthand side and returns the result. In effect,
1400+
that list-lookalike assigns to C<$scalar> its rightmost value. Many
13701401
people mess this up because they choose a list-lookalike whose
13711402
last element is also the count they expect:
13721403

@@ -2172,7 +2203,7 @@ This is very similar to "How do I process an entire hash?", also in
21722203
L<perlfaq4>, but a bit simpler in the common cases.
21732204

21742205
You can use the C<keys()> built-in function in scalar context to find out
2175-
have many entries you have in a hash:
2206+
how many entries you have in a hash:
21762207

21772208
my $key_count = keys %hash; # must be scalar context!
21782209

cpan/perlfaq/lib/perlfaq5.pod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ perlfaq5 - Files and Formats
44

55
=head1 VERSION
66

7-
version 5.20230701
7+
version 5.20230812
88

99
=head1 DESCRIPTION
1010

cpan/perlfaq/lib/perlfaq6.pod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ perlfaq6 - Regular Expressions
44

55
=head1 VERSION
66

7-
version 5.20230701
7+
version 5.20230812
88

99
=head1 DESCRIPTION
1010

cpan/perlfaq/lib/perlfaq7.pod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ perlfaq7 - General Perl Language Issues
44

55
=head1 VERSION
66

7-
version 5.20230701
7+
version 5.20230812
88

99
=head1 DESCRIPTION
1010

cpan/perlfaq/lib/perlfaq8.pod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ perlfaq8 - System Interaction
44

55
=head1 VERSION
66

7-
version 5.20230701
7+
version 5.20230812
88

99
=head1 DESCRIPTION
1010

cpan/perlfaq/lib/perlfaq9.pod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ perlfaq9 - Web, Email and Networking
44

55
=head1 VERSION
66

7-
version 5.20230701
7+
version 5.20230812
88

99
=head1 DESCRIPTION
1010

cpan/perlfaq/lib/perlglossary.pod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ perlglossary - Perl Glossary
77

88
=head1 VERSION
99

10-
version 5.20230701
10+
version 5.20230812
1111

1212
=head1 DESCRIPTION
1313

0 commit comments

Comments
 (0)