Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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
COnversion problems?
2 direct replies — Read more / Contribute
by Anonymous Monk
on Oct 04, 2015 at 14:26
    i am new to PERL. so i have a lot of difficulties in conversions. i am trying to convert Modern numbers to Roman numbers without using the function ROMAN.. also Trying to convert Octal To Hexadecimal number without any oct or hex function. is it possible?
Best practices for warnings about wrong context
1 direct reply — Read more / Contribute
by vsespb
on Oct 04, 2015 at 11:38

    Let's suppose I've created a library with the following API:

    sub myfunc { my ($ref) = @_; # modify $ref somehow warn "Should be called in void context" if defined wantarray; }

    The function does something, but does not returns anything useful. It returns nothing. I can add "return ;" but this does not change things - function returns nothing and I don't want it to be used in non-void context. Purpose of the last warning in function is simple: the function returns nothing, and if someone called it in scalar/list context, he's doing something wrong. So this warning adds more strictness to user's code:

    examples of user's code:

    example 1:

    func1(); myfunc($data); func2();

    everything ok - no warning

    example 2:


    there will be the warning! user obvious did something wrong here!

    example 3:

    sub anotherfunc { # .. code here myfunc($data) } func1(anotherfunc())

    there will be the warning! and indeed this code isn't sane.

    So far everything going well, and the warning seems useful.

    However, let's look on Catalyst now:

    sub xxx : Local Args(0) { my ($self, $c, $s, $r, $p) = @_; $c->res->body( wantarray ); }

    It's the Catalyst action, which return value is ignored, but it's called in list context.

    Sometimes action return value is important (see "Any data returned from the action forwarded to, will be returned by the call to forward." in manual), sometimes no. But catalyst always call actions in list context.

    Now the quesions:
    (a) Is that good practice to create library, which warns for "defined wantarray" for functions, returning nothing?
    (b) Are libraries like catalyst obligated to never call user's callback in non-void context if it's value is ignored?
    I assume if (b)=no, then (a)=no.
    Is there a convention for such kind of things? (or let me rephrase: if I am getting this warning when using my library with Catalyst, who's fault is that? the library's or Catalyst's)

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 having developed 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?

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 contemplating the Monastery: (6)
    As of 2015-10-05 02:23 GMT
    Find Nodes?
      Voting Booth?

      Does Humor Belong in Programming?

      Results (106 votes), past polls