Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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
How do I convert this wget to perl?
2 direct replies — Read more / Contribute
by Todd Chester
on Oct 03, 2015 at 16:14
    Hi All, This following works in Linux Bash script:
    wget --header "Cookie: oraclelicense=accept-securebackup-cookie" +i586.exe
    If you don't get it right, you download something that tells you to click the "accept License" button. Curl always gets the "accept license" button note. So I switched to wget. I have read numerous responses to LWP::UserAgent, but I am confused as to how to handle the cookie. Is it necessary that this be done with a file? Can it be done directly without a file? Would some kind person mind showing me an example of the above? Many thanks, -T
removing leading 0's
4 direct replies — Read more / Contribute
by CSharma
on Oct 03, 2015 at 11:48
    Hi PMs, The output should be "10 & 10 are equal", but this gives output "10 & 8 aren't equal". I don't understand this! perhaps because of leading 0's perl converted 0010 to octel i.e. 8
    I tried removing leading 0's, still the same output "10 & 8 aren't equal".

    Please help to overcome this.
    Actually I'm reading values from a file in which lots of values have leading 0's & I have to compare this value to some other from different file which doesn't have leading 0's.
    #!/usr/bin/perl $x = 10; $y = 0010; $y =~ s/^0+//; ##OR $y += 0; if($x == $y) { print $x . " and " . $y . " are equal\n"; } else { print $x . " and " . $y . " aren't equal\n"; }
Understanding Catalyst
2 direct replies — Read more / Contribute
by QuillMeantTen
on Oct 03, 2015 at 05:07

    Greetings fellow monks.
    After having done some reconfiguring on a server I currently own (as in pay for, not hacked into) and used for a nodejs webapp I have been confronted with the following problem:

    Since I badly patched together the nodejs app it would not run anymore. One evening of unsuccessful hacks later I decided that "screw it, I always hated javascript in the first place, now that I know perl I say good riddance I'll rewrite it using catalyst"

    One week of on and off working on that project (university work had precedence) I now have a new, more maintainable and elegant web application.

    I come here with two questions:

    • As usual, do you see any way to make the following code better (look at the bottom of the page), its my first time with catalyst so It must be quite smelly.
    • How does catalyst architecture works? more specifically please do correct (and|or) add to my current understanding

    Regarding the second question here is my experience:

    I have read The Definitive Guide to Catalyst but I dont think I correctly grasped all the concepts. The Model part is made of tt files (at least for web views) living in the root folder, those are the templates used to generate pages seen by the clients. Each of those tt files uses variables given to it by the controller using the command $context->stash.

    The View part is the one I least understand. Here I only used View Web TT, meaning what is sent back to the client is web pages made from TT models

    The Controller part is the engine that make it all run, it is the script where each url request is translated into an action to be taken.

    What happens if I want to send back serialized objects instead of a webpage? What kind of model files would I need? What if I need to access a database, should the requests go in the controller?

    As you can see I am still struggling and having made a first webapp did not give me more than a hint of the true power of this framework. thanks you for reading!

    and now the code: my and

Template Toolkit custom plugins?
4 direct replies — Read more / Contribute
by lindex
on Oct 02, 2015 at 23:00
    Does anyone have any full examples have developing a custom Template::Toolkit plugin and loading it in a template?
Arithmetic bug within Time:Piece?
5 direct replies — Read more / Contribute
by jeffa
on Oct 02, 2015 at 15:34

    Greetings! Given today's day, i would like to calculate 3 additional dates:

    1. today - one week
    2. today - one month
    3. today - one year
    This should be simple enough with Time::Piece, however i have found that i need to adjust the deltas for one month and one year by some very inconsistent amounts of time. Please consider the following code and its output:
    use strict; use warnings; use Time::Piece; use Time::Seconds; my $now = localtime; print "Today: $now\n"; print " Week: ", $now - ONE_WEEK, $/; print " Mon: ", $now - ONE_MONTH, $/; print " Year: ", $now - ONE_YEAR, $/; print "\n"; print "Today: $now\n"; print " Week: ", $now - ONE_WEEK, $/; print " Mon: ", $now - ONE_MONTH + (ONE_HOUR * 10) + (ONE_MINUTE * 29 +) + 4, $/; print " Year: ", $now - ONE_YEAR + (ONE_HOUR * 6) - (ONE_MINUTE * 11) +- 10, $/; __DATA__ Today: Fri Oct 2 12:30:17 2015 Week: Fri Sep 25 12:30:17 2015 Mon: Wed Sep 2 02:01:13 2015 Year: Thu Oct 2 06:41:27 2014 Today: Fri Oct 2 12:30:17 2015 Week: Fri Sep 25 12:30:17 2015 Mon: Wed Sep 2 12:30:17 2015 Year: Thu Oct 2 12:30:17 2014
    My specific question is why do i have to add 10 hours, 29 minutes and 4 seconds to the delta for last month, and 6 hours minus 11 minutes, 10 seconds to the delta for last year. Surely i am doing something wrong or not taking something into consideration. I have tested this on three separate Linux servers and received the same results.

    Thanks in advance!


    (the triplet paradiddle with high-hat)
Handling japanese file & comparison
2 direct replies — Read more / Contribute
by CSharma
on Oct 02, 2015 at 14:16
    Hi PerlMonks,

    1. A Japanese compressed file(tab separated), Say A having products information (iphone etc), columns: name, description, image, uniqueid, rid1, rid2, url
    2. Another file, say B having mid, rid, ntid (column separated).
    3. rid1, rid2 => A & rid => B are numerical values.

    What I want:
    If rid from B matches rid1(from A), get that line form A into third file, Say C. In case, rid is null then rid(from B) to be matched with rid2 (from A). If rid1 & rid2 don't have values, leave that line.
    Also I've to add some values to the url (from A) & then it's to be pushed to 3rd file C after rid comparison.

    The main problem I've are:
    1. How to handle the japanese? Do I have to use any modules? as saving the japanese character to a perl variable turn to junk.
    2. There are 30 files like file A, each having 1 million of lines in them. What would be the efficient way to do this in perl?

    Help is much appreciated!

XML::SAX parameters
1 direct reply — Read more / Contribute
by Artimus
on Oct 02, 2015 at 08:53

    Hi everyone!

    I wonder if someone could explain me the way I can pass parameters to my SAX handler or, maybe receive smth back after $parser->parse_file($fh) worked.

jquery scripts
3 direct replies — Read more / Contribute
by hermit23
on Oct 02, 2015 at 05:17

    Dear Brothers
    I have a .cgi script which outputs an HTML page.
    The HTML page includes a short jquery script which draws a graph on the HTML page.
    The critical line in the jquery script is:
    <script> var data=[[0,170],[1,27],[2,3],[3,0],[4,0],[5,0],[6,0],[7,0],[8,0],[9,0],[10,0]]; where the bits in square brackets are positions and data.
    This works fine as long as the data line is hard coded, but I normally don't know what the data is going to be till the .cgi script has run.
    Ideally, I'd like to write a line like this: <script> var data=$mydata where $mydata is a string prepared by the cgi script. However, jquery seems not to like this. I think this, is because it interprets the $ as a reference to itself.
    Does anyone have any suggestions how to solve this?The general question is how do I move smoothly between perl and jquery?

Sorting files
4 direct replies — Read more / Contribute
by kepler
on Oct 02, 2015 at 03:41


    I have several files, which I want to sort in a specific way, but all sumed up together. First, I've opened one file, one at the time, and added the lines to a single array. Then made a sort - it all worked fine. But now, the data is to large for the array I think - I get an "out of memory" error. Any suggestions?



Perl Modules Scope ?
4 direct replies — Read more / Contribute
by Anonymous Monk
on Oct 02, 2015 at 02:01
    Hi, I am writing a login screen and and have following files: lib.cgi and login.cgi in i have following code: package config; our $abcd = 1; 1; in lib.cgi i have following code: use config; 1; in login.cgi i have following code: use strict; required 'lib.cgi'; print $config::abcd; on compiling this I get an error. The error goes away if i "use config" in login.cgi. I thought since I am including lib.cgi inside login.cgi I would not have to use config inside login.cgi Please help me understand this better

Add your question
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!
  • 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?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (6)
    As of 2015-10-04 11:49 GMT
    Find Nodes?
      Voting Booth?

      Does Humor Belong in Programming?

      Results (102 votes), past polls