Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
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
Questions regarding mixing up all the data from Image::ExifTool
3 direct replies — Read more / Contribute
by Buttonzz
on Oct 13, 2017 at 16:18

    Hello everybody and thanks for reading my problem.

    Im new in here and need some advice to overwhelm some trouble programming my exif-editor Tool with Perl and Perl-Tk.

    Im dealing with two problems.

    I)

    I have a scrollable GridColumn with 2 columns. Before Im creating it, Im creating a menu where you can pick a file or directory. So I cant call $gc->refresh() in the menu's subs.

    If I start the application and pick a file, the gridcolumns data sofore wont update.

    Is there any way creating an event that "watches" if $file or $folder swap from undef to something else? - I 'overread' some sites dealing with events but cant find anything that really fits. (Or I didnt get deep enough.

    II)

    Dealing with Image:ExifTool - is there any 'easy' way to get all the info of more than one file (all files with exif info in a specific directory) together?

    If I manage those 2 problems I might eb able to stick to my appointment next friday. Its an exercise I chose myself for the last course before my bachelor thesis.

    Unfortunate my kid had lots of trouble with teeth - so we with sleep - and after that we all got ill, so it gets close to the deadline now and Im missing some things. Im sure my lecturer would give me another week. But I wont use this if I dont have to.

    In case you need more information, feel free to ask. I wanted to keep it quite theoretically because I dont want anyone to do my work - I just need some 'slaps on the back of my head' as we German say. :) Have a nice evening and thx for anyone dealing with my post. :)

Screen scraping complex tables and divs
3 direct replies — Read more / Contribute
by parser
on Oct 13, 2017 at 14:53

    I have been screen scraping for a few years with WWW::Mechanize and HTML::TokeParser and they have served me well. However, I recently encountered a set of pages which use complex table structures and numerous tab divs. I need a module (or methodology) which will allow me to search for sections of HTML in a more jQuery find()-like manner rather than simply consuming tokens from a stream of HTML.

    I read through the post The State of Web spidering in Perl and, while helpful, the focus is more on spidering than scraping. I am interested in recommendations from the Monks if there are higher-order methods of finding contructs in HTML using Perl besides regular expressions and token parsing.

    I read Mahmoud's jquery module on CPAN with interest but it appears not to have been maintained since 2013 and and I am uncertain it can query on table structures. To be fair, jQuery is limited on querying unlabeled table structures as well.

    Here is a small example of what I am trying to accomplish:
    1) Find the 6th and 9th rows in a named table (given an id) and pull out the name and value pairs.
    2) Slurp in every row in a named table and parse out the name value pairs.

    Cheers!
How to turn "HASH(0x1234567)" into a real HASH
3 direct replies — Read more / Contribute
by rodd
on Oct 13, 2017 at 12:45
    Monks,

    While debugging some code that's printing "HASH(0x9999999)" to stdout, I'd like to be able to parse that out and convert it to a real Perl hash to be able to identify the hash's origin from looking at its contents.

    I found I can peek into its data structure using the following:

    my ( $addr ) = 'HASH(0x9999999)' =~ /HASH\(0x(.*)\)/; $addr = hex $addr; my $hash_dump = pack 'L', $addr;

    But unfortunately $hash_dump is not a HASH but just memory garbage.

    How can I convert the address into a valid Perl HASH (or HASH ref)?

Getting error multiple values in where conditon.
2 direct replies — Read more / Contribute
by nitn
on Oct 13, 2017 at 12:12
    my $sth3 = $dbh->prepare("select name,value from A where in (".join(" +,",@var1).")"); - @var1 contains the 5 values $sth3->execute(@var1); while (my @row = $sth3->fetchrow_array) { print join(", ", @row), "\n"; }
    getting error :
    DBD::Oracle::db prepare failed: ORA-00936: missing expression (DBD ERR +OR: error possibly near <*> indicator at char 58 in 'select name,valu +e from A where <*>in (1,2,3,4,5)') [for Statement "select name,value +from A where in (1,2,3,4,5)"] at hello.pl line 99. Can't call method "execute" on an undefined value at hello.pl line 102 +.
Reading tar.gz file recursively
2 direct replies — Read more / Contribute
by vinoth.ree
on Oct 13, 2017 at 01:20
    Hi,

    How to list out files from foo.tar.gz, where foo.tar.gz in bar.tar.gz file.

    For example, I have bar.tar.gz file which contains many tar.gz files, I need to read bar.tar.gz file and find tar.gz files in it and read files from that tar.gz

    bar.tar.gz--> foo.tar.gz --> text1.txt, text2.txt Here I need to list out those text1.txt and text2.txt files. I can do this by `tar-xzOf bar.tar.gz foo.tar.gz|tar tzf`. but to how to automate this thing? any module available for this ? suggestions are greatly appreciated.

    All is well. I learn by answering your questions...
Trying to implement 2 seperate alarm timers in POE
1 direct reply — Read more / Contribute
by KaiLoi
on Oct 12, 2017 at 22:06

    Hi there,

    I'm having a bit of trouble with Alarm timers in Perl POE, I have a program that does a couple of things periodically

    • Looks for alerts reported by a sub every 2 seconds
    • rechecks a list of mounts. every 5 seconds

    However my alarm timers appear to be stomping on one another. The first loop around the wheel they both run they work fine the alert alarm happens at 2, then 4 seconds. Then the Mount alarm triggers at 5 seconds, then they both just start triggering every 2 seconds. I can see I must be stomping on the mounts alarm with the alerts alarm assignment, and I've tried a lot of things like naming the alias different things, naming "next_alarm_time" different things between the subs, naming the subs "tick" and "tock" but nothing seems to work. Any suggestions?

    #!/usr/bin/perl use warnings; use strict; use POE qw(Wheel::Run Filter::Reference Wheel::FollowTail); POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->alias_set('MountWatchdog'); $_[HEAP]->{next_alarm_time} = int(time()) + 5; $_[KERNEL]->alarm(tick => $_[HEAP]->{next_alarm_time}); }, tick => sub { my $key; my $name; print "Mount tick at ", time(), "\n"; $_[HEAP]->{next_alarm_time} = $_[HEAP]->{next_alarm_time} + 2; $_[KERNEL]->alarm(tick => $_[HEAP]->{next_alarm_time}); }, }, ); POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->alias_set('AlertWatchdog'); $_[HEAP]->{next_alarm_time} = int(time()) + 2; $_[KERNEL]->alarm(tick => $_[HEAP]->{next_alarm_time}); }, tick => sub { my $key; my $name; print "Alert tick at ", time(), "\n"; $_[HEAP]->{next_alarm_time} = $_[HEAP]->{next_alarm_time} + 2; $_[KERNEL]->alarm(tick => $_[HEAP]->{next_alarm_time}); }, }, ); # Start our POE Kernel. $poe_kernel->run(); exit 0;
json decoding
2 direct replies — Read more / Contribute
by Anonymous Monk
on Oct 12, 2017 at 18:29

    Dear Monks

    I admit I am quite bad at parsing data. I want to read some information out of json data. Someway I am not getting the information I want. The data is the following.

    { "head": {}, "def": [ { "text": "time", "pos": "noun", "ts": "ta&#618;m", "tr": [ { "text": "tempo", "pos": "noun", "gen": "m", "syn": [ { "text": "volta", "pos": "noun", "gen": "f" }, { "text": "momento", "pos": "noun", "gen": "m" }, { "text": "Time", "pos": "noun", "gen": "m" } ], "mean": [ { "text": "day" }, { "text": "moment" } ] } ] } ] }

    First of all, I would like to read "text": "tempo" (i.e. tempo). Furthermore I would like to read also a the other values of "text" inside "syn", being the number of "text" element variable

    I am using the following:

    my $req = HTTP::Request->new(GET => $uri); my $res = $ua->request($req); if ($res->is_success) { my $json_text= $res->content; my $decoded_json = decode_json( $json_text ); my $result = $decoded_json->{'def'}{'tr'}{'text'};#Here I was suppos +ing to get the first "text" value = tempo }

    Unfortunately it fails, as I am evidently interpreting badly the data structure (and a dumper did not help me a lot). Any suggestions?

Seamless recovery from DB disconnects in Apache/mod_perl
2 direct replies — Read more / Contribute
by cleverett
on Oct 12, 2017 at 16:14

    My employer is upgrading the Oracle DB to RAC. TAF will be enabled.

    I'm pretty clear on how to handle TAF events by supplying a callback function.

    What I'm not clear on, is what to do after reconnection. I've figured out a way of replaying all the DB requests that came through before the DB failure. But that could easily go south if a sequence or intermediate query result changes between the time DBI disconnects and reconnects.

    Our environment is unfortunately primitive. We run mod_perl, but we don't do handlers; we have CGI scripts that we very slightly modified to run with reliably with PerlResponseHandler ModPerl::PerlRun.

    What I'd really like to do, is simply roll back the changes and start the response handler (PerlRun) over again as if it had never run in the first place. I'm just not sure what general approach to take to get that result. I'm thinking that I could create a specific exception class, and use that to tell a class inheriting from ModPerl::PerlRun to start the request over, and use that class instead of ModPerl::PerlRun for the response handler.

    I'm not looking for code, just a clue that what I want to do isn't crazy and/or pointers to something simple that would work reliably.

discussion: What should split( /PATTERN/, EXPR, 0 ) return better?
8 direct replies — Read more / Contribute
by rsFalse
on Oct 12, 2017 at 14:18
    Hello,

    Today I have used split( /PATTERN/, EXPR, 0 ) (LIMIT = 0), and it returned an answer equivalent to what does split( /PATTERN/, EXPR ) return. Such behaviour is documented split: "If LIMIT is omitted (or, equivalently, zero), then...".

    I was solving a task, and I've forgotten this LIMIT=0 behaviour, and I was expecting to get an empty list. In my opinion this behaviour would be good also. That has some logic. One can interpret "LIMIT" as a non-negative number representing a number of chunks of string one wants to get. Then if one wants to get as much as possible chunks, he do not use LIMIT (unlimited chunks), or use verbose keywors like LIMIT="MAX". What are your opinion?

    The task was: to arithmetically add K (K>=0) first numbers which are written in a string form separated by whitespaces, e.g. "5 6 7 8\n". For this task I wrote:
    my $K = <>; my $sum = 0; $sum += $_ for split ' ', "5 6 7 8\n", $K; print $sum;
    and got correct answers for all K > 0, but not K == 0.
    K sum 0 26 1 5 2 11 3 18 4 26 5 26
how to choose the greater or equal number in array
5 direct replies — Read more / Contribute
by lakshu
on Oct 12, 2017 at 13:54

    In below program I am expecting the value like 3, 6,6,10, 10 can anyone help

    use strict; use warnings; sub min_and_max { my (@numbers); @numbers = @_; my ($min, $max, @ret1); $min = $numbers[0]; $max = $numbers[0]; foreach my $i (@numbers) { if ($i >= $max) { return push my(@ret1), $i; } } return (@ret1); } my (@test_array); @test_array = (3,6,,7,6,3,10,5,6,2, 10); my @ret = min_and_max(@test_array);

    In this program I am expecting the value like 3, 6,6,10, 10 can anyone help


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 scrutinizing the Monastery: (6)
    As of 2017-10-19 00:18 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My fridge is mostly full of:

















      Results (251 votes). Check out past polls.

      Notices?