Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
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
Hashing temporal tables in PostgreSQL
1 direct reply — Read more / Contribute
by gtk
on Sep 22, 2017 at 01:23
    Hi All, I am in a process of writing a perl script to hash tables in a schema to track any changes done in table definition level. This is thoroughly for the security purpose and to minimize the unauthorized changes in the DB. So the plan is to generate a Hash/Checksum key for each table and store in a temporary table after any deployment. Then generate the Hash/Checksum key value again before the next deployment and compare the previous Hash/Checksum values. Please let me know a correct way to do this in PostgreSQL. I did the same thing Oracle DB by using DBMS_CRYPTO function and couldn't able to find a way in PostgreSQL. So please suggest me a way to handle this hashing tables method and relevant functions/utilities? Thanks.
Keeping relationally child objects alive with Moo
3 direct replies — Read more / Contribute
by SimonClinch
on Sep 21, 2017 at 06:24
    Hi Monks, The concept of inheritance carries with it a concept of parent and child, but what if I want a relational parent/child model?

    So using Moo, I tried this:

    package Myproject::Model; use Moo; has table => (is => 'rw'); sub newtable { my ($self, $table) = @_; my $tob = Myproject::Model::Table->new( # also uses Moo and define +s these ro attributes:- name => $table, model => $self, ); $self->table or $self->table({}); my $tables = $self->table; $tables -> {$table} = $tob; } 1;
    Problem is that sometimes a $tob gets destroyed in spite of being nested in a living model object.

    But rather than hack my way around what I did, I am wondering if I am missing a tried and tested way of storing relationally child objects in their relationally parent object (including if necessary upgrading from Moo to Moose). Many thanks in advance for suggestions (I am looking for architectural insight/tips rather than merely fixing the code I already have).

    One world, one people

Problem upgrading XML::Fast from 0.11 to 0.17
3 direct replies — Read more / Contribute
by mje
on Sep 21, 2017 at 05:33

    I've been using XML::Fast to process XML files for some time and successfully. However, the code was moved to a newer machine and has stopped working in some circumstances. A difference between the machines is XML::Fast version, 0.11 on original machine (working) and 0.17 on new machine (not working). When no other changes are made but to upgrade to 0.17 on the old machine it also stops working.

    The error I'm getting is:

    Failed to encode 2017-9-21T08-49-17.XML to JSON for indexing - malform +ed or illegal unicode character in string [�ndby IF], cannot c +onvert to JSON at xx.pm line 1827.

    The XML file comes from a 3rd party and is ISO-8859-1 encoded. The bit it is complaining about is <Value>Br<F8>ndby IF</Value>. A cut down version of the XML which fails is:

    <?xml version="1.0" encoding="ISO-8859-1"?> <xx feedtype="delta"><Timestamp CreatedTime="2017-09-21T06:49:17" Time +Zone="GMT"/><Value>Brøndby IF</Value></xx>

    The code which is now failing is:

    use Cpanel::JSON::XS; use XML::Fast; sub esIndexFile2 { my ($self, $file) = @_; my $xml = do { local $/ = undef; open (my $fh, "<:encoding(ISO-8859-1)", $file) or die "Failed +to open $file - $!"; <$fh>; }; $xml =~ s/^(?:.*\n)//; # remove first line - the encoding lin +e my $hash; eval { $hash = xml2hash $xml; }; if (my $ev = $@) { warn("Failed to parse file $file for indexing - $@ - SKIPPING" +); return; } my $json = eval { encode_json($hash); # <------------ fails here }; if (my $ev = $@) { $self->logwarn("Failed to encode $file to JSON for indexing - +$@ - SKIPPING"); return; } return 1; }

    The changes file for XML::Fast is not too helpful. I have discovered adding utf8decode => 1 to the xml2hash makes it work now but I don't really understand why. I am doing anything wrong here? What might have changed in XML::Fast to cause this to happen?

Trouble with Perl Heroku buildpack
1 direct reply — Read more / Contribute
by BeneSphinx
on Sep 20, 2017 at 23:58

    Hello Perl Monks

    I ask for your wisdom from a position of great humbleness. I have tried to get Perl running in Heroku, but this simple task is eluding me for now. I have started with the buildpack here: https://github.com/miyagawa/heroku-buildpack-perl

    My understanding is that all I need is an app.psgi file, a cpanfile, and a Procfile. My procfile just calls out to starman, which I think (but don't know) will automatically notice my app.psgi.

    It was building fine back when I didn't have an app.psgi and just a hello.pl - but of course that wouldn't do anything. Once I changed to app.psgi (hoping that Starman would launch, correctly hook into it, and use my app.psgi to start serving web pages), I started getting the error "Can't locate Plack/Runner.pm in @INC"

    But in my cpanfile I do indeed have Plack listed as a requirement, as stated on the buildpack homepage: requires 'Plack', '1.0000';. My understanding is that Plack::Runner should come along with that. I guess somehow the buildpack isn't properly installing this, but I'm not sure what to do next.

totally skipping a test in CPAN ("ultra force!")
2 direct replies — Read more / Contribute
by BeneSphinx
on Sep 20, 2017 at 22:18
    Dear Monks, I am attempting to install a Perl-based webserver named Starman on my computer (Strawberry Perl, 64-bit). However something is happening which causes it to hang on a test. I have attempted force install in CPAN, but it still runs the tests. I'm guessing force install just causes it to ignore the results of the tests, but that doesn't help me since the hanging test prevents the install from proceeding. What I really need is some sort of "ultra force" that prevents the tests from even running. Is there anything like that? What else should I do? Thank you.
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?.


    Hi!

    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:

    Alexander

    --
    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
6 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: 5.16.3.1604 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.2.1.0.272.7 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.


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?
    [choroba]: which counts as a good weekend
    [Discipulus]: yes, (at least until Sun afternoon...): Saturday we got splendid birthday party in a park: lot of eat, drink and children amusement: bag running, magnetic fishing, rope and that big pot full of candies to smash with a club

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (5)
    As of 2017-09-25 08:40 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      During the recent solar eclipse, I:









      Results (278 votes). Check out past polls.

      Notices?