in reply to Re: How to find Perl demo programs?
in thread How to find Perl demo programs?

Well, I know the documentation exists, but it does not have sufficient example programs in it. For example, let me show you what I mean. This page talks about the chr() function: https://perldoc.perl.org/functions/chr but if you open it, there is no example program. This is what I would expect an example program to look like:

#!/usr/bin/perl use strict; use warnings; print 'A'; # Prints 'A' print chr(65); # Prints 'A' my $c = 65; print chr($c); # Prints 'A' $_ = 65; print chr; # Prints 'A'

An example program or demo program is something that you can just copy and paste, and it works. And it shows you what one particular keyword or function can do and how it's used. The functions are described in the documentation in pretty good detail, but a working example is usually missing.

But thank you, I will study the GitHub link you provided. It looks like it might be what I am looking for, although it's quite messy.

Replies are listed 'Best First'.
Re^3: How to find Perl demo programs?
by kcott (Archbishop) on May 21, 2023 at 10:18 UTC
    This is what I would expect an example program to look like:
    #!/usr/bin/perl use strict; use warnings; print 'A'; # Prints 'A' print chr(65); # Prints 'A' my $c = 65; print chr($c); # Prints 'A' $_ = 65; print chr; # Prints 'A'

    I'll assume that you've successfully tested that on your system; however, consider:

    • Not all systems have /usr/bin/perl.
    • chr() does not require the strict pragma.
    • chr() works on versions of Perl5 prior to the introduction of the warnings pragma.
    • A variable, supplied as an argument to chr(), does not need to be lexical.

    So, as you can probably see, there's no one-size-fits-all example. Providing explanations and code fragments is likely to be suitable for a wider audience; even then, many pages require links to perlport or other caveats.

    "I will study the GitHub link ... although it's quite messy."

    Well, I didn't have any trouble finding the chr() tests for the latest stable release, https://github.com/Perl/perl5/blob/v5.36.1/t/op/chr.t, or those from over a decade ago, https://github.com/Perl/perl5/blob/v5.16.0/t/op/chr.t.

    At the end of the day, if you're really struggling with using some function, ask here: we're always happy to help. I would request that you restrict your questions to a single function or related group of functions; listing every operator and function that you can find is just off-putting — many who could otherwise provide insightful responses may simply move on to the next question.

    — Ken