Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
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
Connection to urls which are having dynamic ipadddresses through perl scripts
1 direct reply — Read more / Contribute
by prathap keerthipati
on Jun 29, 2017 at 05:11

    Hi Monks,

    I need to download the content of the websites which are having dynamic ipaddresses. Is there a possibility to do it through perl scripts?

regex to match "---" followed by new line
2 direct replies — Read more / Contribute
by Anonymous Monk
on Jun 29, 2017 at 02:46

    Hello PerlMonks who are always smarter than me. I'm trying to write a regex to match "---" followed by a new line to parse a number of files and return some data with no success. Here's the code that I have that's not working , any assistance is greatly appreciated.

    @matches7 = ($text =~ /(.{0,0})\K(---\s*)(.{0,200})/gisx);
use experimental 'autoderef'; ???
4 direct replies — Read more / Contribute
by LanX
on Jun 28, 2017 at 19:52
    the core° pragma experimental says

    The supported features, documented further below, are:

    array_base - allow the use of $[ to change the starting index of @array autoderef - allow push, each, keys, and other built-ins on references lexical_topic - allow the use of lexical $_ via "my $_"

    Though running the following code under 5.24 doesn't show any effect

    use strict; use warnings; use experimental 'autoderef'; BEGIN { warn "@INC\n"; warn "$]\n"; } my $a=[]; push $a,1,2,3; warn "@$a";

    out

    c:/Perl_524/bin/\perl.exe d:/Users/RolfLangsdorf/AppData/Roaming/pm/e +xperimental_autoderef.pl c:/Perl_524/site/lib c:/Perl_524/lib . 5.024001 Experimental push on scalar is now forbidden at d:/Users/RolfLangsdorf +/AppData/Roaming/pm/experimental_autoderef.pl line 13, near "3;" Execution of d:/Users/RolfLangsdorf/AppData/Roaming/pm/experimental_au +toderef.pl aborted due to compilation errors.

    I suppose this is a bug, though I'm wondering was there ever a useful application for

    use experimental 'autoderef'; ?

    AFAIK autoderef never needed to be activated.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

    °) strange

    ~/pm $ corelist experimental Data for ????-??-?? experimental was first released with perl v5.19.11

    but perldoc.perl.org doesn't list experimental

    update

    I know that auto deref was deprecated, but the mention in experimental doesn't make sense, because

    • it was a normal builtin, not an experimental feature
    • it pretends to allow activation despite deprecation
    • perldoc.Perl.org doesn't list a core pragma

    That's very confusing

No Clickable button with name.... in WWW::Scripter
1 direct reply — Read more / Contribute
by trahulprajapati
on Jun 28, 2017 at 14:53

    Hello Everyone

    I'm facing an issue while clicking the button after login to the webpage

    What I want to do is , First login to the webpage then click the OK button. I'm using WWW::Scripter(plugin javascript) as login page is using javascript while loading.

    Here is the code that I have tried

    use strict; use warnings; use WWW::Scripter; my $username = "abc"; my $password = "abc\@123"; my $w= WWW::Scripter->new( cookie_jar => { autosave => 1} ); $w->use_plugin('JavaScript'); $w->get('abc.xyz.com'); $w->submit_form( with_fields => { username => $username, password => $ +password }); print $w->title(); #Till here it is working, I'm able to login ############## Clicking OK button ################ $w->click(name=>'successOK'); print $w->title(); #it is giving me that no clickable button with name successOK

    Here is OK button code

    <div id="srv_successok"><input type="button" name="successOK" value=" + OK " onClick="redir();"></div>

    Please suggest how can I resolve it

    Thank you

execute if date is greater then 2hours
2 direct replies — Read more / Contribute
by snehit.ar
on Jun 28, 2017 at 03:11
    Want to compare 2 date and if hour is more then 2 hours then its should enter if condition and perform the action .
    #!/usr/bin/perl use warnings; use strict; use DateTime; use DateTime::Duration; # my $file = 'C:/Users/snehit.rahate/Perl/events.xml'; # #my $xpath = q{//custom_attribute_list/custom_attribute[normalize-sp +ace(name)='SLB_SSRID']/value}; # my $xp = XML::XPath->new(filename=>$file); # my $nodeset = $xp->find("//custom_attribute_list/custom_attribute[no +rmalize-space(name)='SLB_SSRID']/value"); # for my $node ($nodeset->get_nodelist) { # print " XML::XPath: ",$node->string_value,"\n"; # } use DateTime::Format::Duration; my $dtnow = DateTime->now; $dtnow =~ s/T/ /; $dtnow =~ m/(\d+)-(\d+)-(\d+)\s(\d+):(\d+):(\d+)/gi; my $now_hour = $4; my $now_minute = $5; my $now_second = $6; my $dtevent = '2017-06-15 13:14:31'; $dtevent =~ m/(\d+)-(\d+)-(\d+)\s(\d+):(\d+):(\d+)/gi; my $event_hour = $4; my $event_minute = $5; my $event_second = $6; my $diffhour = $now_hour - $event_hour; my $diffminute = $now_minute - $event_minute; my $diffsecond = $now_second - $event_second; my $event_time = $diffhour.":".$diffminute.":".$diffsecond; print $event_time; if ($event_time > "2:00:00") { print "Start the service if time is more then 2 hours"; }
    Error :Argument "2:00:00" isn't numeric in numeric gt (>) at test.pl line 37. Argument "-6:-8:15" isn't numeric in numeric gt (>) at test.pl line 37. -6:-8:15
Minimally changing combinations
5 direct replies — Read more / Contribute
by Yary
on Jun 28, 2017 at 03:08
    There are a few modules on CPAN for generating combinations. For example given the lists
    [ 'a','b','c' ] , [ 1, 2 ]
    they produce

    a 1
    a 2
    b 1 # two changes this iteration
    b 2
    c 1 # two changes this iteration
    c 2
    

    There's another ordering, where only one position at a time changes. And there's a name for that ordering which I've forgotten, so I haven't been able to search CPAN for it. It would produce the tuples in an order like so:

    a 1
    a 2
    b 2
    b 1
    c 1
    c 2
    

    Can anyone refresh my memory as to what that ordering is called, and as a bonus, find me a module on CPAN that already produces combinations that way?

    ... I have tried the the obvious keywords "permute" and "combination" on metacpan but suspect I'm missing the right word... yes I could implement it from scratch, or take the output of one of the CPAN modules and reverse some records to get the desired ordering. But why re-invent a wheel, if it's already been invented.

Replace value in the text file
4 direct replies — Read more / Contribute
by mhoang
on Jun 28, 2017 at 01:17

    Hello guys, I have two text files: file1.txt

    "A123","valueA1","valueB1" "B234","valueA2","valueB2" "C345","valueA3","valueB3" "D456","valueA4","valueB4" "E567","valueA5","valueB5" "F678","valueA6","valueB6"
    file2.txt
    "C345","valueX1","valueY1" "D456","valueX2","valueY2"
    I want to replace the value in file 1 with the second column value in file 2 if the key is matched.
    "A123","valueA1","valueB1" "B234","valueA2","valueB2" "C345","valueX1","valueB3" "D456","valueX2","valueB4" "E567","valueA5","valueB5" "F678","valueA6","valueB6"
    and here is my code, but I actually don't know how to write back to file1 with new value. Pls shed some light into it thanks.

    #!/usr/bin/perl #use strict; #use warnings; open fh1,"<C:/Perl-Script/file1.txt"; open fh2,"<C:/Perl-Script/file2.txt"; open fh3,">>C:/Perl-Script/file3.txt"; @a=<fh1>; @b=<fh2>; foreach $b(@b) { @k = split ' ', $b; $hash2{$k[0]} = $k[1]; } foreach $a(@a) { @k = split ' ', $a; $hash1{$k[0]} = $k[1]; } while(($k,$v)= each %hash1) {$hash1{$k} = $hash2{$k} if (exists $hash2{$k})}; foreach $value (@a) { print fh1 $value; }
SELECT LAST_INSERT_ID does not work
6 direct replies — Read more / Contribute
by Vagabundo
on Jun 28, 2017 at 00:49
    Hi, I have two scripts using the same mysql-database with DBI and the same table. One of this scripts add sometimes a lot of inserts.
    The other script than has a problem to get the correct LAST_INSERT_ID.
    It looks like the busy script makes entries at the same time between my Insert and my SELECT LAST_INSERT_ID.
    Is that real possible and how can I prevent it.

    My Code is:
    my $sthopen = $dbh->prepare("INSERT INTO..... $sthopen->execute; &ErrorDBI; my $resid = $dbh->prepare("SELECT LAST_INSERT_ID()"); $resid->execute; &ErrorDBI; my @idrow = $resid->fetchrow_array;
    for example:

    The auto_increment entry is 2201 and the last_insert is 2203
    or 2504 and 2505
    and so on.....
    Has anybody an idea for an solution?
perl6 install fail
2 direct replies — Read more / Contribute
by freakcoco
on Jun 28, 2017 at 00:07

    I try to build perl6 on my ubuntu system(version => "Ubuntu 15.04",architectures=>ARM Cortex-A7)

    sudo apt-get install build-essential git libssl-dev git clone https://github.com/tadzik/rakudobrew ~/.rakudobrew echo 'export PATH=~/.rakudobrew/bin:$PATH' >> ~/.bashrc source ~/.bashrc rakudobrew build moar

    when i build moar I got this :

    how to fix this problem?

Why perl with strict allows to use -bareword?
2 direct replies — Read more / Contribute
by hurricup
on Jun 27, 2017 at 16:04

    According to docs for strict subs:

    This disables the poetry optimization, generating a compile-time error if you try to use a bareword identifier that's not a subroutine, unless it is a simple identifier (no colons) and that it appears in curly braces or on the left hand side of the => symbol.

    But use Some::Thing -base;, for example, works and not looks like example in docs. Also, it may cause a surprise, when sub with name 'base' been defined before this use.


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?
    [Eily]: LanX that sounds fishy to be honest
    [marto]: puntastic
    [choroba]: o'nest

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (6)
    As of 2017-06-29 12:38 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      How many monitors do you use while coding?















      Results (662 votes). Check out past polls.