Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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
Failure to cpanm PP on portable Strawberry Perl 24
2 direct replies — Read more / Contribute
by aplonis
on Jul 23, 2017 at 12:56

    Seeking a workaround for the failure of cpanm to install Tk::TableMatrix in Starwberry Perl v26, I thought to maybe try it out in a portable installation of Strawberrry Perl 24, and that worked. So, finding success, I next went to install also the module PP, which promply failed.

    The failure occurs here ...

    A:\PP>cpanm pp --> Working on pp Fetching +tar.gz ... OK Configuring PAR-Packer-1.037 ... OK ==> Found dependencies: Module::ScanDeps, Getopt::ArgvFile --> Working on Module::ScanDeps Fetching +.24.tar.gz ... OK Configuring Module-ScanDeps-1.24 ... OK Building and testing Module-ScanDeps-1.24 ... OK Successfully installed Module-ScanDeps-1.24 --> Working on Getopt::ArgvFile Fetching +1.11.tar.gz ... OK Configuring Getopt-ArgvFile-1.11 ... OK Building and testing Getopt-ArgvFile-1.11 ... OK Successfully installed Getopt-ArgvFile-1.11 Building and testing PAR-Packer-1.037 ...

    It fails with the pop-up herewith included. The pop-up occures six times in a row, like that over and over.

    The pop-up says...

    The procedure entry point _ZdlPvy could not be located in the dynamic link library C:\Strawberry\perl\bin\perl526.dll

    Just to be sure there was no confusion with cpanm from my installed Strawberry on the c: drive, I tried it again like below, (first insuring that my prior installs had really taken)...

    ---------------------------------------------- Welcome to Strawberry Perl Portable Edition! * URL - * see README.TXT for more info ---------------------------------------------- Perl executable: A:\PP\perl\bin\perl.exe Perl version : 5.24.2 / MSWin32-x64-multi-thread A:\PP>A:\PP\perl\bin\perl.exe -e "use Tk"; A:\PP>A:\PP\perl\bin\perl.exe -e "use Tk::TableMatrix"; A:\PP>A:\PP\perl\bin\cpanm.exe PP 'A:\PP\perl\bin\cpanm.exe' is not recognized as an internal or externa +l command, operable program or batch file. A:\PP>A:\PP\perl\bin\cpanm PP ! Finding PP on cpanmetadb failed. --> Working on PP Fetching +r.gz ... OK Configuring PDL-PP-0.010 ... N/A ! Configure failed for PDL-PP-0.010. See A:\PP\data\.cpanm\work\150082 +8689.4884\build.log for details. A:\PP>A:\PP\perl\bin\cpanm PAR::Packer --> Working on PAR::Packer Fetching +tar.gz ... OK Configuring PAR-Packer-1.037 ... OK Building and testing PAR-Packer-1.037 ...

    ...but results were as before.

Understanding endianness of a number
2 direct replies — Read more / Contribute
by stevieb
on Jul 23, 2017 at 11:07

    Hey all,

    I ran into a situation recently where I was reading from an I2C device, and the byte ordering was in the opposite endianness that I was expecting. Although I fixed the problem by reversing the bytes before returning them, I went off to research exactly what endian was. I've spent numerous hours testing, reading and more testing, but I still can't grasp it fully. I'm hoping just one or two more examples will have it 'click'.

    So, I'll start off with a couple of examples here to see if I have the basics down. Please feel free to elaborate with other examples or comments etc.

    Set up our number, and two byte scalars (full version copy/pastable at the bottom of the post):

    use warnings; use strict; use feature 'say'; my $num = 1023; # 0x03ff my ($b1, $b2);

    Now, if I do the following bit shifting, the printf() is printing the bytes in big endian format, correct?

    $b1 = ($num & 0xff00) >> 8; $b2 = $num & 0xff; printf("%x, %x\n", $b1, $b2); # 3, ff

    Likewise, if I reverse the operations/bytes, this one will print in little endian format, right?

    $b1 = $num & 0xff; $b2 = ($num & 0xff00) >> 8; printf("%x, %x\n", $b1, $b2); # ff, 3

    Full code:

    use warnings; use strict; use feature 'say'; my $num = 1023; my ($b1, $b2); $b1 = ($num & 0xff00) >> 8; $b2 = $num & 0xff; printf("%x, %x\n", $b1, $b2); $b1 = $num & 0xff; $b2 = ($num & 0xff00) >> 8; printf("%x, %x\n", $b1, $b2);
sub variables
4 direct replies — Read more / Contribute
by Todd Chester
on Jul 22, 2017 at 19:33
    Dear Perl Monks,

    In Perl 5, is there a way to name my variables in the () of the sub declaration, as I do in Perl 6?
    sub DoSomething( $DataStr ) {;}

    Many thanks, -T
Space inserted into output file
3 direct replies — Read more / Contribute
by He77e
on Jul 22, 2017 at 11:36

    Greetings Esteemed Monks,

    I am relatively new to Perl so this may be an easy fix.

    My script here is meant to import a CSV, parse, output a new string containing the elements in FASTA format into an array and write to a file.

    The problem I come across is that before each new entry a blank space (\s) is inserted; I assume the problem is with the way I am exporting the array to a file but I cannot find a method which deals with the problem.

    Any help? (script shown below)

    use Text::CSV; use Data::Dumper qw(Dumper); print "Enter file name: \n"; my $file = <STDIN>; chomp $file; print "Enter output file name: \n"; my $ofile = <STDIN>; my $csv = Text::CSV->new({ sep_char => ',' }); my @fasta; open(my $data, '<', $file) or die "Could not open '$file' $!\n"; while (my $line = <$data>) { chomp $line; if ($csv->parse($line)) { my @fields = $csv->fields(); #print Dumper \@fields; $fields[4]=~s/\s//gs; #removes spaces within the sequence push @fasta,"\>$fields[0]\_$fields[1]\_$fields[2]\_$fields[3]\n$ +fields[4]\n"; #outputs the correct format } else { warn "Line could not be parsed: $line\n"; } } #print Dumper \@fasta; open (FH,">$ofile"), print FH"@fasta", close; end;

    Sample input: (it is in TSV format but is read into the script anyway without a problem)


    Sample output: (note the \s added to every entry excluding the first)

    Any help would be greatly appreciated!
Passing hashes to sub
1 direct reply — Read more / Contribute
by PSP
on Jul 22, 2017 at 04:28
    my $loopCnt=0; my %prevsidstat=%{getSessStat()}; while (1) { debug("Sleeping for $ENV{SESSNAP_INTRVL}...\n"); sleep $ENV{SESSNAP_INTRVL}; my %cursidstat=%{getSessStat()}; if ((keys %cursidstat) != 0 ) { my $ComResult={sidStatComp(%prevsidstat,%cursidstat)}; my %prevsidstat=%cursidstat; } last; }

    Here I am getting hash reference when %{getSessStat()} is executed. Now I want to pass two hash references to sub to process them further, however just printing them in sub getting following error. Appreciate in advance for help. Odd number of elements in anonymous hash at line 65, <SQLPLUS> line 20.

    Sub code:
    #***************************************************** sub sidStatComp { #***************************************************** my (%prevsidstat,%cursidstat)=@_; print "Previous\n"; for my $instsid (keys %prevsidstat) { print "$instsid => $prevsidstat{$instsid}{SQLEXECINFO}\n"; } print "Current\n"; for my $instsid1 (keys %cursidstat) { print "$instsid1 => $cursidstat{$instsid1}{SQLEXECINFO}\n"; } return 1; }
need help downloading a file
2 direct replies — Read more / Contribute
by Todd Chester
on Jul 22, 2017 at 02:28

    Dear Perl Monks,

    I am trying to get this curl command to work with perl5:

    curl --header 'Host:' +FO.html/hw64_554.exe -o eraseme

    But no joy. Here is my test code.

    What am I doing wrong?

open and read text file
5 direct replies — Read more / Contribute
by hchana
on Jul 21, 2017 at 16:01

    I am trying to open and print the contents of a text file I've named 'Text1.txt' which is in my perl folder. I'm running the code below using Komodo on my Mac Book Pro but it is not working, I keep getting the message "/bin/sh: command not found". I'm new to Perl as they come, so could my error be explained in a simple manner. Thanks in advance.?

    #!/user/bin/perl open(FILE, "Text1.txt"); while(<FILE>){ print "I saw $_ in Text1.txt\n"; } close FILE;
Get TAP output when compiling Perl and running "make test"
1 direct reply — Read more / Contribute
by Rjevski
on Jul 21, 2017 at 15:53


    I am currently working on automating our Perl builds and I'd like to know how do I get the TAP output when I run make test so that the continuous integration system can pick up failures and display them nicely (manually going through a 5k line build log is not fun).

    I've already tried setting PERL_TEST_HARNESS_DUMP_TAP as well as HARNESS_OPTIONS but those have no effect when running through make for some reason.

    Steps to reproduce:

    curl +2 | tar -jxC /root cd /root/perl* ./Configure -des -Dprefix=/opt/perl-5.20.3 make -j $(nproc) make test

    I am running Perl 5.20.3 on Debian 9.0 amd64.


Tk::TableMatrix won't build on Strawberry 5.26.0
3 direct replies — Read more / Contribute
by aplonis
on Jul 21, 2017 at 09:17

    Running Strawberry version 5.26.0 on Win 10 Pro. And, alas, Tk::TableMatrix will not build. I get this error...

    Checking dependencies from MYMETA.json ... Checking if you have ExtUtils::MakeMaker 0 ... Yes (7.24) Checking if you have Tk 800.022 ... Yes (804.033) Building and testing Tk-TableMatrix-1.23 cp blib\lib\Tk\ AutoSplitting blib\lib\Tk\ (blib\lib\auto\Tk\TableMatrix +) cp TableMatrix/ blib\lib\Tk\TableMatrix\ cp TableMatrix/ blib\lib\Tk\TableMatrix\Spreadsh cd pTk && gmake gmake[1]: Entering directory 'C:/Users/gan/.cpanm/work/1500635987.1034 +8/Tk-TableMatrix-1.23/pTk' gmake[1]: *** No rule to make target '..\blib\arch\Tk\pTk\.exists', ne +eded by 'config'. Stop. gmake[1]: Leaving directory 'C:/Users/gan/.cpanm/work/1500635987.10348 +/Tk-TableMatrix-1.23/pTk' gmake: *** [Makefile:1171: pTk/libpTk.a] Error 2 -> FAIL Installing Tk::TableMatrix failed. See C:\Users\gan\.cpanm\wor +k\1500635987.10348\build.log for details. Retry with --force to force + install it.

    And --force also failed. Anyone know how to work through this?

blank pdf generated using PDF::API2
1 direct reply — Read more / Contribute
by lennelei
on Jul 21, 2017 at 02:46

    Hi all,

    I've a very small Perl script that splits PDF files bigger than 100 pages :

    use strict; use warnings; use PDF::API2; #...some code here... #for testing purpose: my $file='path_to_some.pdf'; # my $oldpdf = PDF::API2->open($file); if ($oldpdf->pages > 100) { my $newpdf = PDF::API2->new; printf " (%d pages)\n", $oldpdf->pages; for my $page_nb (1..10) { $newpdf->importpage($oldpdf, $page_nb); } $newpdf->saveas("_$file"); }

    I'm running this on Windows (Windows 7 for my desktop, Windows 2008/2012 for the servers) with a Strawberry Perl 5.14 and PDF::API2 module installed using cpan.bat

    It's working and used for weeks now without trouble until this week. With a pdf received a few days ago, the script output is a 100 blank pages document.

    I tried using the alternative with importPageIntoForm by snoopy from with the same result.

    I also tried another tool (sejda) and the pages are correctly extracted so it's probably an issue with PDF::API2 or a misconfiguration but I don't know what to add/change in the script.

    FYI, the sejda command line:

    sejda-console.bat extractpages -f SOURCE.PDF -o TARGET.PDF -s 1-100

    Any idea/alternative I could try? I'd like to keep the Perl as this is only a small part of a bigger script, but if I have no other option, I'll use sejda for the split.

    Unfortunately, I cannot provide the PDF :(

    Thank you

    Edit : I just found and tried with CAM::PDF using the following code and it's working!

    For what I've seen, the difference between both code is that PDF::API2->import_page function tries to copy the content of the pages where CAM::PDF->extractPages function removes the pages outside the given range. Maybe there is a similar method in PDF::API2 but I couldn't find it yet?

    use strict; use warnings; use CAM::PDF; #...some code here... #for testing purpose: my $file='path_to_some.pdf'; # my $oldpdf = CAM::PDF->new($file) or die "$CAM::PDF::errstr\n"; if ($oldpdf->numPages() > 100) { printf " (%d pages)\n", $oldpdf->numPages(); $oldpdf->extractPages(1..100); $oldpdf->cleanoutput("_$file"); }

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 all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (2)
    As of 2017-07-24 06:19 GMT
    Find Nodes?
      Voting Booth?
      I came, I saw, I ...

      Results (348 votes). Check out past polls.