#perl

perlbrew installation and usage

Installation

Copy & paste this line into your terminal.

\curl -L https://install.perlbrew.pl | bash

Then, execute following line:

echo "source ~/perl5/perlbrew/etc/bashrc" >> ~/.profile

Then, open new shell and you can start working with perlbrew in there.

All files will be installed in ~/perl5/perlbrew/, and it will use that directory and subdirectories.

Basic usage

Get a list of available perls you can use:

perlbrew available

Install some version of perl:

perlbrew install perl-5.36.1

It will compile that perl version and install it within ~/perl5/perlbrew/ subdirectory.

It will take some time (around 21 minutes at my laptop), and it will take 324M of disk space.

Now you can list all installed perl versions:

perlbrew list

To switch to specific version you can use command switch:

perlbrew switch perl-5.36.1

To execute the script with another version of perl, but not switching to it completely:

perlbrew exec --with perl-5.40.0 perl myprogram.pl

To run the script with specific version of perl from cron, use the following:

* * * * * PERLBREW_ROOT=$HOME/perl5/ ~/perl5/perlbrew/bin/perlbrew exec --with perl-5.36.1 ~/myprogram.pl

For more on cron tips, see: http://johnbokma.com/blog/2019/03/08/running-a-perl-program-via-cron.html

To return back to system perl version, you can switch it off:

perlbrew switch-off

For additional help:

perlbrew -h
perlbrew help

See more: https://perlbrew.pl/

See also: https://github.com/tokuhirom/plenv

Bookmarked Ryan Voots [blogs.perl.org] (blogs.perl.org)

A while back I bought the https://perl.social/ domain without much immediate use for it.... ... I started setting up an activitypub based network to take the place of the twitter community in the advent that there was an exodus of Perl programmers from twitter. That seems to have been happening so I finally kicked into gear to get it ready for use.

"https://perl.social/ should show you the public face of the community, (if it doesn't let me know). In the upper right you'll find the login button, and can register a new user. Once registered, like all fediverse things you'll be able to be followed by people as such @username@perl.social and can follow other users on other servers by putting them in the search box at the top and then following them." - Ryan Voots

_postfile
content
> A while back I bought the https://perl.social/ domain without much immediate use for it.... > ... I started setting up an activitypub based network to take the place of the twitter community in the advent that there was an exodus of Perl programmers from twitter. That seems to have been happening so I finally kicked into gear to get it ready for use. > > "https://perl.social/ should show you the public face of the community, (if it doesn't let me know). > In the upper right you'll find the login button, and can register a new user. > Once registered, like all fediverse things you'll be able to be followed by people as such @username@perl.social and can follow other users on other servers by putting them in the search box at the top and then following them." > - Ryan Voots
date
1671408712
day
19
description
> A while back I bought the https://perl.social/ domain without much immediate use for it.... > ... I started setting up an activitypub based network to take the place of the twitter community in the advent that there was an exodus of Perl programmers from twitter. That seems to have been happening so I finally kicked into gear to get it ready for use. > > "https://perl.social/ should show you the public face of the community, (if it doesn't let me know). > In the upper right you'll find the login button, and can register a new user. > Once registered, like all fediverse things you'll be able to be followed by people as such @username@perl.social and can follow other users on other servers by putting them in the search box at the top and then following them." > - Ryan Voots
domain
blogs.perl.org
filename
2022-12-19-01:11:52.md
filepath
bookmarks
hour
01
link
https://blogs.perl.org/users/ryan_voots/2022/12/perl-fediverse-network.html
minute
11
minutes_to_read
1
month
12
month_name
December
next
HASH(0x56026edd5ca8)
prev
HASH(0x56026ede0d18)
second
52
slug
01:11:52
sourcedir
posts/bookmarks/
tags
bookmarks, perl, fediverse, mastodon
title
Ryan Voots [blogs.perl.org]
type
bookmark
url
/bookmarks/2022/12/19/011152/
url_name
index.html
url_path
/bookmarks/2022/12/19/011152
year
2022

How to run perl from index.php

Sometimes you need to run a simple perl script, but your webhosting is configured to look for index.php only. Here is the way to get it through:

Edit index.php

<?php
foreach ($_SERVER as $key => $value) { putenv("$key=$value"); }
foreach ($_GET as $key => $value)    { putenv("GET_$key=".escapeshellarg($value)); }
foreach ($_POST as $key => $value)   { putenv("POST_$key=".escapeshellarg($value)); }

echo shell_exec('perl index.pl 2>&1');

Create your index.pl

#!/usr/bin/perl

use Data::Dumper; $Data::Dumper::Sortkeys = 1;

print "Done.\n";

print Dumper( \@INC );
print Dumper( \%ENV );

Conclusion

All $_GET variables will be in GET_xxx environment variables.

All $_POST variables will be in POST_xxx environment variables.

ALL $_SERVER variables will be set as CGI environment variables.

This is 'out of head' document. It should be tested.

That's all.

How to use perl script with nginx

Sometimes you need to run a simple perl script, without a need to create a full perl web app. The easiest way is to use it using nginx+fcgiwrapper.

Install required software

apt intall nginx
apt install fcgiwrap

Configure nginx

/etc/nginx/sites-enabled/test.com.conf

location ~ \.pl$ {
  try_files $uri =404; # without this, we will get '403 Forbidden'
  fastcgi_param SCRIPT_NAME $fastcgi_script_name;
  fastcgi_pass unix:/var/run/fcgiwrap.socket;
  include fastcgi_params;

  # run it immediately, without buffering ....
  fastcgi_param NO_BUFFERING "1";
  fastcgi_keep_conn on;
}

Note:

Files .pl MUST BE in the path accessible by the nginx.

Buffering is active per-default. With current installation on Ubuntu, there is no way to disable buffering and enable streaming.

Example:

#!/usr/bin/perl

use strict;
use warnings;

# To enable buffering:
$|=1;
# tell browser, not to wait for content...
print "Content-Encoding: none\n";
print "Content-Type: text/html; charset=ISO-8859-1;\n";
print "\n\n";

print "<h1>Perl is working!</h1>\n";
sleep 1;
print "test2<br>\n";
sleep 2;
print "test3<br>\n";
sleep 3;
print "test4<br>\n";

Tested on:

  • system1:

    Ubuntu 20.04.1 LTS

    apt show fcgiwrap

    Version: 1.1.0-12

All Articles Bookmarks