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
module as parameter
4 direct replies — Read more / Contribute
by pwagyi
on Sep 20, 2017 at 22:06

    If I have an interface 'I', and possibly several implementations A, B,C that satisfies interface 'I'. How could I have a module M takes 'I' as parameter? Something similar to ML functor?

search.cpan.org broken?
2 direct replies — Read more / Contribute
by afoken
on Sep 20, 2017 at 17:52

    Update: Problem on my side. See Re^2: search.cpan.org broken?.


    Since about two or three weeks, I can't use search.cpan.org. I can ping it, but the web server lets any connection run into a timeout. Did I miss something?

    The problem is not in my home network. I have the same problem from the network at work, using a different provider, different DSL box, different firewall.

    Ping / traceroute / nmap output from home network:


    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
concatenate a non-printable character onto an ascii string and inspect the content
5 direct replies — Read more / Contribute
by holandes777
on Sep 20, 2017 at 12:05

    I am trying to append a non printable character (FileSeparator/FS/0x1c) onto an ascii string and then inspect the contents of the string for debugging purposes. I think I am screwed up on the "how to inspect the contents of an ASCII string in hex) side.

    my $string = pack('a*','123456'); foreach (my $i=0; $i<length($string); $i++) { printf("%02x ", substr($ +string,$i,1)); } print "\n";
    the result is: 01 02 03 04 05 06 the expectation was: 31 32 33 34 35 36 continuing, let's add the FS character to the string:
    $string .= pack('a', 0x1c); foreach (my $i=0; $i<length($string); $i++) { printf("%02x ", substr($ +string,$i,1)); } print "\n";
    the result is: 01 02 03 04 05 06 02 the expectation was: 31 32 33 34 35 36 1c (Further explanation: this is for use with serial communications of for sending into sockets) Thanks!!
Crash with ForkManager on Windows
6 direct replies — Read more / Contribute
by amitsq
on Sep 20, 2017 at 11:34

    I wrote a Link Checker, to check which Links are dead on a webpage. To get Server informations like Status Code and last modified Date, I used the head function of LWP::simple. Now this takes a lot of time. To speed up the process I’d like to run the processes simultaneous. I used the modul ForkManager and I am very impressed. It’s easy to use and fasten up the program. But it is not reliable. I have run the script multiple times to see the crash happens unregulary. Sometimes after 9 times of executions, then again after the first time, while in between it works fine and correct. The question is why?

    The Program crashes with a windows msg opening, saying “Perl Command Line Interpreter has been stop working”.

    If I click on show further informations, following Informations get shown:
    Problem signature: Problem Event Name: APPCRASH Application Name: perl.exe Application Version: Application Timestamp: 534c69c3 Fault Module Name: ntdll.dll Fault Module version: 6.1.7601.23864 Fault Module Timestamp: 595fa942 Exception Code: c0000022 Exception offset: 00000000000c8078 OS version: 6.1.7601. Locale ID: 1031 Additional Information 1: fdd8 Additional Information 2: fdd8457bc7039603b6dc9eb824e5dab9 Additional Information 3: 8044 Additional Information 4: 80447c7063d0a8ad48b87e45c4d37c4f
    Though I assume this is an incompatibility problem with lwp::Simple head function, because if I wouldn’t include it in the parallising process, it doesn’t crash so far. But this is also the point in the script, which takes the most time in processing. So I wonder if there is an error in my script or any working alternative? ( I already tried HTTP::Async, which I couldn’t get work at all).

    I use ActivePerl 64 bit (v5.16.3 built for MSWindows32-x64-multi-thread) on Windows Server 2008 R2 Standard.

    #!d:\perl\bin\perl.exe use LWP::Simple; use strict; use warnings; use Parallel::ForkManager; my $pm= new Parallel::ForkManager(8); #didn’t matter if it’s 1 or 5 o +r whatever else .. crash gets caused anyways foreach my $url ( 'http://us.a1.yimg.com/us.yimg.com/i/ww/m5v9.gif', 'http://hooboy.no-such-host.int/', 'http://www.yahoo.com', 'http://www.ora.com/ask_tim/graphics/asktim_header_main.gif', 'http://www.guardian.co.uk/', 'http://www.pixunlimited.co.uk/siteheaders/Guardian.gif' ) { $pm->start and next; my ($type, $length, $mod) = head($url); unless (defined $type) { print "$url is done \n"; ## I obviously reduced the output msgs $pm->finish; next; } if ($mod) { print "$url is done \n"; $pm->finish; } else { print "$url is done \n"; $pm->finish; } $pm->finish; } $pm->wait_all_children;
    Thanks for your time.
Download screenshot from website
3 direct replies — Read more / Contribute
by jeevansai
on Sep 20, 2017 at 10:30

    I am trying to download screenshots of different graphs present on some websites by simply clicking on the graph which is inside a tabbed pane.Is there any way i can achieve this,i tried taking screenshot using phantomjs but i do not have element selector.

XS linking problem
1 direct reply — Read more / Contribute
by frazap
on Sep 20, 2017 at 08:41
    I'm trying to replicate the example of a simple XS module given at https://www.lemoda.net/xs/xs-intro/geometry.html

    I have this send_string.cpp file

    #include "send_string.h" #include "stdio.h" void send_string (const wchar_t * str) { printf ("string\n"); }
    And the header send_string.h file is
    void send_string (const wchar_t * str);
    The package name is Kbh, and the Kbh.xs file is
    #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h" #include "send_string.h" MODULE = Kbh PACKAGE = Kbh PROTOTYPES: DISABLE void send_string(s) const wchar_t * s TYPEMAP: <<HERE const wchar_t * T_PV HERE
    My Makefile.pl is
    use ExtUtils::MakeMaker; WriteMakefile ( NAME => 'Kbh', VERSION_FROM => 'lib/Kbh.pm', OBJECT => 'Kbh.o send_string.o', )
    My lib/Kbh.pm file is
    package Kbh; our $VERSION = '0.01'; require XSLoader; XSLoader::load('Kbh', $VERSION); 1;
    When I run dmake I get the linking error "Kbh.o:Kbh.c:(.text+0x75): undefined reference to `send_string'"

    Thanks for any help


Merging worksheets in .xls in one Excel sheet
3 direct replies — Read more / Contribute
by machirajun
on Sep 20, 2017 at 08:28

    Hi I used below code to merger different .xlsx in on excel as separate sheets and trying to put the data in worksheets to one work sheet but I am able to write only one sheet data other sheets data I am able to read but not able write in Final.xls

    use Spreadsheet::XLSX; use Excel::Writer::XLSX; use Spreadsheet::WriteExcel; use Spreadsheet::BasicRead; (@file_list) = glob "*xlsx"; my $workbook = Excel::Writer::XLSX->new( 'Target.xlsx' ); foreach my $setoffiles (@file_list){ my $excel = Spreadsheet::XLSX -> new ("$setoffiles"); $worksheet = $workbook->add_worksheet(); foreach my $sheet (@{$excel -> {Worksheet}}) { $sheet -> {MaxRow} ||= $sheet -> {MinRow}; $sheet -> {MaxCol} ||= $sheet -> {MinCol}; foreach my $row ($sheet -> {MinRow} .. $sheet -> {MaxRow}) { foreach my $col ($sheet -> {MinCol} .. $sheet -> {MaxCol}) { my $cell = $sheet -> {Cells} [$row] [$col] ; if($cell){ $worksheet->write( $row, $col, $cell -> {Val}); } } } } } $workbook->close() or die "Error closing file: $!"; my $tlfile= "Target.xlsx"; my $WorkBook1 = Spreadsheet::WriteExcel->new('Final.xls'); my $Sheet1 = $WorkBook1->add_worksheet(); my $TL = new Spreadsheet::BasicRead($tlfile) || die "Could not open '$ ++tlfile': $!"; do { $TL->setRow(0); my $firstrow = $TL->getFirstRow(); $Sheet1->write_row(0, 0, $firstrow); while (my $nextrow = $TL->getNextRow()) { my $row = $TL->getRowNumber(); print "$row\n"; $Sheet1->write($row, 0, $nextrow); } }while ($TL->getNextSheet()); $WorkBook1 ->close() or die "Error closing file: $!";

    Please help

Accent file names issue
7 direct replies — Read more / Contribute
by ruimelo73
on Sep 20, 2017 at 06:41

    I'm portuguese and like so many people that live in countries with latin languages (portuguese, spanish, french, italian, etc) I have to deal with accent file names. Other non-latin languages have the same problem for sure (german, dutch, etc). The context here is Windows using NTFS drives, using Unicode to set up the files names. I'm using the latest perl version, that supports Unicode.

    For example, I have a directory/folder in "c:\users\someuser\documents" named "documentação" ("documentation" in english). The full path will be "c:\users\someuser\documents\documentação". Now, if I do this:

    use strict; our $dp; $dp = "c:\\Users\\someuser\\Documents\\documentação"; if (-d $dp) { print "ok\n"; } else { print "nope\n"; }

    It will return "nope"...
    If I change the text to "documenta\x{00E7}\x{00E3}o", it returns "ok"...
    Printing the string variable will show the same thing...
    If I use opendir/readdir in the "c:\users\someuser\documents" directory it will read "documentação" perfectly and -d will work fine...
    The -d simply does not work with the direct text on the string variable...
    If I add code to set the variable using command line argument in a dos console it will return "ok" also.

    I wasted hours reading unicode and perl documentation, and trying diferent methods (utf8, encoding, deconding, locale, etc) for correcting this, but nothing works. It is a problem with the way perl codifies the string internaly. I suppose that using some sort of perl command line option would do some thing that could solve the issue but this is not the way to resolve this.

    (post edited meanwhile, the solution I have found did not work)

    Unicode is a wonderful thing but reading about the evolution of Unicode you start thinking that Unicode is now on the same level of confusion to what happened to the ancient codepages... I hope that some one teachs me a lesson, or this sort of weirdness can be solved in future versions of perl.

    Thank you / Obrigado.

Seeking The Exceptionally Wise
1 direct reply — Read more / Contribute
by Kjetil
on Sep 20, 2017 at 04:32

    I would like to shout so that it is heard all over the Monastery: "Have anybody heard from the Exceptionally Wise Tobyink recently!?!?"

    As you may have noticed, Tobyink recently announced he was back from a hiatus, and indeed did contribute updates to his modules and shared his wisdom here. I was happy, because Tobyink is a friend and I have enjoyed his guidance, friendship and code. But since then, I have not heard from personally, even though I have emailed him several times and submitted pull requests.

    I have several things to contribute to his modules. They range from small additions to RDF::DOAP and Dist::Inkt::DOAP, to the need to adapt RDF::RDFa::Generator to the new Attean framework. The former are trivial, the latter requires large changes. Also HTML::HTML5::Parser have an urgent issue that I don't know what to do about really.

    If I had a co-maint role I could do it all myself, but I'd much prefer Tobyink's company.

    I therefore call on all monks to help.

VERSION format & compare
3 direct replies — Read more / Contribute
by perl-diddler
on Sep 19, 2017 at 17:48
    I wanted to make sure a changed library mod was included, so I bumped the version. My mod:
    package tlib; our $VERSION='0.0.3';
    The prog:
    #!/usr/bin/perl use warnings; use strict; use tlib '0.0.4';
    I get no error. I vaguely remember that I was told that as long as the version strings were of the same format -- like a quoted literal, or a 'v' string, they'd compare correctly (I thought).

    In fact, the problem seems to lie in the 'use-ing' prog. The version check works whether the module has quotes (or not), but the version check is ignored if the 'using' prog has a version in quotes in the same format as in the module.

    Why doesn't this work? I.e. if a prog that is using a module uses the same version format as is used in the module, why doesn't compare happen correctly?

    Does anyone think it would be worth asking for a "enhancement" on version checks to allow a quoted version string to work the same as if it was unquoted (or if it is in the same format used in the module)?

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.