Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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
Encode - List ALL available encodings [SOLVED]
1 direct reply — Read more / Contribute
by kzwix
on Sep 23, 2014 at 04:15

    Greetings, O wise ones.

    I would like to get a list of all the available encodings installed on my machine. The Encode documentation (on the Perl website) clearly states:

    To get a list of all available encodings including those that have not yet been loaded, say:
        @all_encodings = Encode->encodings(":all");

    Now, executing this command and displaying the list contents, one result per row, gives me the following result:


    However, when I type, in the very same program:

    my $canon = resolve_alias('Latin-9');
    print $canon ? "Found Alias for: $canon\n" : "Unknown\n";

    I get the result:

    Found Alias for: ISO-8859-15

    Now, this leaves me puzzled: The canonical name clearly wasn't stated in the list which was supposed to give me all available encodings... I have the same problem with other encodings, too.

    Would you know what I do wrong ?

1 direct reply — Read more / Contribute
by Ashwitha
on Sep 23, 2014 at 01:00
    Hi all, I need to know is there a way to generate Ant XML file using perl script.
Perl nested loop to print out two arrays n number of times in different patterns
3 direct replies — Read more / Contribute
by arty32l
on Sep 22, 2014 at 20:26

    I am looking to create a loop where the following data is printed n number of times. So given:"

    n = 9; @a = (1, 2 ,3); @b = (a, b, c);
    $a[0] = 1 $b[0] = a $a[0] = 1 $b[1] = b $a[1] = 2 $b[2] = c $a[1] = 2 $b[0] = a $a[2] = 3 $b[1] = b $a[2] = 3 $b[2] = c $a[0] = 1 $b[0] = a $a[0] = 1 $b[1] = b $a[1] = 2 $b[2] = c
keys and values
3 direct replies — Read more / Contribute
by waytoperl
on Sep 22, 2014 at 16:34

    Hash obtained from excel file saved in CSV format. Need to obtain output based on hash keys and corresponding values. How to read contents of various CSV file with data stored in various sheets? Now, I'm able to read data from sheet1 and store in a hash.

    Contents of CSV sheet1, stored in hash table.

    $VAR1 = 'key_2'; $VAR2 = 'value_2'; $VAR3 = 'key_1'; $VAR4 = 'value_1';

    Required output should be to print, contents of csv are value_1 and value_2 in a single print statement

    Please help

Wither SVN::Client?
1 direct reply — Read more / Contribute
by blue_cowdawg
on Sep 22, 2014 at 13:43

    In the process of setting up a new development environment for myself and ran into a minor snag.

    Part of my setup includes Dist::Zilla and a slew of plugins for it. I got to the Subversion plugin which failed complaining there was no SVN::Client on the system. I searched CPAN from the CPAN shell and noticed:

    Module < SVN::Client (N/A)
    So... where'd it go and what replaces it? Will Dist::Zilla like the replacement?

    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; Blog: Warning: No political correctness allowed.
jQuery & Perl?
1 direct reply — Read more / Contribute
by jdlev
on Sep 22, 2014 at 13:10
    Hello Monks!

    I'm working on a perl scraper using www::mechanize, but need it to execute a line of jQuery code to pop information about an element on a page. I could either use jquery or not, it doesn't really matter, I just figured jquery might be a bit more concise. Basically, the code I want perl to click is this, so how would I go about doing that?

    <div class="slick-cell l1 r1"> <a href="#" onclick="return Game.ContestPop(33445566, true);" class= +"fr"> Contest 33445566 </a> </div>

    Thanks in advance monks :D

    I love it when a program comes together - jdhannibal
Am I hitting a Perl XML parser module internal bug when dealing with large amounts of data?
2 direct replies — Read more / Contribute
by feiiiiiiiiiii
on Sep 22, 2014 at 12:18

    Hi Monks, I recently came across a weird bug when using the Perl XML parser. I'm not sure if it's Perl internal bug, or is caused by some unusual characters in my XML file.

    Here's the parser I'm using:

    my $parser = XML::Parser->new(Handlers => { Start => \&handle_start, Char => \&handle_char, End => \&handle_end });

    The xml file has over 300 million lines. The part I'm having trouble with is

    <Rating_Class_Text indicator="_">LT Issuer Rating</Rating_Class_Text>

    By definition, the handle_char part should be able to read all the non-markup text into one String. For example, here it should read "LT Issuer Rating". The above line repeated hundreds of times in the xml file, and it works correctly for most of the times. However, there is one exception that it reads "LT" and " Issuer Rating" into two separate Strings.

    Here're a few attempts I tried:

    1) I tried checking that particular line using Emacs hexl mode, and didn't find any unusual character in that line.

    2) I tried cutting the problematic part out, and create a new xml file containing only that part. It works correctly.

    3) I tried creating a copy of the whole file, by removing all the non-printable characters (which basically removes the leading spaces before xml tags and makes the file shorter). This does solve the problem.

    4) I tried only removing all the non-printable characters in that problematic line. This time Perl reads "LT Iss" and "user Rating".

    Could anyone help to identify if this is a Perl XML parser module internal bug when handling large amounts of data? Or is this something wrong in my xml file? Thanks a lot!

Perl CGI -disabled
2 direct replies — Read more / Contribute
by misterperl
on Sep 22, 2014 at 10:31
    I guess this is more of an HTML question than Perl, but I've read the detailed desctiption of the -disabled switch (used on an input text box) and all it says is it prevents the user from clicking into the box. Which is exactly what I need.

    But IN ADDITION, the param seems to vanish from the cgi returned from the page? That seems particularly undesirable, since now I'm having to push it in with a cgi->hidden to get the dataset proper again.

    Is the disappearing param an actual built-in functionality of disabled, or is something else going on?

    -disabled is also one of those oddball switches where it's specification is undefined. Some pages suggest you use -disabled => 1,
    others -disabled => 'on',
    and others say -disabled,
    is sufficient. Aggregated docs are unclear.
    TY and happy Monday.

executing perl script using -e
7 direct replies — Read more / Contribute
by mradul
on Sep 22, 2014 at 08:45

    Hi, I am trying to do something like this

    perl -e '"system(/usr/bin/perl /root/"'

    The looks like this

    use strict; use warnings; `touch /tmp/1`;

    The file /tmp/1 is not geting created. Any clues why and how can I do that?

Optimization of Regexes
1 direct reply — Read more / Contribute
by shadowSage
on Sep 22, 2014 at 07:47

    Hi Perl Monks. Got another one to lay on you: In the 'Intermediate Perl' book, it is discussing the Regexp::Assemble module.

    After the brief discussion of how it optimizes the expression it says 'If you are using v5.10 or later, Perl already does this for you.'

    I did a quick (not exactly comprehensive) script to check what that statement was on about

    use 5.020; use Regexp::Assemble; my $re = Regexp::Assemble->new; for('blah', 'bleh', 'chicken', 'woofie', 'snake', 'snakes', 'woofies', + 'chicken-woofy'){ $re->add("\Q$_"); } say $re->re; my $newre = qr/blah|bleh|chicken|woofie|snake|snakes|woofies|chicken-w +oofy/; say $newre;

    The result:

    (?^:(?:chicken(?:-woofy)?|woofies?|bl[ae]h|snakes?)) (?^u:(blah)|(bleh)|(chicken)|(woofie)|(snake)|(snakes)|(woofies)|(chic +ken-woofy))

    What's the deal? Does it just happen internally when /matching|substituting/? Or do I have the wrong idea completely?

    Thanks for your time in reading this

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
  • Outside of code tags, you may need to use entities for some characters:
            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 musing on the Monastery: (10)
    As of 2014-09-23 10:02 GMT
    Find Nodes?
      Voting Booth?

      How do you remember the number of days in each month?

      Results (216 votes), past polls