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 am not able to follow symbolic links when using the find() command. it says on the manual that the 'follow' or 'follow_fast' option should be used but i don't understand how to use it together with the '\&wanted' routine -
use File::Find;
find(\&wanted, @directories);
find(\%options, @directories);
I'm using Imager to render truetype fonts but there is no output, and no error, it's just blank. I checked $Imager::formats{tt} to see if Imager has truetype support and it's blank. I have some /usr/share/fonts/truetype so I dunno why Imager says that. How can Imager be compiled with tt support?
I have another computer with a similar setup but on that one Imager does render truetype even though $Imager::formats{tt} is blank! They are different operating systems and versions of Imager so I don't know. I could install the only fonts that Imager supports on this box: Freetype2, but I want to use truetype and would appreciate any ideas you have on how to get Imager to use my fonts.
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:
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).