http://qs321.pair.com?node_id=479

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
Installing Net::SCP::Expect - it can't find/install Expect
1 direct reply — Read more / Contribute
by mrkrinkle
on Apr 08, 2020 at 19:14

    I'm running Ubuntu 18.04.2

    This is perl 5, version 26, subversion 1 (v5.26.1) built for x86_64-linux-gnu-thread-multi (with 67 registered patches, see perl -V for more detail)

    I have make installed (all I did was sudo apt-get update; sudo apt-get install make).

    I installed CPAN according to this:

    https://how-to.fandom.com/wiki/How_to_install_PERL_modules

    The first line

    perl -MCPAN -e install Net::SCP::Expect

    seems to have only install cpan (well MCPAN is what it's called now)?

    So then I did:

    sudo perl -MCPAN -e shell

    And "install Net::SCP::Expect"

    It ended with this:

    Test Summary Report ------------------- t/01-test.t (Wstat: 512 Tests: 0 Failed: 0) Non-zero exit status: 2 Parse errors: Bad plan. You planned 14 tests but ran 0. t/02-bc.t (Wstat: 512 Tests: 0 Failed: 0) Non-zero exit status: 2 Parse errors: No plan found in TAP output t/03-log.t (Wstat: 512 Tests: 0 Failed: 0) Non-zero exit status: 2 Parse errors: Bad plan. You planned 11 tests but ran 0. t/04-multiline.t (Wstat: 512 Tests: 0 Failed: 0) Non-zero exit status: 2 Parse errors: Bad plan. You planned 33 tests but ran 0. t/10-internal.t (Wstat: 512 Tests: 0 Failed: 0) Non-zero exit status: 2 Parse errors: Bad plan. You planned 17 tests but ran 0. t/11-calc.t (Wstat: 512 Tests: 0 Failed: 0) Non-zero exit status: 2 Parse errors: No plan found in TAP output Files=6, Tests=0, 1 wallclock secs ( 0.03 usr 0.00 sys + 0.27 cusr + 0.06 csys = 0.36 CPU) Result: FAIL Failed 6/6 test programs. 0/0 subtests failed. Makefile:883: recipe for target 'test_dynamic' failed make: *** [test_dynamic] Error 2 JACOBY/Expect-1.35.tar.gz make test -- NOT OK //hint// to see the cpan-testers results for installing this module, t +ry: reports JACOBY/Expect-1.35.tar.gz RYBSKEJ/Net-SCP-Expect-0.16.tar.gz Has already been unwrapped into directory /home/bog/.cpan/build/Net- +SCP-Expect-0.16-2 RYBSKEJ/Net-SCP-Expect-0.16.tar.gz Has already been prepared Running make for R/RY/RYBSKEJ/Net-SCP-Expect-0.16.tar.gz Warning: Prerequisite 'Expect => 1.14' for 'RYBSKEJ/Net-SCP-Expect-0.1 +6.tar.gz' failed when processing 'JACOBY/Expect-1.35.tar.gz' with 'ma +ke_test => NO'. Continuing, but chances to succeed are limited. cp Expect.pm blib/lib/Net/SCP/Expect.pm Manifying 1 pod document RYBSKEJ/Net-SCP-Expect-0.16.tar.gz make -- OK Running make test PERL_DL_NONLAZY=1 "/usr/bin/perl" "-MExtUtils::Command::MM" "-MTest::H +arness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/l +ib', 'blib/arch')" t/*.t t/attributes.t .... ok t/glob.t .......... ok t/signature.t ..... skipped: Set the environment variable TEST_SIGNATU +RE to enable this test. t/string_parse.t .. ok All tests successful. Files=4, Tests=54, 0 wallclock secs ( 0.03 usr 0.00 sys + 0.26 cusr + 0.03 csys = 0.32 CPU) Result: PASS RYBSKEJ/Net-SCP-Expect-0.16.tar.gz Tests succeeded but one dependency not OK (Expect) RYBSKEJ/Net-SCP-Expect-0.16.tar.gz [dependencies] -- NA Failed during this command: TODDR/IO-Tty-1.14.tar.gz : writemakefile NO '/usr +/bin/perl Makefile.PL INSTALLDIRS=site' returned status 6400 JACOBY/Expect-1.35.tar.gz : make_test NO RYBSKEJ/Net-SCP-Expect-0.16.tar.gz : make_test NO one depen +dency not OK (Expect)
    I could give you the whole output if you want. What am I doing wrong? I'm not doing anything else with perl right now. (I mean Ubuntu probably is somewhere but that's all standard stuff.)
Convert JSON to Perl and back with unicode
1 direct reply — Read more / Contribute
by bliako
on Apr 08, 2020 at 18:16

    Hello Monks,

    I am struggling to make either of Data::Dump or Data::Dumper to print rendered(?) unicode characters rather than those ugly escapes but I can't seem to succeed. Perl prints them nicely but dump and dumper escape.

    use utf8; binmode STDOUT, ':encoding(UTF-8)'; use Data::Dumper; use Data::Dump qw/pp/; my $pv = {'&#945;&#946;&#947;' => '&#967;&#968;&#950;'}; #<<<proper gr +eek key and value print pp($pv)."\n"; print Dumper($pv); print "XX:'".$pv->{'&#945;&#946;&#947;'}."'\n"; # proper greek nicely +printed # madness: { "\x{3B1}\x{3B2}\x{3B3}" => "\x{3C7}\x{3C8}\x{3B6}" } $VAR1 = { "\x{3b1}\x{3b2}\x{3b3}" => "\x{3c7}\x{3c8}\x{3b6}" }; # nicely printed XX:'&#967;&#968;&#950;' #<<<< that's proper greek

    thanks, bliako

    Edit: sorry, I did not mention JSON (thanks haukex for reminding me). What I am trying to do is to visualise a long JSON by converting it to a Perl var and then possibly edit the perl var, and finally save back to JSON (with the changes). So, yes, actually I am serialising and de-serialising but I can't seem to find an ascii-text-based, unicode-friendly serialiser other than Dump and Dumper. And for me, YAML is too tiring with all that spaces. Or I am just used to nested Perl data.

    So, the input and output are JSON. Long JSON with unicode. I want to edit that JSON too. But it's too cumbersome in a text-based editor. And so I prefer to covert JSON to Perl, edit the Perl and then convert back to JSON. My procedure/tool was working until some unicode broke it.

Tk Listbox item padx
2 direct replies — Read more / Contribute
by Anonymous Monk
on Apr 08, 2020 at 16:42

    Hello monks

    Is there a way to set a horizontal padding to the items inserted in a ListBox? I want the item text to be some pixel away from the border of the ListBox container. I couldn't find any option to do this ($listbox->itemconfigure is limited to a couple of options). Thank you for any suggestion.

PDF::API2 behaving differently on two computers?
2 direct replies — Read more / Contribute
by trillich
on Apr 08, 2020 at 13:42

    Having issues with PDF::API2. We are creating PDF output starting with a watermark/background (lines for the form and a bitmap logo) and then overlay text on top. The database text overlay never has any trouble. It's the background PDF we are wrestling with.

    Computer 1: template.pdf is read in by the script, we overlay the text, all is well with the generated PDF. The background form and logo show up with the text on top, just as expected.

    Computer 2: template.pdf is read in by the script, and only part of it renders properly in the final PDF. The overlay text renders just fine, so I don't think the PDF gets entirely corrupted. The template files are identical on both computers.

    #1 has PDF::API2 version 2.023 and #2 has 2.033, so I thought maybe I could downgrade. But testing with v2.023 on #2 has the same problem.

    Experimented with dozens of variations on the template file. Made a simple 3-rectangle background in Illustrator as the template, and that worked fine. Added a white blob with bezier curves on top of the rectangles, updated the template, and then none of the rectangles showed up, either, as if the whole template was empty. Removed the blob and added a white oval (which is also bezier curves), and that worked 100% fine. So far I can't find the pattern.

    So I'm concluding that somewhere between my $bg = $pdf->importPageIntoForm( $bg, 1 ); and $page->gfx->formimage( $bg, 0, 0, 1.0 ) something is going south on #2 but not on #1. Right?

    Suggestions on how to troubleshoot this are welcome. :/

.VCF records cleansing
3 direct replies — Read more / Contribute
by solocazzimiei
on Apr 08, 2020 at 05:51
    Hi to all, ...and sorry for bad post formatting but PerlMonks seems don't recornize \n statement..

    Here we are: after had accumulate lots of .vcf files were inside of each are plenty of duplicated records, I'm working on custom script for rationalize,merging & cleansing over 700k records.

    I stuck on find universal solution for splits fields from records like this :

    $in[$x]="NOTE;ENCODING=QUOTED-PRINTABLE:=0AAddress:=0A=0Aor. Soroca=0A +Republic of Moldova=0A=0A=0A=0A Footwear. =Children's footwear. Lady' +s footwear."

    using code like:

    $in[$x] =~ /(\w+\W?\w*\W?\w*\W?\w*\W?\w*\W?\w*\W*?\w*\W*?\w*\W*?\w*)\: +(=?0?.+:*)/; $a =$1;$2; $a =~ s/;X-SYNCMLREF\d+//; $key{$a} = $a;
    This script work fine on almost the VCF's lables like : N, FN, ORG, TEL, etc.. but in record frame like above I obtain splitting on the lastest \: instead of first one, despite use of non greedy techniques:
    $1 = "NOTE;ENCODING=QUOTED-PRINTABLE:=0AAddress" $2 = "=0A=0Aor. Soroca=0ARepublic of Moldova=0A=0A=0A=0A Footwear. =Ch +ildren's footwear. Lady's footwear."
    Any suggestions ? Thks
Where is documenation for defining servers for use by Rex?
3 direct replies — Read more / Contribute
by nysus
on Apr 07, 2020 at 17:24

    I'm having trouble locating documentation that explains how to set up servers for use in Rex scripts. Can someone please point me in the right direction? Thanks.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

Override new in Moose for flyweight objects
2 direct replies — Read more / Contribute
by Aaronrp
on Apr 07, 2020 at 14:15

    I've found the module MooseX::Role::Flyweight a useful one for keeping a cache of objects, but I've never been happy with the way it requires you to use Class->instance(y => 'x') instead of Class->new(y => 'x') to get the new object. What if I change my mind about caching, or want to debug the code without the cache? Then I have to find all the calls in all my code and change them. What if I miss one, and call new from outside the class? So much for the cache.

    I came up with this alternative approach, which seems to work. It overrides Moose's new method but still inlines the constructor.

    package TestNew 0.001; use Moose; has thingy => ( required => 1, is => 'ro', ); my %obj_cache; override 'new' => sub { my ( $class, @args ) = @_; my $params = $class->BUILDARGS(@args); # from Moose::Object my $thingy = $params->{thingy}; my $cachekey = $thingy; if ( exists $obj_cache{$cachekey} ) { return $obj_cache{$cachekey}; } return $obj_cache{$thingy} = $class->_new( thingy => $thingy ); }; *Moose::Object::_new = \&Moose::Object::new; __PACKAGE__->meta->make_immutable( constructor_name => '_new' ); 1;

    Other than the unfortunate need to mess around inside the Moose::Object namespace, I don't see any huge downsides, but I must admit I don't really know what I'm looking at when I poke around inside Class::MOP::Class and was wondering if others had thoughts.

    Thanks,

Parsing Emacs Lisp sexpr?
3 direct replies — Read more / Contribute
by perlancar
on Apr 07, 2020 at 13:41
    Wondering if there's something on CPAN or elsewhere which can parse the contents of https://melpa.org/packages/archive-contents into a reasonable Perl representation? I think Data::SExpression chokes on bracket character and that module seems to be pretty much what CPAN has to offer for something relating to parsing S-expression. I guess whipping up a new parser is not hard...
Invokes perl modules from perl script in different perl versions
2 direct replies — Read more / Contribute
by maria80e
on Apr 07, 2020 at 13:33

    We have two versions of Active perl 5.6 and 5.24. We have web services which is written as perl modules to be executed on Active perl '5.24' versions(to adopt TLS 1.2 version) and this needs to be invoked from Active perl '5.6' version.

    Is there any feasibility to do the following Main Program runs on 5.6 version perl modules to be executed in 5.24 version Perl modules are invoked by main program which runs on 5.6 version.

    For the below example,

    Example:-

    TestMain.pl (5.6 version) use webser; my $result = qx{C:/Perl_524/bin/perl.exe D:/webser.pm};

    Expected Result: the expected result is Main program which runs on 5.6 invokes the perl module which has to be run on 5.24 version and returns the result.

    During the execution we noticed that the perl modules runs on 5.6 instead of executing on 5.24.

    Note:

    1. The input paramter for the web services are binded in the object created for the module

    2. we tried system command too and its not worked as expected

    3. Perl modules returns the response of the webservice to the main program

    4. Having two versions of a perl is a work around and later we upgrade it into higher version

    5. Working on windows platform

Not finding NDBM_File.pm
2 direct replies — Read more / Contribute
by dirtdog
on Apr 07, 2020 at 12:47

    Hi Monks, I'm stumped as to why the NDBM_File.pm module is not being found even though i see it in the Oracle perl package version v5.22.0

    ..oracle/product/12.2.0.1/perl/lib/5.22.0/Memoize>ls -ltr NDBM_File.pm -rwxr-xr-x 1 oracle dba 1488 May 12 2016 NDBM_File.pm

    ..oracle/product/12.2.0.1/perl/lib/5.22.0 is in my PERL5LIB dir and when i run perl -V i see the following dirs:

    /.../oracle/product/12.2.0.1/perl/lib/site_perl/5.22.0/x86_64-linux-thread-multi .../oracle/product/12.2.0.1/perl/lib/site_perl/5.22.0 .../oracle/product/12.2.0.1/perl/lib/site_perl/5.22.0/x86_64-linux-thread-multi .../oracle/product/12.2.0.1/perl/lib/site_perl/5.22.0 .../oracle/product/12.2.0.1/perl/lib/5.22.0/x86_64-linux-thread-multi .../oracle/product/12.2.0.1/perl/lib/5.22.0

    yet i get this error:

    Can't locate NDBM_File.pm in @INC (you may need to install the NDBM_File module) (@INC contains: /.../oracle/product/12.2.0.1/perl/lib/site_perl/5.22.0/x86_64-linux-thread-multi /.../oracle/product/12.2.0.1/perl/lib/site_perl/5.22.0 /.../oracle/product/12.2.0.1/perl/lib/5.22.0/x86_64-linux-thread-multi /.../oracle/product/12.2.0.1/perl/lib/5.22.0 /.../oracle/product/12.2.0.1/perl/lib/site_perl/5.22.0/x86_64-linux-thread-multi /.../oracle/product/12.2.0.1/perl/lib/site_perl/5.22.0 /.../oracle/product/12.2.0.1/perl/lib/5.22.0/x86_64-linux-thread-multi /.../oracle/product/12.2.0.1/perl/lib/5.22.0 .). BEGIN failed--compilation aborted.

    Perms are ok so it's definitely not that.

    Any help would be greatly appreciated!

    thanks


Add your question
Title:
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.