Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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
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
No replies — Read more | Post response
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

Connecting to remove server with Rex using .pem file
1 direct reply — Read more / Contribute
by nysus
on Apr 07, 2020 at 10:25

    I'm stumped trying to figure out how to use Rex to log into a remote server. The server provides me with a .pem file. I have successfully used this file to log in manually using ssh -i PEM_FILE_NAME blah@111.222.222.123.

    I tried converting it to public key with ssh-keygen -y -f PEM_FILE_NAME > public.key and have the following in my RexFile:

    Rex::connect( server => '111.222.222.123', user => 'my_user_name', public_key => '/home/my_user_name/public.key', );

    But this isn't working. Not sure what else to try. 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


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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (6)
    As of 2020-04-08 23:21 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      The most amusing oxymoron is:
















      Results (46 votes). Check out past polls.

      Notices?