diff options
author | Karen Etheridge <ether@cpan.org> | 2021-04-10 17:49:24 -0700 |
---|---|---|
committer | Karen Etheridge <ether@cpan.org> | 2021-04-10 19:48:33 -0700 |
commit | fa88ae8ef84c6386a43eef48f18326b51eecce55 (patch) | |
tree | 72cab62cf28d1f67ab7ca92381a94f560137876c /cpan | |
parent | 12c68733611a690880d3f4621d10c9110b8ac7e4 (diff) | |
download | perl-fa88ae8ef84c6386a43eef48f18326b51eecce55.tar.gz |
Update perlfaq to CPAN version 5.20200523
[DELTA]
5.20210411 2021-04-11 00:45:30Z
* Add entry to faq4 for equivalent to ruby #{}, python fstring
(PR#93, John Karr)
Diffstat (limited to 'cpan')
-rw-r--r-- | cpan/perlfaq/lib/perlfaq.pm | 2 | ||||
-rw-r--r-- | cpan/perlfaq/lib/perlfaq.pod | 6 | ||||
-rw-r--r-- | cpan/perlfaq/lib/perlfaq1.pod | 2 | ||||
-rw-r--r-- | cpan/perlfaq/lib/perlfaq2.pod | 2 | ||||
-rw-r--r-- | cpan/perlfaq/lib/perlfaq3.pod | 2 | ||||
-rw-r--r-- | cpan/perlfaq/lib/perlfaq4.pod | 49 | ||||
-rw-r--r-- | cpan/perlfaq/lib/perlfaq5.pod | 2 | ||||
-rw-r--r-- | cpan/perlfaq/lib/perlfaq6.pod | 2 | ||||
-rw-r--r-- | cpan/perlfaq/lib/perlfaq7.pod | 2 | ||||
-rw-r--r-- | cpan/perlfaq/lib/perlfaq8.pod | 2 | ||||
-rw-r--r-- | cpan/perlfaq/lib/perlfaq9.pod | 2 | ||||
-rw-r--r-- | cpan/perlfaq/lib/perlglossary.pod | 2 |
12 files changed, 63 insertions, 12 deletions
diff --git a/cpan/perlfaq/lib/perlfaq.pm b/cpan/perlfaq/lib/perlfaq.pm index 3dd5421987..dcb5ea730b 100644 --- a/cpan/perlfaq/lib/perlfaq.pm +++ b/cpan/perlfaq/lib/perlfaq.pm @@ -2,6 +2,6 @@ use strict; use warnings; package perlfaq; -our $VERSION = '5.20201107'; +our $VERSION = '5.20210411'; 1; diff --git a/cpan/perlfaq/lib/perlfaq.pod b/cpan/perlfaq/lib/perlfaq.pod index de114be28a..bef9aa466e 100644 --- a/cpan/perlfaq/lib/perlfaq.pod +++ b/cpan/perlfaq/lib/perlfaq.pod @@ -4,7 +4,7 @@ perlfaq - Frequently asked questions about Perl =head1 VERSION -version 5.20201107 +version 5.20210411 =head1 DESCRIPTION @@ -475,6 +475,10 @@ How can I expand variables in text strings? =item * +Does Perl have anything like Ruby's #{} or Python's f string? + +=item * + What's wrong with always quoting "$vars"? =item * diff --git a/cpan/perlfaq/lib/perlfaq1.pod b/cpan/perlfaq/lib/perlfaq1.pod index e8ecaffe3b..e4dd3d9651 100644 --- a/cpan/perlfaq/lib/perlfaq1.pod +++ b/cpan/perlfaq/lib/perlfaq1.pod @@ -4,7 +4,7 @@ perlfaq1 - General Questions About Perl =head1 VERSION -version 5.20201107 +version 5.20210411 =head1 DESCRIPTION diff --git a/cpan/perlfaq/lib/perlfaq2.pod b/cpan/perlfaq/lib/perlfaq2.pod index 614aac9190..d4cc9f8b27 100644 --- a/cpan/perlfaq/lib/perlfaq2.pod +++ b/cpan/perlfaq/lib/perlfaq2.pod @@ -4,7 +4,7 @@ perlfaq2 - Obtaining and Learning about Perl =head1 VERSION -version 5.20201107 +version 5.20210411 =head1 DESCRIPTION diff --git a/cpan/perlfaq/lib/perlfaq3.pod b/cpan/perlfaq/lib/perlfaq3.pod index 017ab38afb..b5a6fd7a03 100644 --- a/cpan/perlfaq/lib/perlfaq3.pod +++ b/cpan/perlfaq/lib/perlfaq3.pod @@ -4,7 +4,7 @@ perlfaq3 - Programming Tools =head1 VERSION -version 5.20201107 +version 5.20210411 =head1 DESCRIPTION diff --git a/cpan/perlfaq/lib/perlfaq4.pod b/cpan/perlfaq/lib/perlfaq4.pod index 3645a1489d..82072e2a59 100644 --- a/cpan/perlfaq/lib/perlfaq4.pod +++ b/cpan/perlfaq/lib/perlfaq4.pod @@ -4,7 +4,7 @@ perlfaq4 - Data Manipulation =head1 VERSION -version 5.20201107 +version 5.20210411 =head1 DESCRIPTION @@ -1120,6 +1120,53 @@ signal that I missed something: print $string; + +=head2 Does Perl have anything like Ruby's #{} or Python's f string? + +Unlike the others, Perl allows you to embed a variable naked in a double +quoted string, e.g. C<"variable $variable">. When there isn't whitespace or +other non-word characters following the variable name, you can add braces +(e.g. C<"foo ${foo}bar">) to ensure correct parsing. + +An array can also be embedded directly in a string, and will be expanded +by default with spaces between the elements. The default +L<LIST_SEPARATOR|perlvar/$LIST_SEPARATOR> can be changed by assigning a +different string to the special variable C<$">, such as C<local $" = ', ';>. + +Perl also supports references within a string providing the equivalent of +the features in the other two languages. + +C<${\ ... }> embedded within a string will work for most simple statements +such as an object->method call. More complex code can be wrapped in a do +block C<${\ do{...} }>. + +When you want a list to be expanded per C<$">, use C<@{[ ... ]}>. + + use Time::Piece; + use Time::Seconds; + my $scalar = 'STRING'; + my @array = ( 'zorro', 'a', 1, 'B', 3 ); + + # Print the current date and time and then Tommorrow + my $t = Time::Piece->new; + say "Now is: ${\ $t->cdate() }"; + say "Tomorrow: ${\ do{ my $T=Time::Piece->new + ONE_DAY ; $T->fullday }}"; + + # some variables in strings + say "This is some scalar I have $scalar, this is an array @array."; + say "You can also write it like this ${scalar} @{array}."; + + # Change the $LIST_SEPARATOR + local $" = ':'; + say "Set \$\" to delimit with ':' and sort the Array @{[ sort @array ]}"; + +You may also want to look at the module +L<Quote::Code>, and templating tools such as L<Template::Toolkit> and +L<Mojo::Template>. + +See also: L</"How can I expand variables in text strings?"> and +L</"How do I expand function calls in a string?"> in this FAQ. + =head2 What's wrong with always quoting "$vars"? The problem is that those double-quotes force diff --git a/cpan/perlfaq/lib/perlfaq5.pod b/cpan/perlfaq/lib/perlfaq5.pod index 81a44d804b..859134fad7 100644 --- a/cpan/perlfaq/lib/perlfaq5.pod +++ b/cpan/perlfaq/lib/perlfaq5.pod @@ -4,7 +4,7 @@ perlfaq5 - Files and Formats =head1 VERSION -version 5.20201107 +version 5.20210411 =head1 DESCRIPTION diff --git a/cpan/perlfaq/lib/perlfaq6.pod b/cpan/perlfaq/lib/perlfaq6.pod index 6b33321190..d7fe1ca2c6 100644 --- a/cpan/perlfaq/lib/perlfaq6.pod +++ b/cpan/perlfaq/lib/perlfaq6.pod @@ -4,7 +4,7 @@ perlfaq6 - Regular Expressions =head1 VERSION -version 5.20201107 +version 5.20210411 =head1 DESCRIPTION diff --git a/cpan/perlfaq/lib/perlfaq7.pod b/cpan/perlfaq/lib/perlfaq7.pod index 0ad703ec90..1790bdc0ef 100644 --- a/cpan/perlfaq/lib/perlfaq7.pod +++ b/cpan/perlfaq/lib/perlfaq7.pod @@ -4,7 +4,7 @@ perlfaq7 - General Perl Language Issues =head1 VERSION -version 5.20201107 +version 5.20210411 =head1 DESCRIPTION diff --git a/cpan/perlfaq/lib/perlfaq8.pod b/cpan/perlfaq/lib/perlfaq8.pod index d19235052a..e2ab7013bc 100644 --- a/cpan/perlfaq/lib/perlfaq8.pod +++ b/cpan/perlfaq/lib/perlfaq8.pod @@ -4,7 +4,7 @@ perlfaq8 - System Interaction =head1 VERSION -version 5.20201107 +version 5.20210411 =head1 DESCRIPTION diff --git a/cpan/perlfaq/lib/perlfaq9.pod b/cpan/perlfaq/lib/perlfaq9.pod index 0e23935160..47fc0c5af0 100644 --- a/cpan/perlfaq/lib/perlfaq9.pod +++ b/cpan/perlfaq/lib/perlfaq9.pod @@ -4,7 +4,7 @@ perlfaq9 - Web, Email and Networking =head1 VERSION -version 5.20201107 +version 5.20210411 =head1 DESCRIPTION diff --git a/cpan/perlfaq/lib/perlglossary.pod b/cpan/perlfaq/lib/perlglossary.pod index d2b54c6fa6..23e7192b88 100644 --- a/cpan/perlfaq/lib/perlglossary.pod +++ b/cpan/perlfaq/lib/perlglossary.pod @@ -7,7 +7,7 @@ perlglossary - Perl Glossary =head1 VERSION -version 5.20201107 +version 5.20210411 =head1 DESCRIPTION |