|
New here? ⇒ I want to ask a question of the Perl Monks. Where do I start?
Notices:
| • erzuuli | ‥ Anonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots. |
If you're new here, please read PerlMonks FAQ and Create a new user!
|
Perl News
|
Call for Papers! - Perl Community Conference, Summer 2025
on May 10, 2025 at 22:41
|
0 replies
|
by oodler
|
This is a hybrid (in-person and virtual) conference being held in Austin, TX on July 3rd-4th.
Did you miss your chance to speak or wish to speak at the only available Perl Science Track (and get published in the Science Perl Journal)? Or maybe you just can't get enough Perl this summer??? Read on ...
The following lengths will be accepted for publication and presentation:
- Science Perl Track: Full-length paper (10-36 pages, 50-minute speaker slot)
- Science Perl Track: Short paper (2-9 pages, 20-minute speaker slot)
- Science Perl Track: Extended Abstract (1 page, 5-minute lightning talk slot)
- Normal Perl Track (45-minute speaker slot, no paper required)
Don’t wait! Submit a paper or talk today. All published authors will be presenting their papers at this hybrid (in-person and virtual) 2-day conference being held on July 3-4, 2025 in Austin, TX; and attendance will be free for everyone, but you must be registered and donations are kindly appreciated.
Also posted at at BPO: https://blogs.perl.org/users/oodler_577/2025/05/call-for-papers---perl-community-conference-summer-2025.html and at l'reddit's: r/perlcommunity.
|
Toronto Perl Mongers presented - Dave Cross: Still Data Munging with Perl
on Apr 14, 2025 at 13:35
|
0 replies
|
by talexb
|
Olaf Alders arranged to have Dave Cross come speak at a meeting of the Toronto Perl Mongers recently, and the video has now been posted on the TPRF channel. Here's the link to the Youtube video: link
Update: Made the URL into a link. And how long have you been visiting this site? Goof.
Alex / talexb / Toronto
For a long time, I had a link in my .sig going to Groklaw. I heard that as of December 2024, this link is dead. Still, thanks to PJ for all your work, we owe you so much. RIP Groklaw -- 2003 to 2013.
|
|
|
Supplications
|
Speed comparison of foreach vs grep + map
6 direct replies — Read more / Contribute
|
by mldvx4
on May 25, 2025 at 13:57
|
|
|
Greetings, PerlMonks!
I'm trying to figure out if foreach is faster than grep with map. I've replaced grep and map in a large script with foreach and noticed a substantial speed improvement, so my guess is that it is faster. However, I'd like to verify that somehow.
With the two scripts below, am I comparing the same things and not apple to oranges? Or have I misunderstood grep and map?
#!/usr/bin/perl
use strict;
use warnings;
my @c = (1 .. 10000000);
my @d;
foreach my $dd (@c) {
push(@d, $dd % 2);
}
my @e;
foreach my $ee (@d) {
if (!$ee) {
push(@e, $ee);
}
}
exit(0);
The script above is much faster than the one below, according to time.
#!/usr/bin/perl
use strict;
use warnings;
my @c = (1 .. 10000000);
my @d = map( $_%2, @c);
my @e = grep(/0/, @d);
exit(0);
|
Race when redirecting output.
1 direct reply — Read more / Contribute
|
by gnosti
on May 21, 2025 at 17:49
|
|
|
Experienced Monks!
I have a command-line app that parses commands and prints the output to the terminal. In search of new features, I'm migrating the terminal library from readline to tickit.
To simplify this changeover, my plan is to use open and select to direct the default output filehandle to a $variable, and then periodically dump the contents of $variable to a tickit widget.
I'm close, but my naive implementation loses every other line of output. Seems like I need to away to ensure that writes to $command_output are held up while printing and then deleting the contained text. Some kind of first-in-last-out buffer with synchronization.
Will be grateful for any hints on an easy way to accomplish this. Here is sample code demonstrating my conundrum:
|
Perl Expect Help
3 direct replies — Read more / Contribute
|
by Anonymous Monk
on May 21, 2025 at 16:01
|
|
|
I am having a problem with understanding expect. I have am trying to create an shh script. I have 3 different conditions:
- host is unknown it needs to be added to known host list,
- host needs password,
- host dose not need password as it is using ssh key.
$exp->expect($timeout,
[ qr/\(yes\/no\)\?/i, sub { my $self = shift;
$self->send("yes\r"); <----unk
+nown host
exp_continue; }],
[ qr/password: /i, sub { my $self = shift;
$self->send("$password\n"); <---
+--- needs password
exp_continue; }],
[ qr/#/i, sub { my $self = shift; <------
+-- ready to go.
$self->send("ls\n");
;
}],
);
So how do I, once I get through the 3 conditions continue using expect?
$exp->expect($timeout,
[ qr/#/i, sub { my $self = shift;
$self->send("ll\n"); <---- only
+ works when I have a line below (crazy that is how I know this is not
+ right)
;
}], un
+less ($exp->expect($timeout, -re , "~")){} ;
);
What I would like is to get past the three different ssh scenarios and keep going on.
#!/usr/bin/env perl
use strict;
use warnings;
use Expect;
#$Expect::Exp_Internal = 1;
my $command = "ssh";
my $user = "root";
my @ips = ("10.16.135.157");
my $cnt= 0+@ips;
my $password = "aristo1";
my $timeout = 10;
for (my $i =0; $i < $cnt; $i++) {
my $exp = Expect->spawn ($command, "$user"."@"."$ips[$i]");
#$exp->debug(2);
$exp->expect($timeout,
[ qr/\(yes\/no\)\?/i, sub { my $self = shift;
$self->send("yes\r");
exp_continue; }],
[ qr/password: /i, sub { my $self = shift;
$self->send("$password\n");
exp_continue; }],
[ qr/#/i, sub { my $self = shift;
$self->send("ls\n");
;
}],
);
$exp->expect($timeout,
[ qr/#/i, sub { my $self = shift;
$self->send("ll\n");
;
}],
);
unless ($exp->expect($timeout, -re , "~")){} ;
# $exp->send("time\n");
}
|
PLS (Perl Language Server) renaming support in NVIM
1 direct reply — Read more / Contribute
|
by igoryonya
on May 21, 2025 at 04:36
|
|
|
Hello, I've installed https://metacpan.org/dist/PLS module.
Configured it in NVIM with https://github.com/neovim/nvim-lspconfig plugin.
Auto completions work. It even shows documentation excerpts, when cursor is over some keyword or library module, but out of all issues, my biggest problem is that Language Server's renaming doesn't work.
When I try to rename some function or a variable, it gives me an error:
'[LSP] Rename, no matching language servers with rename capability.'
Does anybody know, if perl Language servers don't support such functionality or did I configure something wrong?
|
Dancer2 App Deployment through Apache Proxy
2 direct replies — Read more / Contribute
|
by choroba
on May 20, 2025 at 11:53
|
|
|
I wrote a Dancer2 application to be used by about 10 people from work. It ran fine on http://localhost, but the pages needed to be available from the outside world. Our IT admin told me the standard practice is to run it on a virtual host and use Apache's mod_proxy.
Dancer2::Manual::Deployment even mentions such a possibility, so I followed the instructions. I included
behind_proxy: 1
to config.yml, and the admin configured the proxy similarly as shown in the manual (see Using-Apache's-mod_proxy of Dancer2::Manual::Deployment.
I was given a prefix under which the app would be running, e.g. https://example.com/prefix/login.
But it doesn't work correctly. For example, the css files are ignored. Or rather, they can't be found.
The main.tt template was created with the following link (part of the initial scaffolding):
<link rel="stylesheet" href="<% request.uri_base %>/css/style.css">
But the request.uri_base doesn't expand to /prefix, it remains empty.
Similarly, I use Dancer2::Plugin::Auth::Tiny for user authentication. Again, I almost copied verbatim the synopsis code:
get '/' => needs login => sub {
# ...
};
get '/login' => sub {
template 'login'
};
post '/login' => sub {
my $user = body_parameters->get('uname');
if (is_valid($user, body_parameters->get('psw'))) {
session(user => $user);
redirect('/')
} else {
template index => {error => 'Wrong username or password'}
}
};
But again, when I try to open the page, the authentication plugin redirects the browser to /login instead of /prefix/login.
I was able to fix the problems by
Mentioning the prefix in the config definitely feels wrong. Hardcoding the prefix into the app? It also means the app can't be run locally on localhost for testing anymore.
How should I properly write the app, configure it, and configure Apache to make it work both locally and in production, without hardcoding the prefix anywhere in the app?
Interestingly, all Python flask and whatever apps written by other colleagues run as written without problems.
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
|
|
|
|