Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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
DBI trace and Apache
1 direct reply — Read more / Contribute
by Anonymous Monk
on Sep 14, 2019 at 02:55
    I'm redirecting DBI trace to a file from within a CGI script.
    The script contains some info but not the sql query.
    There has to be something wrong with the environment becuase in other servers I can see the sql output
    Any htoughts?
Change Namespace of Package
5 direct replies — Read more / Contribute
by elliott9
on Sep 14, 2019 at 00:55

    I'll start by saying I am new to Perl.

    Short Story: How can I rename the namespace of a Perl package? Either doing this on an already installed package OR do this on a new package before I compile it?

    Long Story (if you are interested):

    I have an existing Perl script that runs a package imported from a vendor named Infoblox that we use to automate changes to records on a server. The Perl packages are custom to Infoblox AND the version of their OS that happens to be on that server. We'll call this package version 7.

    I need a way to, without disturbing existing functionality, run scripts from the same Linux machine that interact with a different Infoblox server that runs a newer version of the Infoblox operating system. Since they have released a newer version of their OS (version 8) they also have a newer version of their Perl package. After testing I am unable to make API calls to the version 7 server using the version 8 perl package. Likewise I am not able to make API calls to the version 8 server using the version 7 perl package. I tried installing them at the same time but since they use the same namespace of "Infoblox" that did not work out at all.

    I have no experience creating perl packages but it seems that I should be able to alter something in the new package before I compile and install it which would give it a unique namespace. Any tips on where that would be? ALternatively I thought I could use CPAN or package or some kind to rename the existing (version 7) already installed package to something unique which would mean installing version 8 package would work okay. I found Package::Rename on but have been unable to figure out how to make it work.

    Any help would be appreciated.

Soap::Lite set charset
3 direct replies — Read more / Contribute
by Anonymous Monk
on Sep 13, 2019 at 14:21
    Simple question but I can't figure it out.
    I want to send iso-8858-5 to a Soap service, but Soap::Lite client defaults to utf8.
    How do I change that?
How to update tk label value embedded in textarea.
2 direct replies — Read more / Contribute
by Anonymous Monk
on Sep 13, 2019 at 14:14

    Hi Monks,
    I have list of labels embedded in textarea.
    After deleting/removing label from textarea, I want to update the value of remaining labels in textarea all the time.
    Any help on this would be appreciated.


get() from website hangs
5 direct replies — Read more / Contribute
by jeffw_00
on Sep 13, 2019 at 08:42

    Hi - the relevant lines of my script are

    ------- use LWP::Simple; $pass=1; my $doc = get(' +ry&state=MA&site=BOX&lat=42.3667&lon=-71.4') || die {$pass=0}; -------

    This is part of a script that runs every 15 minutes that gets this webpage, parses some specific info from it (like temperature), and writes the info to a file so my home control program can later open the file and act on the data. My problem is that a few times a day, the get never returns, and the script hangs. I have another script running that detects the hang, and kills and restarts the script. But that's clunky. I'd like to either eliminate the hang, or detect the hang -within- the script. But that is a level of Perl that I haven't dealt with before so I'm wondering if anyone can point me to a recipe. Thanks!

    Further background - using ActivePerl on a W7 machine this code never hung. Switched to W10 and ActivePerl stopped supporting the get properly so I switched to Strawberry Perl (which i like better overall) but where I am having this intermittent issue. (this is probably the "fanciest" thing I do with Perl on my PC so for everything else either Perl works fine).

    Many Thanks!

Extacting lines where one column matches a name from a list of names
4 direct replies — Read more / Contribute
by mr_clean
on Sep 12, 2019 at 21:07
    Hello, wise monks.

    I have some tab delimited data:

    name1 \t data \t moredata \t evenmoredata \t
    name2 \t data \t moredata \t evenmoredata \t

    And a list of names which are interesting;

    name1 name2 name3 name4

    I have been using awk to extract rows from the tab delimited file where column 0 matches my name, and looping through my list of names in order to extract all matching rows. But as my data grows, this task gets very time consuming (6 hours for 200 mb worth of data; and I want to analyse files that are 10 gb!)

    So I would like to user perl (I have no perl experience, previously worked in bash).

    My plan:

    Convert each entry in the data file to a key (the name column) and corresponding hashes (all the other data in each column).
    Do a regex match between my list of names, and my hash keys.
    Use the matching hashes to extract the keys.

    But I have no idea where to start.

    Any advice?

Running JavaScript from within Perl
6 direct replies — Read more / Contribute
by anautismobserver
on Sep 12, 2019 at 21:06

    My goal is to develop an automated means to obtain the number of followers for each of a list of WordPress blog feeds (eg, which display the number of followers in a way that is captured by a copy-and-paste but is not in the HTML page source code. In order for these pages to display properly I need to be logged into a WordPress account and have JavaScript enabled in the browser.

    So far I have the following code:

    use strict; use warnings; use LWP::UserAgent; use LWP::Simple; use HTML::TreeBuilder; print HTML::TreeBuilder->new_from_url(' +s/94271045')->as_text;

    This code produces the following output:

    > WordPress.comPlease enable JavaScript in your browser to enjoy

    Naively it seems to me that since my browser can interpret a web page using JavaScript without any a priori information, Perl should be able to as well. Is this possible? If not, why not?

    I'm a Perl novice who wants to get code running without learning Perl "from the ground up". My strategy has been to find working code samples that do pieces of what I want, then change them incrementally until they do all I want. I'm using Strawberry Perl on Windows.

    Can you offer guidance or link to somewhere that explains it for novices like me? Thank you.

copy an epub as a file, not a directory
2 direct replies — Read more / Contribute
by Trudge
on Sep 12, 2019 at 17:21
    I have a Perl script to manage my library of digital books (pdf & epub). When I use Perl to copy an epub file from one directory to a local Apache web site, it seems to copy as a directory, not a file, according to 'ls'. I know epubs are zipped HTML and the mime type is 'application/epub+zip'. After copying, I cannot click to download it. I've looked at Extended Attributes and played with xattr but no joy. Very frustrating. Any ideas please?
$File::Fetch::WARN = 0; not working?
1 direct reply — Read more / Contribute
by jamroll
on Sep 12, 2019 at 14:24
    i have tried for hours now, and i am very upset, cause this should be super simple. File::Fetch::WARN, as I have read, when set to 0 will stop things from being carp'd (which outputs to STDOUT, no?). but, my code emits an error message when $PARAMS{url} does not exist when i need it to just shutup and let me handle the error. so i do this in my code:
    use strict; use warnings; use CGI::Carp qw(fatalsToBrowser); use File::Copy; use File::Path qw(remove_tree rmtree); use File::Fetch; $File::Fetch::WARN = 0; use Fcntl; use URI::Escape; use English; my $ff = 0; eval { $ff = File::Fetch->new(uri => $PARAMS{url}); }; if (not $ff) { if ($DEBUG_OP_ADD_COVER_PHOTO) { $output .= "failed to retrieve image: " . $ff->error . "<br>\n"; } else { print error_redir(redirrer($OP_QUERY, $OP_FILE_MANAGER, $FOLDER_QU +ERY, $FOLDER), "Failed to Retrieve Image: " . $ff->error); exit 1; } }
    the eval was added in as a suggestion to suppress the warning, but that doesn't work. $File::Fetch::WARN = 0 has no affect!

    the fetching process emits a completely different error message, and it's printed (i presume to STDOUT) before i get to print anything to STDOUT! which causes "internal server error", and i can't get the thing to stop printing that damn junk out, it 'breaks' things!

    Note: whilst $DEBUG_OP_ADD_COVER_PHOTO = 1, the error message emitted is: could not retrieve file: Command failed:. Nowhere in my code have I asked for that to be printed out.

    Edit: Added "use" statements which may affect your answer. the code in this post is only a very small part of a much larger program.

    I was pondering why the ball was getting bigger, and hit me!

Diiference between these two filenames / strings
5 direct replies — Read more / Contribute
by Anonymous Monk
on Sep 12, 2019 at 13:07

    Hi Monks,

    what is difference between below two filenames/strings, as first one doesn't seems needed any utf-8 encoding and second one needed.

    How can I check the difference between below two filename/strings or what condition will differentiate these two files.

    1. test1℗ὓ.txt #this works without further encoding
    2. 1669-SCC-H˘pitauxdeSaint-Maurice-POC.PIF #but this needs utf-8 encoding.


    <P> tags added by Grandfather to improve readability

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 having an uproarious good time at the Monastery: (7)
    As of 2019-09-19 07:04 GMT
    Find Nodes?
      Voting Booth?
      The room is dark, and your next move is ...

      Results (240 votes). Check out past polls.