If
you have a question on how to do something in Perl, or
you need a Perl solution to an actual real-life problem, or
you're unsure why something you've tried just isn't working...
then this section is the place to ask.
However, you might consider asking in the chatterbox first (if you're a
registered user). The response time tends to be quicker, and if it turns
out that the problem/solutions are too much for the cb to handle, the
kind monks will be sure to direct you here.
As I mentioned earlier my unthreaded builds of perl were, upon installation, being assigned an @INC that was empty.
Well .... silly me .... I had assumed that an archname of 'MSWin32-x64-multi-thread' would, upon becoming neither 'multi' nor threaded, change to simply 'MSWin32-x64'.
But, no - the win32/makefiles decree that it becomes 'MSWin32-x64-perlio' if USE_PERLIO is defined.
The fact that USE_PERLIO is also defined for the multi-threaded build is apparently unworthy of mention, even though defining USE_PERLIO is equally optional for both multi-thread and non-multi-thread builds of perl, AFAICS.
So why do they add '-perlio' for the unthreaded build only ?
Is there a good reason ? (Not that one is required, of course ... heaven forbid !!)
UPDATE - to elaborate a little on how this led to @INC being empty:
In these unthreaded builds I was specifying (eg) INST_ARCH=MSWin32-x64 and that didn't match the actual designated archname of MSWin32-x64-perlio .
Now, I don't exactly know why that resulted in an empty @INC, but the problem went away as soon as I changed to specifying INST_ARCH=MSWin32-x64-perlio .
perl -V
Can't locate Config.pm in @INC (you may need to install the Config module) (@INC contains: …).
BEGIN failed--compilation aborted.
Additional information :
@INC has paths of two versions of perl. Path mentioned in @INC has Config.pm but still it is throwing this error when I execute this command. Similar problem can be recreated with other examples where perl goes for search in @INC. Note that It works fine when I export same paths from @INC to PERL5LIB.
I would like to call a different function in this loop before like
for ( $sFunction ) {
/test1/ && do {
# ....
};
/test2/ && do {
# here I want to call /test1/ part above ...
# ... and then do different stuff here
};
}
When I saw matrices, I immediately thought PDL. After finding a solution, I tried searching for existing solutions, and found the following at Rosetta Code:
#!/usr/bin/perl
use strict;
use warnings;
use PDL;
use PDL::NiceSlice;
sub kron{
my $A = shift;
my $B = shift;
my ($r0, $c0) = $A->dims;
my ($r1, $c1) = $B->dims;
my $kron = zeroes($r0 * $r1, $c0 * $c1);
for(my $i = 0; $i < $r0; ++$i){
for(my $j = 0; $j < $c0; ++$j){
$kron(
($i * $r1) : (($i + 1) * $r1 - 1),
($j * $c1) : (($j + 1) * $c1 - 1)
) .= $A($i,$j) * $B;
}
}
return $kron;
}
Wait, loops? The whole point of PDL is to hide loops. And indeed, my solution doesn't involve them. Also, a benchmark shows my solution is more than twice faster than the Rosetta Code one.
I'm far from an expert on PDL or matrices in general. But it seems we can easily multiply each element in a matrix by the same number, but it's not so easy to multiply them by different numbers. But we can multiply each element by a matrix, so we just need to "inflate" the matrix, so instead of
That's what dummy does (two dummies, in fact, one in each dimension). Multiplying this with the second matrix gives us a result that has all the expected numbers, but a bit different dimensions.
Hello Respected Monks I am seeking some help question.
package Validation;
use Moose::Role;
sub check_entity {
my ( $self, $db_id ) = @_;
#some logic
my $found_db = sub {
#logic verify id present in db
return 1;
}
return $found_db;
}
I have a module that helps me write clean modules using the following `package MyApp::Moose;`.
I tried searching a lot and am not sure exactly how I can inject the above role to the caller (so that it will get consumed) and the caller can have access to `check_entity` method.
Note:- I cant create an object of the caller since it has some required entity (*object may not be needed to inject role I believe)
But unfortunately, I couldn't able to figure out the right way,
I am sure there must be a simple way to do it which I am missing out.
Also want to do similar for multiple roles in the future once I develop them.
package MyApp::Moose;
use strict;
use warnings;
use namespace::autoclean;
use Hook::AfterRuntime;
use Import::Into;
use Moose ();
use Clone 'clone';
sub import {
my ($class, @opts) = @_;
my $caller = caller;
my %opt = map { $_ => 1 } @opts;
strict->import::into($caller);
warnings->import();
Clone->import::into($caller,'clone');
if($opt{role}) {
require Moose::Role;
Moose::Role->import({into=>$caller});
} else {
Moose->import({into=>$caller});
after_runtime {
$caller->meta->make_immutable();
};
}
namespace::autoclean->import(
-cleanee => $caller,
);
return;
}
1;
package MyApp::Process;
use MyApp::Moose;
sub some_method {
my ($self, $db_id) = @_;
# I want to call like this
$self->check_entity($db_id) || return;
}
1;
I was hoping I could inject it directly to the caller using metacpan.org/pod/Moose::Exporter(Moose::Exporter) but after several attempts, I was unable to accomplish
I'm new to Perl. I have a problem with installing Tk.
The error message:
Indexing failed! at C:/Strawberry/perl/vendor/lib/CPAN/SQLite.pm line 77, <DATA> line 69.
CPAN::SQLite setup failed at C:/Strawberry/perl/vendor/lib/CPAN/SQLite/META.pm line 325, <DATA> line 69.
system C:\Strawberry\perl\bin\perl.exe -MCPAN::SQLite::META=setup,update,check -e setup failed: 6400 at C:\Strawberry\perl\vendor\lib/CPAN/SQLite/META.pm line 318.
I can't find a solution on google.
Hope anyone can help me.
Esteemed monks, I have a problem with encoding of an emoji in perl. The string "Test 😀" is read from a MySQL database table which has encoding latin1. Obviously that's not a UTF-8 character set, but my console seems smart enough to detect the intended output, as a plain "select * from table" on the "mysql" client displays the "grinning face" emoji correctly.
Then my perl (version 5.26) program logs the text to a log file, and again running "tail -f" on the log file displays the emoji in the text correctly. I also log the bytes using sprintf( "%vX", $text) and it prints "54.65.73.74.20.F0.9F.98.80". So the bytes for the emoji are there, in "F0.9F.98.80".
Then the text is JSON encoded (using the JSON library), and sent using $conn->send_utf8() to a websocket client using Net::WebSocket::Server, however the websocket client (running in a web browser) receives "Test ð". I've tried encode( 'UTF-8', $text ) which did not fix the problem.
The whole subject of character encoding is not an easy one, and mixing MySQL with Perl with websockets (with JSON for good measure) has made it tricky to tell where the problem is.
Can anyone help find why the websocket client doesn't receive the emoji correctly please?
When the various annotation is the same, then the sequence is also the same.
I am pretty sure I need to use the map command, but I am a bit unsure how I would handle this. So far I have used it when I have 2 things to compare, e.g. only the id that would change and the sequence that could be repeated, and I was grouping based on the sequence. Like this:
use strict;
use warnings;
my %res;
while (<>)
{
chomp;
my ( $name, $rest ) = split /\t/;
push @{ $res{$name} }, $rest;
}
for ( sort keys %res )
{
print "$_:", join( ",", @{ $res{$_} } );
print "\n";
}
Hello fellow monks!
I keep trying to understand why I am getting an exception error although it does not seem to be some kind of mistake. So, I have a script that is reading a file and storing some number ranges, which I will use to re-structure a string.
Initial string is something like:
where I am getting the info I need and change the '.' accordingly. For debugging, I made the script print the string length and each $start and $end, to see which substring is out of bounds, in the form of string length <TAB> range
Weirdly enough, in the string that it fails, which has a length of 413 characters, the debugging prints the following:
As you can see, for some weird reason, and although my string's length is 413 chars and there are more ranges after 356-369, it exits with this error.
Any ideas?
Snippets of code should be wrapped in
<code> tags not<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).