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.
I'm running into a weird problem with overload , I'm overloading dereferencing like with %{} which means I can't access the objects attributes inside the methods without causing an infinite loop.
My script below works, but i have one problem, it just display out 1 record
What i need is to return all records from database
my $sth = $dbh->prepare("SELECT
snd.name, snd.country, m.item, m.eqty, m.price, m.line, m.prodct FRO
+M
buys as m
JOIN Busers as snd ON snd.id = m.buyer WHERE CASE WHEN (SELECT SUM(s
+tatus = ?) FROM buys) > 0 THEN m.status = ? ELSE m.status = ? OR m.
+status = ? OR m.status = ? END
ORDER BY created ASC");
$sth->execute('sold', 'forsell', 'bugt', 'paid', 'inshop');
my $Data = $sth->fetchall_arrayref();
foreach my $Data (@$Data) {
my ($name, $country, $item, $eqty, $price, $line, $prodct) = @$Dat
+a;
$html = "<tr>
<td>
<p>$name</p>
<p>
$eqty, $price, $line,
</p>
$prodct
$country
</td>
</tr>
";
}
First of all, i have to admit that i feel that i should know this already, but i just don't.
Is it possible to add external cpp/h files when using Inline::CPP? I only need XS bindings for the stuff i'm inlining, the rest only needs to be accesible through the inlined CPP code.
Here is the simplest example i could tink of.
test.pl
use Inline CPP;
for(1..3) {
print "Perfect random number: ", cast_die(), "\n";
}
__END__
__CPP__
#include "xkcd.h"
int cast_die() {
int rolled = xkcd_dice_roll();
return rolled;
}
#ifndef XKCD_DICE
#define XKCD_DICE
// See https://xkcd.com/221/ for why this is absolutely perfect
#define FAIRLY_GENERATED_RANDOM_NUMBER 4
int xkcd_dice_roll();
#endif
It occurred to me that I have to enclose this inside a BEGIN block to avoid the overhead and side-effects of loding
all modules with use (this happens in the BEGIN phase) before the unless is executed at run time.
This doesn't work, since caller() IS defined inside BEGIN
I'm developing a DBIx distribution and need to check plenty of SQL in the tests.
My approach is to use SQLite as primary engine, since it comes with the DBD::SQLite module installed and that's not much of a prerequisite (it's even comes bundled with Strawberry Perl!)
My issue is where to put the temporary SQLite file...
in the distribution's /t directory?
in the FS's /tmp ? What about other OSes?
or should I restrict the SQL-testing to the authors system
Those SQLite files don't become big, but I'm not sure about writing stuff into the dist directory.
On a side note:
I want to be able to switch to other DB-Servers while testing. (But now really author's side unless explicitly wanted by the user)
What's the best approach to make this configurable?
I found out that I left some unaltered code that I programmed 10 years ago and it went unnoticed. I knew this bug and I actually fixed it quick and dirty in multiple places but I never found a good fix for it.
What is the best way to use the splice inside of a loop like this (foreach, or other)
I have users who are doing cut-n-paste into a Tk Entry widget in my perl app and causing some issues.
Apparently things like Outlook, Notepad, etc, can be configured to change an ASCII single quote (') into smart quotes aka Unicode Right Single Quote and Left Single Quote. When they cut-n-paste this into my entry widget, I see goofy things happen later in my script. I'm including a test script below, note the difference between what shows up in the message box and what the print STDERR outputs.
What is going on here, and what are some intelligent ways for me to handle it?
I think I want to simply translate any unicode single quotes (left or right) to the ASCII single quote - no? What if they start pasting other unicode characters? Looking for experience & guidance here.
Thanks
-Craig
#!/opt/homebrew/bin/perl
use strict;
use warnings;
use Tk;
my $main = new Tk::MainWindow();
my $entry_test = $main->Entry(-text => "single-quotes: ’'")->pack();
my $btn_test = $main->Button( -text => ' Test ',
-command => sub {
my $text = $entry_test-
+>get();
&msg($main, $text) if (
+$text);
} )->pack();
sub msg
{
my ($parent, $msg) = @_;
print STDERR "Messaging: $msg\n";
$parent->messageBox( -title => 'Event', -message => $msg, -type => '
+ok', -icon => 'info' );
}
MainLoop();
I'm trying to parse RSS feeds with XML::RSS::Parser, and it's mostly working fine, except that I need to be able to pull the content of elements in the itunes namespace and nothing I can think of seems to work.
If I'm trying to read the element itunes:summary (it will be en object of type XML::RSS::Parser::Element), for example, I've tried:
What follows is my very first adventure in perl world, so please be merciful.
I wrote the following code to modify a bunch of pandoc-generated DokuWiki formatted files in order to convert some expressions to DokuWiki internal links.
That went through many iterations and I am now somewhat satisfied with the result except for one mystery I am unable to pierce through.
It does not crash my code, nor does it sends any warning, but I can't explain this result.
Here's my problem:
In this substitution part of the code:
.(defined($4) ? $4 =~ tr[\/*][]dr : '.')
line 44, I check if the value of $4 is defined and if it is, I apply a tr to it to remove italic (//) or bold (**) marks if they are present. If $4 is undefined (meaning there are no dot, comma or semicolon after the last word of the expression), the conditional operator sends a dot to end the substitution.
No line breaks.
And I don't understand why and how those line breaks get inserted.
Actually, those breaks don't really matter, as DokuWiki format being some kind of lesser markdown, it just gives the same html output with or without them, but it worries me as a sign of my incomplete understanding of my own code.
It may have something to do with the /x modifier I suspect.
We currently use qr_code of Auth::GoogleAuth to generate QR codes for Google Authenticator, but recently found out that the underlying Google Image Charts was deprecated in 2012... (apparently it's periodically shut off to "notify" users of it going away). Anyone know of an easy replacement or have any recommendations?
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).