in reply to How to find Perl demo programs?

G'day harangzsolt33,

"Is there a website that explains what each builtin function does ..."

Yes: https://perldoc.perl.org/perl.

"... and how to use it with a little demo program that one can test?"

Most of the entries in perldoc have examples (or links to other manpages with examples).

If you're looking for specific tests, try https://github.com/Perl/perl5. You can pick a specific branch or tag. The default is "blead" but, let's say you wanted the latest stable release (at the time of writing), you'd pick the v5.36.1 tag and get https://github.com/Perl/perl5/tree/v5.36.1. From here you can select the "t" directory where you'll find all of tests: check the README and drill down into subdirectories for specific tests.

"I copied all the functions from perldoc ..."

Perhaps you need to be more specific. To me, that means you looked in https://perldoc.perl.org/functions; however, if you'd done that, you wouldn't be asking where to find function documentation.

There's also a Search function in the top-righthand corner of https://perldoc.perl.org/perl.

— Ken

Replies are listed 'Best First'.
Re^2: How to find Perl demo programs?
by harangzsolt33 (Deacon) on May 21, 2023 at 04:48 UTC
    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.

      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