Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Seekers of Perl Wisdom

( #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. Post a new question!

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.

User Questions
Archive::Extract - error handling
2 direct replies — Read more / Contribute
by luxs
on Aug 28, 2016 at 21:21
    I'm using Archive::Extract, as in the original example.
    use Archive::Extract; my $ae = Archive::Extract->new( archive => 'myfile.tgz' ); my $ok = $ae->extract or die $ae->error;
    And the file myfile.tgz is broken. This code produce error on the screen
    Unable to extract 'myfile.tgz': at ./ line 156.
    and continue to execute the further code, but it should die!!! What was wrong? How to catch this error?
Feedback for programming a UI in Perl
2 direct replies — Read more / Contribute
by stevieb
on Aug 28, 2016 at 19:52

    I'm looking for recommendations on which UI platform to use under Perl.

    As someone who has developed or used Perl-based User Interfaces, please share your experiences with what you have found.

    Feedback on all aspects welcome... integration, ease-of-coding, ease of use, look, feel, documentation, availability of help/guidance here at PM or external etc.

    I'm looking at writing small, short and simple GUI apps that'll be on touch-screens to control events and situations with button pushes. Ease of configuration of text, grey-out, displaying small images etc is what I'm looking for.

    After you have an opinion, answer this...

    What led you to choose what you're using?

Changing font colour in a Wx StaticText or Button
2 direct replies — Read more / Contribute
by stevieb
on Aug 28, 2016 at 17:05

    I'm working on a GUI for one of my projects (I dislike UI programming, specifically non-web), which will be as basic and simple as possible. I chose Wx, simply because it's a tad bit prettier (than Tk). This UI is being designed for a 5" touch-screen, and doesn't need many features.

    I'm wondering with Wx, how I can change the font colour of a simple StaticText (or even a button). The docs are sparse, but even the perl and XS code don't seem to have anything relating to changing colours.

    Am I missing something, or is this just the way Wx is? If Tk or (insert suggestion here) can be manipulated to do simple things like change the colour of a font, I'll seriously consider changing to that (to begin with, Wx was a PITA to get set up on a Raspberry Pi, so I'm half-way toward changing as-is).

    my $font = Wx::Font->new(16); $self->{t_header} = Wx::StaticText->new( $panel, 1, "Temperature", $self->{xy}{t_header} ); $self->{t_header}->SetFont($font);

    update: The code and references to other code in this and subsequent nodes require trunk installs of certain modules. CPAN versions will not have the updates to render things properly...

Perl with redistributable web server and mysql?
2 direct replies — Read more / Contribute
by whiteperl051
on Aug 28, 2016 at 14:02

    I love Perl. It's awesome.

    I've been thinking of writing software in Perl that can be used on Windows but for it to work I will require a redistributable web server and perhaps Mysql? to go with that.

    So, the way it would work is that I have a setup.exe file that I offer for download. When setup.exe is run to install my app it will install a webserver on port 12345 with mysql and then execute my Perl scripts - and this is all done on the host machine. Hope this makes sense.

    Is there perhaps a web server I can borrow or redistribute with my Perl app so that I don't have to re-create a web server myself which can execute and run the Perl scripts.

    Some apps that work this way (you simply install it and the app runs in a web browser on a server running on the local host) that come to mind is:

    sabnzbd / deluge / sonarr / etc.
question when learning P::RD?
2 direct replies — Read more / Contribute
by xiaoyafeng
on Aug 28, 2016 at 04:11

    Hello Monks,

    Long time no see! Recently I have to parse a file and export to another format. the original file is like this:

    Y 034309201607258 1 #Y means header Q 02751VACANT / CLOSE #comment G .... # inner head ... ... ... T RCRC 0810010 T RDRD 0810010 A 22OP A 13O A 12O P 3472CHSK00010014 #P means inner trailer Z 034309201607258 #Z means trailer
    I took this weekend to learn P::RD, and seems a little bit to understand it. but when I tried some snippet to run, it's hard to succeed as I image:
    use Parse::RecDescent; use IO::All; my $text = io("xxx.DAT")->slurp; # Create and compile the source file $parser1 = Parse::RecDescent->new(q( startrule : HeadRule /.+/ms TrailerRule HeadRule : /^Y.+$/m TrailerRule: /^Z.+$/m )); $parser2 = Parse::RecDescent->new(q( startrule : HeadRule HeadRule : /^Y.+^Z.+$/ms )); # Test it print "Valid data\n" if $parser1->startrule($text); #no! print "Valid data\n" if $parser2->startrule($text); #yes
    why parser1 is failed? and in order to learn P::RD, Could anyone tell me if some module parsing files( like xml or html etc> on cpan make use of P:RD?


    I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction

PPI usage w/r/t documentation
2 direct replies — Read more / Contribute
by perl-diddler
on Aug 27, 2016 at 23:58
    I was looking over the PPI set of modules and am wondering if anyone uses it in the format:
    # Create a document from source $Document = PPI::Document->new(\'print "Hello World!\n"');
    I've tried several variations using vars, double and single quotes, but have been unable to get it to parse anything from memory. It *does* work if I give it a file, but the example above doesn't seems to work -- which seems pretty basic.

    I'm wanting to use it for memory-based input and no files are involved, For example, I might want to parse the same line 2 different ways (maybe with a trailing semicolon, or w/o, or some other way).

    I'm wondering what syntax is suppose to work -- I also pointed out that the documented example doesn't work in their issue database, but no response on that. So does anyone have any working examples? My basic framework (in a file called ppi_dump) looks like:

    #!/usr/bin/perl use warnings; use strict; # use utf8; use open IN=>q(:utf8); use open OUT=>q(:utf8); use PPI; use PPI::Dumper; use P; P "parse: %s", $ARGV[0]; my $doc=PPI::Document->new($ARGV[0]); my $dumpr=PPI::Dumper->new($doc, qw(whitespace 0 comments 0)); # .my $toks = $dumpr->list; # for indirect access... $dumpr->print;

    A working example should suffice to jumpstart this -- from the documentation, I would have thought a string would have worked for my "arg", like:

    > ppi_dump 'print "Hello World!\n"' parse: print "Hello World!\n" Can't call method "list" on an undefined value at ./ppi_dump line 14.

    FWIW, if I give it a filename, it shows the content of the file, parsed, but the parse from string is the issue.


Highly efficient variable-sharing among processes
3 direct replies — Read more / Contribute
by cnd
on Aug 27, 2016 at 17:44

    My unsolved quest for efficient variable(memory) sharing on linux continues.

    I have a monster (lots of gigs, upto 200gb in future) in-memory hash and a nice perl sub which does lookups and returns results for me.

    I want *other* processes to be able to do lookups as well, obviously without every process loading it's own duplicate copy of the hash.

    The rate of lookups is extreme, *many* millions per minute at least.

    Can anyone think of an efficient way to code this? The "lookup" child processes will be mod_perl (web cgi); I'm hoping the giant-hash process can simply be a local daemon.

    I'm wanting to have zero unnecessary overhead: so: no interprocess communication if possible (no sockets, no messages), no memory-shuffling (I don't want to move gigs of hash out of a shared memory pool into the web server pool prior to starting the lookup), no serializing...


    Has anyone ever built a modern perl from source? What about the idea of modding the source to introduce some kind of shared region that way? e.g. every variable with the name "shared_*" uses a different subset of RAM or something like that?

Embedded function or subroutine - which is better?
4 direct replies — Read more / Contribute
by Linicks
on Aug 27, 2016 at 12:51

    Hi All

    I don't know how perl pre-parses code on the fly - is it quicker (i.e. will perl map out a call to a sub-routine on pre-parse) such as

    sudo code if ($debug == "true") { &debugit; # call the routine } or if ($debug == "true") { ** do all the debug code here and/or carry on ** }



Using unpack on Windows with external data
2 direct replies — Read more / Contribute
by locinus
on Aug 27, 2016 at 07:33

    Hi monks.

    I'm new using unpack function to get data from an external binary source. I'm having trouble getting the right values.

    My first value is coded as an unsigned 16-bit integer, little-endian. When I open it with my hex editor, I can see that the two first bytes are coded "DC 20", which represents 8412, which is the value I expect.

    My perl code is the following:

    my $fh = FileHandle->new; open ($fh, '<', $filename) or die 'missing file'; binmode $fh, ':raw'; my @values = unpack 'S<', $fh; print @values;

    and provides the value 26950. I really can't figure out where this data comes from. Same if I provide '<:raw' to the open function.

    I'm running on Windows 7 64-bit, Perl 5.12.3.

    Any idea/suggestion? I'm clueless right now.

How do I replace the camel icon on Windows exe built with pp?
2 direct replies — Read more / Contribute
by perltux
on Aug 27, 2016 at 05:52
    I use 'pp' to build self-contained exe files of my graphical (Tk) Perl applications for MS Windows. The icons in the task bar and in the top left corner of the application window show up correctly when setting them with $mw->iconimage($icon), but on the desktop and in the windows file browser I still get the default camel icon.

    In the past 'pp' supported the '--icon' switch which allowed to specify a custom icon, but recent versions of 'pp' no longer support that switch.

    So how do I replace this camel icon with my own custom icon with recent versions of 'pp'?

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

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (5)
    As of 2016-08-29 04:10 GMT
    Find Nodes?
      Voting Booth?
      The best thing I ever won in a lottery was:

      Results (398 votes). Check out past polls.