Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Seekers of Perl Wisdom

( [id://479]=superdoc: print w/replies, xml ) Need Help??

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.

Post a new question!

User Questions
how to use find() options
3 direct replies — Read more / Contribute
by ypreisler
on Apr 17, 2024 at 12:16
    Hi Monks,

    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);
    thanks a lot, Yaron.
Imager font problem
3 direct replies — Read more / Contribute
by Anonymous Monk
on Apr 16, 2024 at 17:04
    Dear Monks,

    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.

    Thank you.

De-Overload reference?
3 direct replies — Read more / Contribute
by LanX
on Apr 16, 2024 at 13:12
    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.

    What am I missing?

    While writing this I'm having an idea...

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

    Update

    I just discovered eval no overload mentioned in the docs, will give it a try ... :)

problem with returning all records
2 direct replies — Read more / Contribute
by frank1
on Apr 16, 2024 at 06:30

    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> "; }
External (extra) files when using Inline::CPP
1 direct reply — Read more / Contribute
by cavac
on Apr 16, 2024 at 05:52

    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; }
    xkcd.h
    #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
    xkcd.cpp
    #include "xkcd.h" int xkcd_dice_roll() { return FAIRLY_GENERATED_RANDOM_NUMBER; }

    Is something like this even possible with Inline::CPP?

    PerlMonks XP is useless? Not anymore: XPD - Do more with your PerlMonks XP
Running modulino inside BEGIN
3 direct replies — Read more / Contribute
by LanX
on Apr 14, 2024 at 13:22
    Hi

    while developing a module I like to run (F5) the testsuite automatically. I'm using a moulino approach which works considerably well

    #BEGIN { # TODO unless ( caller() ) { # Modulino for development exec q(cd ../..; prove ./t/); #run proove from dist root } #}

    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

    BEGIN { warn "Caller Begin: ",defined caller(0) } warn "Caller Normal: ",defined caller();

    Caller Begin: 1 at /home/lanx/... Caller Normal: at /home/lanx/...

    EDIT Solution

    while writing this I realized that BEGIN is called 2 levels down, hence caller(2) seems to work

    BEGIN { # TODO unless ( caller(2) ) { # Modulino for development exec q(cd ../..; prove ./t/); #run proove from dist root } }

    Is this reliable?

    (I think it is, but I already wrote this post, before finding the solution and the monastery is not overwhelmed with writeups :)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

CPAN test suites with SQL
1 direct reply — Read more / Contribute
by LanX
on Apr 14, 2024 at 06:22
    Hi

    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?

    • A prove option
    • an ENV setting
    • a prompt while testing? (DBI can test for available DBD:: drivers)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

How to use a splice inside a foreach
4 direct replies — Read more / Contribute
by Veltro
on Apr 13, 2024 at 03:55

    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)

    Original code bugged:

    sub filterExclude{ my $ar = $_[0] ; # REF! my $someConfig = $_[1] ; my $ix = 0 ; foreach ( @{$ar} ) { my $sKey = $_ ; if ( exists ( $someConfig ->{ $sKey }->{ Exclude} ) && $someConf +ig ->{ $sKey }->{ Exclude} ) { splice ( @{$ar}, $ix, 1 ) ; $ix = $ix - 1 ; } $ix = $ix + 1 ; } }

    Right now I have:

    sub filterExclude{ # 20240414 Quick fix needed because of the splice my $ar = $_[0] ; # REF! my $someConfig = $_[1] ; my $tmpCheckedEverything = 0 ; while ( !($tmpCheckedEverything) ) { $tmpCheckedEverything = 1 ; my $ix = 0 ; foreach ( @{$ar} ) { my $sKey = $_ ; if ( exists ( $someConfig ->{ $sKey }->{ Exclude} ) && $someC +onfig ->{ $sKey }->{ Exclude} ) { splice ( @{$ar}, $ix, 1 ) ; $tmpCheckedEverything = 0 ; } $ix = $ix + 1 ; } }

    But of course this is ugly and not efficient

Tk Entry & Right Single Quote
3 direct replies — Read more / Contribute
by cmv
on Apr 11, 2024 at 14:39
    Hi Monks-

    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();
namespaces in XML::RSS::Parser::Element
2 direct replies — Read more / Contribute
by wintermute_115
on Apr 11, 2024 at 08:38

    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:

    $summary = $element->query('itunes:summary'); $summary = $element->query('{http://www.itunes.com/dtds/podcast-1.0.dt +d}summary'); $summary = $element->query('summary') $summary = $element->query(process_name('itunes:summary'): $summary = $element->query(process_name('{http://www.itunes.com/dtds/p +odcast-1.0.dtd}summary'):
    and some other things I don't remember. But everything I try, it ether returns undef or I get told Bad call to match: '<XXX>' contains unknown token.

    Does anyone know how this works? Thanks.


Add your question
Title:
Your question:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":


  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • 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).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-18 08:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found