• Shaarli
  • Tag cloud
  • Picture wall
  • Daily
  • RSS
  • Login
4252 shaares
3 / 7
Filters
140 results tagged perl

Easy Data::Printer in the perl debugger | Chisel [blogs.perl.org]

QRCode

If you want to try it add the following to $HOME/.perldb:

$DB::alias{dp} = 's/dp/DB::dp/';
sub DB::dp {
    eval {
        require Data::Printer;
        Data::Printer->import(colored=>1,use_prototypes=>0);
    };
    if ($@=~/Can't locate/) {
        print 'Data::Printer is not installed';
        return;
    };
    print Data::Printer::p(@_);
}
http://blogs.perl.org/users/chisel/2012/03/easy-dataprinter-in-the-perl-debugger.html
March 17, 2021 at 10:40:10 AM EDT *
perl debugger
FILLER

Dist::Zilla::PluginBundle::Starter - A new way to start using Dist::Zilla - DEV Community

QRCode

Dist::Zilla is an extremely powerful and versatile CPAN authoring tool, which has enabled me to relia... Tagged with perl.

https://dev.to/grinnz/dist-zilla-pluginbundle-starter-a-new-way-to-start-using-dist-zilla-38m6
March 16, 2021 at 11:20:34 AM EDT *
perl cpan
FILLER

The Perl debugger can be your superpower - The Phoenix Trap

QRCode

What if I told you that you could freeze time in the middle of your program?

By far my favorite thing to do with the debugger is to run it against test scripts using the prove command. This takes advantage of prove’s ability to run an arbitrary interpreter through its test harness. Run it like this:

% prove --verbose --lib --exec 'perl -Ilib -d' t/foo.t

https://phoenixtrap.com/2021/03/09/perl-debugger-superpower/
March 16, 2021 at 11:19:31 AM EDT *
perl cpan
FILLER

IPC::Cmd considered harmful - ETOOBUSY

QRCode

Recently, I had to do some command-line invocations from Perl. Well, let’s see what we have at our disposal then…

  • system is fine, but too limited. E.g. it does not allow grabbing the output of a command, which I might need;
  • qx is a joke from the past. I mean, not having a list-oriented alternative and forcing the user to do (and possibly forget) quotemeta is something I can’t bear in 2021;
  • IPC::Open2 and IPC::Open3 are in CORE but require some effort to be used, which I’d like to avoid;
  • IPC::Cmd seems interesting, because it’s in CORE and its run_forked seems to hit the sweet spot: it supports providing the command as an array reference, has a bunch of options and provides back everything that’s needed;
  • IPC::Run, IPC::Run3, insert your favourite module here all seem very interesting and flexible, but they are not in CORE and are probably overkill in my case.

Well then, we’re done! IPC::Cmd’s run_forked for the win… right?!?

Well… not so fast.

https://www.reddit.com/r/perl/comments/lu39cy/ipccmd_considered_harmful/

https://github.polettix.it/ETOOBUSY/2021/02/27/ipc-cmd-considered-harmful/
March 9, 2021 at 10:20:21 AM EST *
perl
FILLER

Perl Advent Calendar 2020 - There is No Try

QRCode

eval Stinks!

Even if not a huge increase in the code needed for the operation, it's a bunch of magic to remember every time. If you don't do this sort of thing, though, you've got a big opening for horrible error-handling problems.

use Try::Tiny;

my $start = Time::HiRes::time;

return try {
  $self->computation_helper->compute_stuff;
} catch {
  my $error = $_ eq '' ? 'unknown error' : "$_";
  $self->set_last_error( "couldn't get stuff computed: $error" );
  return undef;
} finally {
  my $failed = @_;
  my $end  = Time::HiRes::time;
  warn sprintf "took %f seconds to %s",
    $end - $start,
    $failed ? 'fail' : 'succeed';
};
http://perladvent.org/2020/2020-12-03.html
January 6, 2021 at 2:55:14 PM EST *
perl
FILLER

Interpolating Functions and Expressions Within Strings - Perl Cookbook [Book]

QRCode

Interpolating Functions and Expressions Within Strings Problem You want a function call or expression to expand within a string. This lets you construct more complex templates than with simple scalar … - Selection from Perl Cookbook [Book]

Or you can use the slightly sneaky @{[ LIST EXPR ]} or ${ (SCALAR EXPR ) } expansions:

$answer = "STRING @{[ LIST EXPR ]} MORE STRING";
$answer = "STRING ${\( SCALAR EXPR )} MORE STRING";
https://www.oreilly.com/library/view/perl-cookbook/1565922433/ch01s11.html
December 31, 2020 at 10:33:36 AM EST *
perl
FILLER

Perl do

QRCode

Basically after calling do $filename; we need to check both $! and $@ and verify that both are empty as either one of them can contain an error.

https://perlmaven.com/do
December 14, 2020 at 9:15:20 AM EST *
perl
FILLER

Modern Perl CGI | Aristotle [blogs.perl.org]

QRCode

A modernisation of this using Plack is straightforwardly equivalent:

#!/usr/bin/env perl
use strict;
use warnings;
use Plack::Request;
use Encode::Simple;
use JSON::MaybeXS;

my $app = sub {
    my $req = Plack::Request->new($_[0]);
    my $input = eval { decode 'UTF-8', $req->parameters->{'input'} };
    [ 200, [ 'Content-Type', 'application/json; charset=UTF-8' ], [ encode_json { output => uc $input } ] ];
};

This is now a full PSGI app and as such gains all the same additional deployment options of the Mojolicious example. To deploy it as a CGI script you add this line at the bottom:

use Plack::Handler::CGI; Plack::Handler::CGI->new->run($app);

In all it takes about twice as long to load as the CGI.pm example, compared to the Mojolicious example taking about 7× as long. In exchange you get all the benefits of the PSGI ecosystem – without losing any of the strengths of deploying as a CGI script, unlike the Mojolicious example.

http://blogs.perl.org/users/aristotle/2018/11/modern-perl-cgi.html
July 2, 2020 at 10:48:23 AM EDT *
perl cgi plack mojolicious psgi
FILLER

Modern Perl toolchain for Git managed web apps | kappataumu.com

QRCode

But this also trickles down inside VMs. Working with Linux, i’ve found that keeping the system as pristine as possible after installation is a good thing. When working with Perl, I set the following objectives:

  1. Leave the system Perl alone.
  2. Install any Perl I choose.
    • And even switch between installed Perls
    • Either globally or on a per-project page
  3. Manage Perl module dependencies within the project’s git repo.
https://kappataumu.com/articles/modern-perl-toolchain-for-web-apps.html
March 13, 2020 at 3:24:41 PM EDT *
perl
FILLER

The Wisdom of TAP Numbering in a JavaScript World – Wumpus Cave

QRCode

Avoiding a test count seems to be the trend in Perl modules these days. After all, automated test libraries in other languages don’t have anything similar, and they seem to get by fine. If the test fails in the middle, that can be detected by a non-zero exit code. It’s always felt like annoying bookkeeping, so why bother?

For simple tests like the above, I think that’s fine. Failing with a non-zero exit code has worked reliably for me in the past.

However, there’s one place where I think TAP had the right idea way back in 1988: event driven or otherwise asynchronous code. Systems like this have been popping up in Perl over the years, but naturally, it’s Node.js that has built an entire ecosystem around the concept. Here’s one of my tests that uses a callback system:

http://www.wumpus-cave.net/2019/08/26/the-wisdom-of-tap-numbering-in-a-javascript-world/
February 17, 2020 at 10:13:04 AM EST *
nodejs testing perl
FILLER

Perl Advent Calendar 2019 - Memories of Past Lives

QRCode

Persisting between program runs
This is all very well, but Memoize uses an in memory cache. Jolly's problem is that each time he runs his code his program has to re-do all the work up until the point that it crashes. Using memoize like above won't speed up his code at all as every time the script runs it starts with a fresh empty cache.

What we need to do is what the Wise Old Elf suggested - persist our results between program runs.

Well, Memoize can do that:

http://www.perladvent.org/2019/2019-12-19.html
December 30, 2019 at 2:45:18 PM EST *
memoize perl
FILLER

Perl Advent Calendar 2019 - We Wish You a Meme Christmas

QRCode

Imager is a handy dandy image drawing library in Perl that we're going to be using for our Meme creation needs.

Imager has about a gazillion methods to do pretty much every standard graphics manipulation you can imagine. But, shockingly, it doesn't have a way to draw standard meme text (Impact font, white text, black outline.) We can fix that by adding our own plugin:

http://www.perladvent.org/2019/2019-12-24.html
December 30, 2019 at 2:40:52 PM EST *
perl meme
FILLER

json - "Fatal error: 'EXTERN.h' file not found" while installing Perl modules - Stack Overflow

QRCode

First, do not use the system Perl on MacOS. The installed version is for Apple, not for you

The best practice seems to be starting with a Perl using brew install perl and work in this environment, remembering to setup your bash_profile as directed by the installer.

Also worth remembering to do a brew link perl. If you receive warnings about this clobbering what looks like system Perl libraries don't worry - these are likely modules that were installed by you over the top and it will cause you less trouble to link over these. If you have concerns, make a note of which module installs will be cleared and re-install them once your environment is configured ( ie your module installer approach is configured using cpanm or sticking with the old perl -MCPAN -e shell etc)

(Other languages like Ruby have the same issue)

https://stackoverflow.com/questions/52682304/fatal-error-extern-h-file-not-found-while-installing-perl-modules
October 3, 2019 at 2:34:04 PM EDT *
perl macos
FILLER

A Perl getopts example | alvinalexander.com

QRCode

Perl getopts FAQ: Can you demonstrate how to use the getopts function? (Also written as, "Can you demonstrate how to read Perl command line arguments?")

http://alvinalexander.com/perl/perl-getopts-command-line-options-flags-in-perl
August 21, 2019 at 10:46:18 AM EDT *
perl
FILLER

App::Stacktrace - Stack trace - metacpan.org

QRCode

perl-stacktrace prints Perl stack traces of Perl threads for a given Perl process. For each Perl frame, the full file name and line number are printed.

https://metacpan.org/pod/App::Stacktrace
July 8, 2019 at 11:15:01 AM EDT *
perl debugger linux
FILLER

David Golden - "Taking Perl to Eleven with Higher-Order Functions"

QRCode
# Transformation helper function
sub _x {
  my $v = shift;
  my $is_code = ref($v) eq 'CODE';
  return $is_code ? $v->() : $v; # What about arguments to $v??
}

Data::Fake

https://www.youtube.com/watch?v=USF4BHMFKbg
July 3, 2019 at 1:52:05 PM EDT *
perl
FILLER

Lookahead and Lookbehind Tutorial—Tips &Tricks

QRCode

Lookarounds often cause confusion to the regex apprentice. I believe this confusion promptly disappears if one simple point is firmly grasped. It is that at the end of a lookahead or a lookbehind, the regex engine hasn't moved on the string. You can chain three more lookaheads after the first, and the regex engine still won't move. In fact, that's a useful technique.

https://www.rexegg.com/regex-lookarounds.html
June 14, 2019 at 1:45:16 PM EDT *
perl regex
FILLER

Deploying Perl Apps using Docker, Gitlab & Kubernetes

QRCode

German Perl Workshop 2019 München 2019-03-06
Thomas Klausner

https://domm.plix.at/talks/2019_munich_perl_docker_gitlab_kubernetes/index.html
April 26, 2019 at 9:53:31 AM EDT *
perl docker
FILLER

Moose is Perl: a guide to the new revolution | YouTube

QRCode

Ricardo Signes at Oscon - July 20-24, 2014

https://www.youtube.com/watch?v=LKXvG6VKew4
April 11, 2019 at 11:27:46 AM EDT *
perl moose
FILLER

Fork yeah!

QRCode

Recently at work I had to speed up a Perl script that processed files. Perl can spawn multiple processes with the fork function, but things can go awry unless you manage the subprocesses correctly. I adding forking to the script and was able to improve the script’s throughput rate nearly 10x, but it took me a few attempts to get it right. In this article I’m going to show you how to use fork safely and avoid some common mistakes.

https://www.perl.com/article/fork-yeah-/
April 5, 2019 at 9:13:56 AM EDT *
perl programming
FILLER
3 / 7
Shaarli · The personal, minimalist, super fast, database-free, bookmarking service by the Shaarli community · Documentation
Fold Fold all Expand Expand all Are you sure you want to delete this link? Are you sure you want to delete this tag? The personal, minimalist, super fast, database-free, bookmarking service by the Shaarli community