Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
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
Generate a report for every month for a year
2 direct replies — Read more / Contribute
by younggrasshopper13
on Jun 23, 2017 at 16:10
    Hey guys! I have a perl script that I use generate billing reports that gets ran and emailed every month via cronjob to report on some metrics. The perl script runs fine (I originally got this working because of some help from the wonderful monks!) For security reasons I cannot post the script itself but I can post how the current date filter works:
    y $START_DATE = `date '+%Y-%m-%d' -d "-1 month"`; my $END_DATE = `date '+%Y-%m-%d'`; chomp $START_DATE; chomp $END_DATE; my $URL = "http://url/url/url/dump?end_date=$END_DATE&start_date=$STAR +T_DATE&type=csv";
    What I need to do is setup this script to generate a monthly report every month for past 2 years. Is there any easy way to do this with the $START_DATE and $END_DATE? Can anyone help me do this?
Wide character in subroutine entry using encode_qp
1 direct reply — Read more / Contribute
by rumburak
on Jun 23, 2017 at 13:21
    use strict; use warnings; use utf8; use MIME::QuotedPrint; binmode STDOUT, ":encoding(UTF-8)"; my $str = "a\x{201E}z"; #my $str = "az"; #my $str = "a\x{201C}z"; #my $str = "a\x{03C9}z"; #my $str = "az"; #works print $str, "\n"; my $str_q = encode_qp($str); print $str_q, "\n";

    gives me this error message / faulty output:

    az Wide character in subroutine entry at ./x.pl line 18.

    Only the fifth version of $str is working.... Can anyone tell me what is going here? (It is perl 5.24.1.)

Issue with regex
1 direct reply — Read more / Contribute
by shounak mukherjee
on Jun 23, 2017 at 11:47
    Hello Experts, I am new to perl programming and facing a few issues related to perl regular expressions. I need to apply a condition logic only if my $filename is something like: $filename =._foo.xml #Any file that starts with ._" For such files,I need to overlook the content of the file. while( ($fileName = readdir(DIR))) { next if ($fileName eq "^\._.*"); However I think this regular expresion is not able to filter the filenames based on the criteria. I shall be highly obliged if anyone can please help.
Architecture design for full stack development.
4 direct replies — Read more / Contribute
by SimonClinch
on Jun 23, 2017 at 10:42
    Hi Monks, I am developing a website from scratch which will hopefully have plenty of activity some time in the future after it goes live. Although I am still developing it on Windows, I will migrate it to Linux/Apache, with Perl and Postgres completing the rest of the picture before and after migration. I am inclined to avoid PHP for performance reasons.

    While loading the database with some initial reference data (about 1GB), using one-off code that got fixed as I went along, I somehow managed to "lose" some PK values, because sequences do not roll back if accessed with nextval.

    But it occurred to me that when the system goes live, it will need to manage deleted values. Although I was careful to use bigint for PK values where necessary, I don't want to have the situation where the PK values stay fragmented and increase fragmentation over time.

    It was at this point that I realised I needed DBIx::Class, otherwise I would have layers of raw SQL hiding in any homegrown DBMS/Perl framework and that had to be avoided at all costs.

    So I am at the point where I have installed DBIx class and feel obliged to determine the rest of the architecture (MVC perhaps) and at the same level of detail, before writing any methods to dynamically defrag my keys (probably through use of an idpool table/class where inserters will look before calling nextval if nothing is in the pool for the table).

    It becomes clear that the defrag code belongs in the "Controller" part of the framework. But having never built a Controller before, I am hoping for advice on what the classes should look like in there, e.g. should I have a dbController class that uses methods in DBIx. Should it inherit from the Schema and/or should I have some kind of parent-of-all utility class? I am keen to make a good choice now rather than have to make fundamental architecture mods later. Many thanks in advance,

    Simon

    One world, one people

strings to json
4 direct replies — Read more / Contribute
by bigup401
on Jun 23, 2017 at 09:26

    how can i read string into json output

    $name = 'mike'; $age = "20"; $email = "johndeo@/test.com"; $pass = "test"; $resp = '{ "$name": $age, "$email": $pass }'; print $resp;
get specific value of element using xpath in perl
1 direct reply — Read more / Contribute
by snehit.ar
on Jun 23, 2017 at 08:48
    <?xml version="1.0"?> <playlist> <movie id="tt0112384"> <title>Apollo 13</title> <director>Ron Howard</director> <release-date>1995-06-30</release-date> </movie> <movie id="tt0307479"> <title>Solaris</title> <director>Steven Soderbergh</director> <release-date>2002-11-27</release-date> </movie> <movie id="tt1731141"> <title>Ender's Game</title> <director>Gavin Hood</director> <release-date>2013-11-01</release-date> </movie> </playlist>
    I want to retrieve value of <release-date> element where <title> having value 'Solaris' and not other title elements.
    use warnings; use strict; use XML::XPath; use Data::Dumper; my $xml = '../events.xml'; my $xp = XML::XPath->new(filename => $xml); my $nodeset = $xp->findnodes('//playlist'); my $records = []; foreach my $node ($nodeset->get_nodelist) { my $title = $xp->find('./title', $node); push @$records, { title => $title->string_value, }; } print Dumper($records);
    I tired XPath something like  my $title= $xp->find("/playlist/movie[title='Solaris']/release-date", $node); But result is not as expected OutPut ::2002-11-27 Please do help !
post url with 2 input
4 direct replies — Read more / Contribute
by bigup401
on Jun 23, 2017 at 05:34

    how can i make url post with input choices

    how can i make it in url to either take input1 or input2

    post => http://link/take input $1 or input $2
Memory needed for perl process
4 direct replies — Read more / Contribute
by bsshetty17
on Jun 23, 2017 at 02:26

    Hi Monks, 2 quick questions. 1) What is the minimum memory required to start a perl process? 2)I need to install following cpan modules in HP_UX: \t Text::CSV_XS; \t SOAP::Lite; \t XML::Twig; \t Config::IniFiles; \t Parallel::ForkManager; Informatica is also installed in the same server. Informatica administrator is not agreeing to install the modules saying, It causes the informatica performance degradation. Can any one help to defend this? Thanks,

mod_perl best practices to increment XML payload
1 direct reply — Read more / Contribute
by glasswalk3r
on Jun 22, 2017 at 17:23

    Hello monks,

    I've being studying mod_perl in the past to implement a project that uses Apache as a reverse proxy, receives a SOAP request, modifies the payload (XML), handles it to the real web application, and returns back the response to the requester.

    What is the best practice in this case? I checked out Apache::ReverseProxy, but it defines a full handler and I'm guessing that using a Input or Output filter handler would be a better option (based on my readings of mod_perl2 User Guide book) combined with the standard Apache modules proxy and proxy_http to avoid reinventing the wheel.

    PS: I know mod_perl2 is not the "sexiest" framework at the moment, but I want to take advantage of already having it available on particular web servers by default.

    Thanks!

    Alceu Rodrigues de Freitas Junior
    ---------------------------------
    "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill
Not able Login into webpage which use javascript while load
4 direct replies — Read more / Contribute
by trahulprajapati
on Jun 22, 2017 at 11:17

    Hi Monks I'm trying to login to a website which is using javascipt while loading. I have tried with WWW:Machanize but it is not working as WWW:Machanize not support javascript. Webpage is dynamically creating the login form as we have different option for login by selecting radio button. By simple view code it is not showing form form ,that means while loading the page it is calling javascript function and from in function form is loading. WWW:Machanize is not support javascript so is there any way by which i can login to site? I we cannot use WWW:Machanize::Firefox ,WWW::Scripter etc.. is there any way through which we can login by WWW:Machanize or somthing else? I have tried the following code:

    use strict; use warnings; use LWP::UserAgent; use WWW::Mechanize; my $login_url = 'abc.xyz.com'; my $username = "abc"; my $password = "xyz123"; my $mech = WWW::Mechanize->new(); $mech -> cookie_jar(HTTP::Cookies->new()); $mech -> get($login_url); $mech->submit_form( with_fields => { "userid" => $username, "authmethod" => 'on', "username" => $username, "login-form-type" => 'pwd', "password" => $$password }, button => "btnSubmit", ); $mech->save_content('out1.txt');

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 musing on the Monastery: (5)
    As of 2017-06-24 02:34 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      How many monitors do you use while coding?















      Results (556 votes). Check out past polls.