Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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
what is "milliBarr"?
1 direct reply — Read more / Contribute
by morgon
on May 26, 2018 at 12:28
    Hi

    reading through the comments on https://log.perl.org/2018/05/goodbye-search-dot-cpan-dot-org.html I came across this:

    there's an old term in Perl, the 'milliBarr' which applies to Graham's particular style.
    "Graham" referring to Graham Barr.

    As I've never heard that "old" term before: Does anybody have any clue what it refers to?

    Many thanks!

Post using LWP useragent curl post request to useragent request
2 direct replies — Read more / Contribute
by smarthacker67
on May 25, 2018 at 17:31
    Hi Monks I am trying to create equivalent post request using LWP::Useragent
    curl ENDPOINT \ -H "Authorization: Bearer ACCESS_TOKEN" -X POST \ -F attributes='{"name":"test.txt", "parent":{"id":"0"}}' \ -F file=@test.txt
    my request looks like this
    my $json = encode_json {"name" => "test.txt", "parent" => {"id" => 0}} +; my $resp = $ua->post( ENDPOINT , {file => <$fh> ,'attributes'=>$json }, 'Authorization' => 'Bearer ' . $token , Content_Type => 'multipart/form-data' . );
    but not working getting 400 response Can some one help me. I am actually trying to upload the file to the endpoint with the curl I am able to but looking for equivalent LWP useragent request.
Looking for combinatorics with state
6 direct replies — Read more / Contribute
by Anonymous Monk
on May 25, 2018 at 16:19
    I'm working a a password recovery program and make use of various combinatorics libraries (Algorithm::Combinatorics, Algorithm::Permute, Set::Product). Depending upon the input, the program can run for days or weeks. I often wish that I could restart a job from a saved state or distribute the processing to multiple machines, but none of these libraries provide access to their state. In fact, I couldn't find a combinatorics library in any language that does. I would think this is not an uncommon task. Is it not easy to accomplish or not possible?
Segfault in Glib/Gtk2 script
3 direct replies — Read more / Contribute
by Anonymous Monk
on May 25, 2018 at 09:24

    I'm getting a segfault which remains impervious to analysis. Perhaps someone can point me in the right direction?

    My Perl script is billions of lines long and all attempts to reproduce the segfault in a shorter script have failed. The general format is:

    use strict; use diagnostics; use warnings; use Glib qw(TRUE FALSE); BEGIN { require 5.008; use Archive::Extract; use Archive::Tar; use Compress::Zlib; use Encode qw(decode encode encodings find_encoding from_to); use Fcntl qw(:flock); use File::Basename; use File::Copy qw(copy move); use File::Copy::Recursive qw(dirmove); use File::Fetch; use File::Find; use File::HomeDir qw(my_home); use File::Path qw(remove_tree); use File::ShareDir ':ALL'; use File::ShareDir::Install; use Gnome2::Canvas; use Gnome2::Wnck; use Gtk2 '-init'; use Gtk2::Ex::Simple::List; use IO::Socket::INET; use IO::Socket::INET6; use IO::Socket::SSL; use IPC::Run qw(start); use JSON; use Math::Trig; use Module::Load qw(load); use Net::OpenSSH; use POSIX qw(ceil); use Regexp::IPv6 qw($IPv6_re); use Safe; use Scalar::Util qw(looks_like_number); use Socket qw(AF_INET SOCK_STREAM inet_aton sockaddr_in); use Symbol qw(qualify); use Storable qw(lock_nstore lock_retrieve); use Time::HiRes qw(gettimeofday); } sub hello_world(); Gtk2->main(); END { }

    What I know so far:

    • The SIGSEGV signal is emitted after the perl 'exit' statement, and after all END {} blocks have been executed
    • Changing 'required 5.008' to any later version does not help
    • Swapping systems between Debian, Ubuntu, Linux Mint, Win 7 (32bit) and Win10 (64bit) does not help
    • Calling 'Gtk->main_quit()' before 'exit' does not help
    • Doing 'Gtk2->main_iteration() while Gtk2->events_pending()' before 'exit' does not help
    • Using 'use Gtk2 qw/-init -threads-init/; Glib::Object->set_threadsafe (1);' does not help

    Devel::Trace produces this output:

    $ perl -d:Trace script.pl >trace 2>&1 >> lib/script.pm:6198: exit; >> /usr/share/perl/5.22/File/Temp.pm:731: local($., $@, $!, $^E, $ +?); >> /usr/share/perl/5.22/File/Temp.pm:732: cleanup(at_exit => 1); >> /usr/share/perl/5.22/File/Temp.pm:738: my %h = @_; >> /usr/share/perl/5.22/File/Temp.pm:739: my $at_exit = delete $h{ +at_exit}; >> /usr/share/perl/5.22/File/Temp.pm:740: $at_exit = 0 if not defi +ned $at_exit; >> /usr/share/perl/5.22/File/Temp.pm:741: { my @k = sort keys %h; +die "unrecognized parameters: @k" if @k } >> /usr/share/perl/5.22/File/Temp.pm:741: { my @k = sort keys %h; +die "unrecognized parameters: @k" if @k } >> /usr/share/perl/5.22/File/Temp.pm:741: { my @k = sort keys %h; +die "unrecognized parameters: @k" if @k } >> /usr/share/perl/5.22/File/Temp.pm:743: if (!$KEEP_ALL) { >> /usr/share/perl/5.22/File/Temp.pm:746: @{ $files +_to_unlink{$$} } : () ); >> /usr/share/perl/5.22/File/Temp.pm:747: foreach my $file (@fil +es) { >> /usr/share/perl/5.22/File/Temp.pm:761: @{ $dirs_t +o_unlink{$$} } : () ); >> /usr/share/perl/5.22/File/Temp.pm:762: my ($cwd, $cwd_to_remo +ve); >> /usr/share/perl/5.22/File/Temp.pm:763: foreach my $dir (@dirs +) { >> /usr/share/perl/5.22/File/Temp.pm:783: if (defined $cwd_to_re +move) { >> /usr/share/perl/5.22/File/Temp.pm:795: if exists $files_to_ +unlink{$$}; >> /usr/share/perl/5.22/File/Temp.pm:797: if exists $dirs_to_u +nlink{$$};

    GDB produces this output:

    (gdb) run Starting program: /usr/bin/perl script.pl [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so +.1". [New Thread 0x7fffe5602700 (LWP 13152)] [New Thread 0x7fffe4e01700 (LWP 13153)] Thread 1 "perl" received signal SIGSEGV, Segmentation fault. emission_find (instance=0x116dfdf0, detail=0, signal_id=11) at /build/glib2.0-prJhLS/glib2.0-2.48.2/./gobject/gsignal.c:824 824 /build/glib2.0-prJhLS/glib2.0-2.48.2/./gobject/gsignal.c: No su +ch file or directory. (gdb) bt #0 0x00007ffff6949820 in signal_emit_unlocked_R (instance=0x116dfdf0, + detail=0, signal_id=11) at /build/glib2.0-prJhLS/glib2.0-2.48.2/./go +bject/gsignal.c:824 #1 0x00007ffff6949820 in signal_emit_unlocked_R (node=node@entry=0x24 +9d070, detail=detail@entry=0, instance=instance@entry=0x116dfdf0, emi +ssion_return=emission_return@entry=0x0, instance_and_params=instance_ +and_params@entry=0x7fffffffd7d0) at /build/glib2.0-prJhLS/glib2.0-2.4 +8.2/./gobject/gsignal.c:3513 #2 0x00007ffff6952d5c in g_signal_emit_valist (instance=<optimised ou +t>, signal_id=<optimised out>, detail=<optimised out>, var_args=var_a +rgs@entry=0x7fffffffd980) at /build/glib2.0-prJhLS/glib2.0-2.48.2/./g +object/gsignal.c:3385 #3 0x00007ffff695308f in g_signal_emit (instance=instance@entry=0x116 +dfdf0, signal_id=<optimised out>, detail=detail@entry=0) at /build/glib2.0-prJhLS/glib2.0-2.48.2/./gobject/gsignal.c:3441 #4 0x00007fffefb72db0 in gtk_object_dispose (gobject=0x116dfdf0 [GtkT +extView]) at /build/gtk+2.0-jJZIsQ/gtk+2.0-2.24.30/gtk/gtkobject.c:421 #5 0x00007ffff693cd25 in g_object_unref (_object=0x116dfdf0) at /build/glib2.0-prJhLS/glib2.0-2.48.2/./gobject/gobject.c:3146 #6 0x00007ffff6b9ae4a in () at /usr/lib/x86_64-linux-gnu/perl5/5.22/auto/Glib/Glib.so #7 0x00000000004bd45a in Perl_pp_entersub () #8 0x000000000043c2a8 in Perl_call_sv () #9 0x00000000004c1e03 in () #10 0x00000000004c2840 in Perl_sv_clear () #11 0x00000000004c2afd in Perl_sv_free2 () #12 0x00000000004c0c7b in () #13 0x00000000004c2eb4 in Perl_sv_clean_objs () #14 0x000000000043ee8b in perl_destruct () #15 0x000000000041caf3 in main ()

    Valgrind produces this output:

    ==12589== Process terminating with default action of signal 11 (SIGSEG +V) ==12589== General Protection Fault ==12589== at 0x88B7820: signal_emit_unlocked_R (in /usr/lib/x86_64- +linux-gnu/libgobject-2.0.so.0.4800.2) ==12589== by 0x88C0D5B: g_signal_emit_valist (in /usr/lib/x86_64-li +nux-gnu/libgobject-2.0.so.0.4800.2) ==12589== by 0x88C108E: g_signal_emit (in /usr/lib/x86_64-linux-gnu +/libgobject-2.0.so.0.4800.2) ==12589== by 0x11102DAF: gtk_object_dispose (gtkobject.c:421) ==12589== by 0x88AAD24: g_object_unref (in /usr/lib/x86_64-linux-gn +u/libgobject-2.0.so.0.4800.2) ==12589== by 0x865DE49: ??? (in /usr/lib/x86_64-linux-gnu/perl5/5.2 +2/auto/Glib/Glib.so) ==12589== by 0x4BD459: Perl_pp_entersub (in /usr/bin/perl) ==12589== by 0x43C2A7: Perl_call_sv (in /usr/bin/perl) ==12589== by 0x4C1E02: ??? (in /usr/bin/perl) ==12589== by 0x4C283F: Perl_sv_clear (in /usr/bin/perl) ==12589== by 0x4C2AFC: Perl_sv_free2 (in /usr/bin/perl) ==12589== by 0x4C0C7A: ??? (in /usr/bin/perl) ==12589== ==12589== HEAP SUMMARY: ==12589== in use at exit: 272,606,526 bytes in 979,458 blocks ==12589== total heap usage: 3,010,187 allocs, 2,030,729 frees, 688,1 +61,553 bytes allocated ==12589== ==12589== LEAK SUMMARY: ==12589== definitely lost: 28,167 bytes in 595 blocks ==12589== indirectly lost: 35,893 bytes in 1,366 blocks ==12589== possibly lost: 173,410,130 bytes in 272,130 blocks ==12589== still reachable: 98,192,416 bytes in 699,586 blocks ==12589== of which reachable via heuristic: ==12589== length64 : 12,696 bytes in + 174 blocks ==12589== newarray : 828,744 bytes i +n 26,261 blocks ==12589== suppressed: 0 bytes in 0 blocks ==12589== Rerun with --leak-check=full to see details of leaked memory ==12589== ==12589== For counts of detected and suppressed errors, rerun with: -v ==12589== Use --track-origins=yes to see where uninitialised values co +me from ==12589== ERROR SUMMARY: 57 errors from 19 contexts (suppressed: 0 fro +m 0)
mod_perl-2.0.ppd installation failed
1 direct reply — Read more / Contribute
by Nedzad G
on May 25, 2018 at 02:53

    When I try to install a mod_perl-2.0.ppd I am getting this error:

    ppm install failed: 500 Can't connect to theoryx5.unwinnipeg.ca:80 (nodename nor servername provided, or not know)

    I am using Active perl version 5.24.3. Can anyone help to fix this ?

I want to remove duplicate based on specific column and value.
3 direct replies — Read more / Contribute
by EBK
on May 25, 2018 at 02:14
    Hello Guys, I need your help I have no idea where to start. I want to remove duplicate based on specific column and value. This file below. There are a lot of rows.
    key_683,march,29031990,ABCD_FH,9,9 key_684,march,29031990,ABCD_FH,9,9 key_685,march,29031990,ABCD_FH,9,9 key_686,march,29031990,ABCD_FH,9,9 key_687,march,29031990,ABCD_FH,9,9 key_688,march,29031990,ABCD_FH,9,9 key_689,march,29031990,ABCD_FH,9,9 key_693,march,29031990,ABCD_FH,9,9 key_694,march,29031990,ABCD_FH,9,9 key_683,march,29031990,ABCD_H + ABC_F,8,17 key_684,march,29031990,ABCD_H + ABC_F,8,17 key_685,march,29031990,ABCD_H + ABC_F,8,17 key_686,march,29031990,ABCD_H + ABC_F,8,17 key_687,march,29031990,ABCD_H + ABC_F,8,17 key_688,march,29031990,ABCD_H + ABC_F,8,17 key_689,march,29031990,ABCD_H + ABC_F,8,17 key_690,march,29031990,ABCD_H + ABC_F,8,17 key_691,march,29031990,ABCD_H + ABC_F,8,17 key_692,march,29031990,ABCD_H + ABC_F,8,17 key_693,march,29031990,ABCD_H + ABC_F,8,17 key_694,march,29031990,ABCD_H + ABC_F,8,17 key_695,march,29031990,ABCD_H + ABC_F,8,17 key_696,march,29031990,ABCD_H + ABC_F,8,17 key_697,march,29031990,ABCD_H + ABC_F,8,17 key_698,march,29031990,ABCD_H + ABC_F,8,17 key_699,march,29031990,ABCD_H + ABC_F,8,17 key_683,march,29031990,ABC_H + AB_F,2,19 key_684,march,29031990,ABC_H + AB_F,2,19 key_685,march,29031990,ABC_H + AB_F,2,19 key_686,march,29031990,ABC_H + AB_F,2,19 key_687,march,29031990,ABC_H + AB_F,2,19 key_688,march,29031990,ABC_H + AB_F,2,19 key_689,march,29031990,ABC_H + AB_F,2,19 key_690,march,29031990,ABC_H + AB_F,2,19 key_691,march,29031990,ABC_H + AB_F,2,19 key_692,march,29031990,ABC_H + AB_F,2,19 key_693,march,29031990,ABC_H + AB_F,2,19 key_694,march,29031990,ABC_H + AB_F,2,19 key_695,march,29031990,ABC_H + AB_F,2,19 key_696,march,29031990,ABC_H + AB_F,2,19 key_697,march,29031990,ABC_H + AB_F,2,19 key_698,march,29031990,ABC_H + AB_F,2,19 key_699,march,29031990,ABC_H + AB_F,2,19 key_700,march,29031990,ABC_H + AB_F,2,19 key_701,march,29031990,ABC_H + AB_F,2,19
    The column 0 there is a unique key and I have groups of keys. I need to print the difference between them. For example my group 1 is ABCD_FH. So I want to print 9 positions of group ABCD_FH and reserved them. key_683 up to key_694.
    key_683,march,ABCD_FH,9,9 key_684,march,ABCD_FH,9,9 key_685,march,ABCD_FH,9,9 key_686,march,ABCD_FH,9,9 key_687,march,ABCD_FH,9,9 key_688,march,ABCD_FH,9,9 key_689,march,ABCD_FH,9,9 key_693,march,ABCD_FH,9,9 key_694,march,ABCD_FH,9,9
    Now is the magic, the group 1 I will use the keys I have reserved and print the leftovers from group 2 - ABCD_H + ABC_F and printing
    key_690,march,ABCD_H + ABC_F,8,17 key_691,march,ABCD_H + ABC_F,8,17 key_692,march,ABCD_H + ABC_F,8,17 key_695,march,ABCD_H + ABC_F,8,17 key_696,march,ABCD_H + ABC_F,8,17 key_697,march,ABCD_H + ABC_F,8,17 key_698,march,ABCD_H + ABC_F,8,17 key_699,march,ABCD_H + ABC_F,8,17
    And the group 3 the leftovers from group 1 and group 2,
    key_700,march,ABC_H + AB_F,2,19 key_701,march,ABC_H + AB_F,2,19
    So my final file will be.
    key_683,march,ABCD_FH,9,9 key_684,march,ABCD_FH,9,9 key_685,march,ABCD_FH,9,9 key_686,march,ABCD_FH,9,9 key_687,march,ABCD_FH,9,9 key_688,march,ABCD_FH,9,9 key_689,march,ABCD_FH,9,9 key_693,march,ABCD_FH,9,9 key_694,march,ABCD_FH,9,9 key_690,march,ABCD_H + ABC_F,8,17 key_691,march,ABCD_H + ABC_F,8,17 key_692,march,ABCD_H + ABC_F,8,17 key_695,march,ABCD_H + ABC_F,8,17 key_696,march,ABCD_H + ABC_F,8,17 key_697,march,ABCD_H + ABC_F,8,17 key_698,march,ABCD_H + ABC_F,8,17 key_699,march,ABCD_H + ABC_F,8,17 key_700,march,ABC_H + AB_F,2,19 key_701,march,ABC_H + AB_F,2,19
[OT] What is 'Good Practice' use of an .ini/.conf file: Database or Active Document?
4 direct replies — Read more / Contribute
by ozboomer
on May 25, 2018 at 00:30

    Howdy, all..

    Not really a Perl question :(... but I don't know how to even title my query...

    There's a text file with lots of sections in it, like an '.ini/.conf' file. Each section can be 'used' or 'unused' by its application.

    Some folk want to use the text file as 'storage', keeping ALL possible items in it, even though they're not in current use (a database); others call it an 'active document' that should only contain 'in-use' sections.

    Is there a recognized/recommended 'good practice' for this sort of thing?

    Thanks for any thoughts...

XS unpackstring, flags and useage
1 direct reply — Read more / Contribute
by coyocanid
on May 24, 2018 at 19:09
    Hello Honored Geschwistern,

    I am working on a perl XS project and would like to use unpack in the XS/C portion of the code. (Using pack in the perl portion seems to do what I want).

    I'm reading the API documents for unpackstring and have some questions questions

    • What are the flags that are allowed? I've been searching in vain
    • The documentation says that the results are put on the perl stack automatically. I don't see much explaining the perl stack in detail
    • How to get the return values from the unpacklist to the perl caller, possibly using the perl stack as a middleman.
    unpackstring

    The engine implementing the unpack() Perl function.

    Using the template pat..patend, this function unpacks the string s..strend into a number of mortal SVs, which it pushes onto the perl argument (@_) stack (so you will need to issue a "PUTBACK" before and "SPAGAIN" after the call to this function). It returns the number of pushed elements.

    The strend and patend pointers should point to the byte following the last character of each string.

    Although this function returns its values on the perl argument stack, it doesn't take any parameters from that stack (and thus in particular there's no need to do a PUSHMARK before calling it, unlike "call_pv" for example).

    I32 unpackstring(const char *pat, const char *patend, const char *s, const char *strend, U32 flags)
pp bleach main script and modules
1 direct reply — Read more / Contribute
by Anonymous Monk
on May 24, 2018 at 14:27

    Hello monks,

    I have a script and a couple of my own modules I want to use to create an executable with pp. I want to hide my code though. I know: nothing can be hidden in a proper way, and and and. We do not need to start the discussion again. I prefer to have my .pl script and my .pm modules hidden, at least to the curious eye. I normally use the following:

    pp -u -f Bleach -o executable myscript.pl

    This works just fine, however only myscript.pl is "bleached", not my own modules. Is there a way to bleach also some modules (not all core modules!). Or there are others method to make my code not readable to the curious eye (again, I know that if something wants to read it... he/she will read it). perl2exe makes this possible (even if it is possible with some work to get the original code)

Subtle(?) issue(?) with lvalues and serialization
3 direct replies — Read more / Contribute
by vr
on May 24, 2018 at 09:08
    use strict; use warnings; use feature 'say'; use Sereal qw/ encode_sereal decode_sereal /; use Storable qw/ freeze thaw /; say 'Storable: ', ${ thaw freeze \substr 'abc', 0 }; say 'Sereal: ', ${ decode_sereal encode_sereal \substr 'abc', 0 }; __END__ >perl 180524.pl Use of uninitialized value in say at 180524.pl line 8. Storable: Sereal: abc

    I was passing lists of string references to mce_map for parallel processing. Because strings are substrings of larger strings, I thought to take shortcut by not creating temporary scalars, but to pass references of substr return values directly. Rather, refs are collected in large array (why whould I store duplicates?), then this array becomes parameter for mce_map. I should have known they are not references to scalars, but to lvalues, though.

    Everything works fine until it doesn't, on a particular machine -- without, it turns out, Sereal installed. Storable, used by MCE in lieu of Sereal, treats these lvalue refs differently.

    I didn't find anything googling for "Perl Storable lvalue", etc. Apart from my sloppy coding, I'm not even sure, if it's Storable issue, Sereal issue, or something else (maybe, MCE should check these?). Kind of, Sereal can be faster drop-in replacement for Storable. Except, it looks, not always. Any thoughts?


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

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (4)
    As of 2018-05-27 03:42 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Notices?