Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

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
Pattern matching exlusion
2 direct replies — Read more / Contribute
by wrkrbeee
on Nov 28, 2014 at 21:30
    Hi everyone, Looking for a fairly simple pattern matching expression, but I am coming up short. Would like to enhance the following IF expression: if ($form_type=~/^$formget/i) Valid strings for $formget are '10-K', '10-KSB', '10-K405', '10-KSB405' and '10-Q'; Deal killers are any of the above followed by '/'. For example, 10-K/A, 10-Q/A ... are invalid strings. In sum, the goal is to keep any string which begins with 10-K or 10-Q, AND does not terminate with a slash (/). I am most grateful for any ideas. Thank you!! Rick
Adding text to an image for printing
1 direct reply — Read more / Contribute
by tel2
on Nov 28, 2014 at 20:12
    Hi Monks,

    I'm wanting to write a Perl script to:
    - take user input (text),
    - somehow merge that with a background image (maybe TIFF), and
    - save the result as a file for users to download and print.
    (This is to replace a more manual (and easy to get wrong) method of doing an MS Word mail merge.)

    To achieve this, I was thinking I'd use Perl's PDF::API2 module to create a PDF from the image and text.
    I may be able to work out how to do that, but the main stumbling block I can see is, the font I need to use is "MT Script Bold", and it doesn't look as if that comes with PDF::API2, so any ideas how to make that font available to PDF::API2?  I've been searching the web for 30+ mins, including looking at the module docs, but I haven't got anywhere with it yet.

    Apart from the font issue, do you see any issues with the above approach or can you suggest a better method of achieving my goals?


1 direct reply — Read more / Contribute
by swesque
on Nov 28, 2014 at 18:49
    I want to use Perl to connect to a PostgreSQL 9.1 database

    Perl version is: v5.8.8 built for MSWin32-x86-multi-thread

    DBI version: 1.609; DBD-Pg is 2.14.1

    DBI->connect generates the following error: The ordinal 284 could not be located in the dynamic link library SSLEAY32.dll.

    Here's the code:

    use DBI; my $dbh = DBI->connect ('dbi:Pg:hostname=;dbname=finance;','po +stgres','uvm', {AutoCommit=>1,RaiseError=>1,PrintError=>0}); print "2+2=",$dbh->selectrow_array("SELECT 2+2"),"\n"; exit(0);

    Thank you in advance ... GA
Pretty Dump Cross References
2 direct replies — Read more / Contribute
by wollmers
on Nov 28, 2014 at 18:31

    Hi monks,

    One of my subs returns structures like this:

    $VAR1 = [ [ [ 0, 0 ], [ 2, 2 ] ], [ [ 1, 0 ], $VAR1->[0][1] ] ];

    The above is the output of Data::Dumper, which in case of larger structures is hard to compare for debugging. Is there something better or maybe an option to get a dump without reference notation like this:

    $VAR1 = [ [ [ 0, 0 ], [ 2, 2 ] ], [ [ 1, 0 ], [ 2, 2 ] ] ];
Two-dimensional match/regex? (2)
2 direct replies — Read more / Contribute
by rsFalse
on Nov 28, 2014 at 17:23
    I tried to make a primitive subroutine, which could match some two-dimensional set of characters.

    And my questions are: 1) have you used two-dimensional search and where? 2) what are good approaches of making match more affective and more fast?

    I've find similar, but old node Two-dimensional match/regex?, almost all links there are non-working.

    Below is my try.
    My example search is:
    # # #.
    And subroutine searches all occurrences of such combination of these 4 chars.
    In usual one-dimension search matches can not overlap if we use /g modifier and do not change pos(), but here I'm changing pos() and matches can overlap.
Testing terminal programs within emacs (or other IDEs)
No replies — Read more | Post response
by LanX
on Nov 28, 2014 at 14:00

    does someone have a clever idea how to interactivly run the currently edited program within a terminal emulation without loosing potential error output?

    Especially Term::ReadLine is unusable within compilation-mode, which opens a new pane showing the interaction with the program.

    Compilation mode has no terminal emulation (AFAIK), which means potential errors and output is displayed but input doesn't get to the process.

    3 ideas come to mind:

    1. augment compilation mode to incorparate term-mode?
    2. Term::ReadLine allows defining explicit IN and OUT handles which may be redirected to a separate xterm window?
    3. like 2., but redirect output to a new splitted pane within emacs
    Curious for input, especially for insights if and how other IDEs solve this.

    Cheers Rolf

    (addicted to the Perl Programming Language and ☆☆☆☆ :)

    I use "pane" for a sub-window within the main window, i.e. what emacs calls a "window" and mozilla calls a "frame"


    for what it's worth, it's possible to run a term script with "M-x term path-to-script" within emacs. This would not only need another keybinding but any special handling of error messages is lost than.

wxHtmlWindow causes exe to crash after PAR::PACKER
2 direct replies — Read more / Contribute
by wongie
on Nov 28, 2014 at 08:23

    With "use wxHtmlWindow", my Perl GUI works under Eclipse but crashes when running the executable after my design has been through PAR::PACKER. I use PAR::Packer 1.023. Any idea what is going on here? I guess some window specific files are missing when going through the PAR::PACKER process. Without the "use wxHtmlWindow", the executable works ok.

Cannot print line
7 direct replies — Read more / Contribute
by nimpoura
on Nov 28, 2014 at 07:30
    Hello, I wrote the code below in order to get the first line of a txt file
    use strict; use warnings; open (IN, "/home/nikol123/indri-5.6/runquery/trec7_4collections.txt") +or die; while (my $file = <IN>){ my @rows = split(/\n/, $file); print "$rows[0]\n"; } close IN;
    Instead,it prints the whole txt and in the end refers this error: "Use of uninitialized value $rows[0] in concatenation (.) or string at /home/nikol123/ line 8, <IN> line 59." Why this code is not functional? Thank you in advance
Best ways to run a windows batch with Perl
3 direct replies — Read more / Contribute
by luxAeterna
on Nov 28, 2014 at 05:14

    Oh, Wise Ones

    I find myself for the first time developing Perl for Windows servers. It is an hostile, unknown jungle for me.

    My question is quite philosophical and I know that there is always more than way to do it, but what would you recommend as a safe way to run a Windows batch?

    A Windows batch will unmercifully exit if it fails, generally providing through console really generic message about the cause of the fail, that rarely will point to the real issue, but it is better than nothing.

    I deduce that for my script to continue running, at least to inform that there was an error before dying, I must spawn a child to execute the batch.

    Problem: I understand that a Windows batch does not provide an error code return, and since it simply dies at any failure, executing inside an eval is futile.

    Which are the plus and minuses of executing a Windows batch with system or with exec?

    Say I have a batch to set the environment variables (which in fact, I have: \dir00\exploit\script\dir_start.cmd) and it can not find some path in certain machines

    Thank you in advance to the monks who wish to dedicate some time to provide their experience to give some light in the obscure Windows land

Ask user to enter IP address repitatively for entities like Netmask, Gateway, DNS, bonds etc till correct address entered
5 direct replies — Read more / Contribute
by rahulruns
on Nov 28, 2014 at 01:43

    I need to write a SCRIPT where it will ask user to enter IP address for entities like Netmask, Gateway, DNS, bonds etc. and will check if valid IP is enetered. If the IP is not valid it will ask to enter it again for the specific entity till the IP entered is correct. The IP could be any IP but a valid IP address. The issue I am facing is how to repeatedly ask for IP of specific entity like Netmask till IP is correct. Sample of code what I am writing is below

    use Data::Validate::IP qw(is_ipv4); use Data::Dumper; my %ipaddress_namei = (); print "Enter IP address of Bond2\n"; my $bond2 = <STDIN>; $ipaddress_namei{bond2} = {$bond2};

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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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 having an uproarious good time at the Monastery: (5)
    As of 2014-11-29 04:16 GMT
    Find Nodes?
      Voting Booth?

      My preferred Perl binaries come from:

      Results (203 votes), past polls