Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
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
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: http://blog.berghold.net Warning: No political correctness allowed.
Am I hitting a Perl XML parser module internal bug when dealing with large amounts of data?
1 direct reply — 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 cgi.pm -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
6 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/test.pl)"'

    The test.pl 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

pack and unpack with 8 bit integers
2 direct replies — Read more / Contribute
by thanos1983
on Sep 22, 2014 at 06:54

    Hello Monks,

    Update: Title update from (How to convert an integer 8bit long to binary and vice versa) to (pack and unpack with 8 bit integers).

    Lately I have been asking way too many questions, apologies for that. Although that I thought that I was starting to get the conversion process of decimal to binary and binary to decimal, I got stack again.

    I want to convert an integer 8 bit long with template format "i" to binary and then convert it pack to decimal with the same format "i". I want to complete the process using pack and unpack.

    I have been experimenting with a sample of code. I can not figure it out why is not working properly.

    Sample of code:

    I have broken down the process into pieces in order to detect the error. It seems the error comes from the pack process.

    So at this point I can not understand why. I have found a way to by avoid the error by modifying the $template on the sub bin2dec process from "i" (intiger) to "c" (8 bit character). By doing so I get the correct output, but since I am defining B8 I should not have a problem with the unpack process.

    So can someone help me understand where I am going wrong, and how to fix my problem?

    Thanks in advance for everyone's time and effort to assist me.

    Seeking for Perl wisdom...on the process of learning...not there...yet!
Unable to read excel columns more than 700
3 direct replies — Read more / Contribute
by doubledecker
on Sep 22, 2014 at 02:42

    Hi Monks

    I have an excel sheet with more than 1000 columns and trying to read data out of it. But, Spreadsheet::XLSX is not letting to read more than 700 columns. I have tried using other modules but the result is same. May I know what is the exact reason behind this?

    Thanks

Finding Minimum Value
7 direct replies — Read more / Contribute
by jimmy88
on Sep 21, 2014 at 19:03

    Please forgive me for my naivety but I'm having an issue that I'm sure one of the wise perl monks can quickly resolve: My script processes all of my input data as desired with the exception of minimum values for the input grades. What is the issue here and how can I ensure accurate output? Once again, sorry to bother by asking for help with something so seemingly simple. Your help is much appreciated.

    ***students.txt*** 122334:James,Lebron: 222223:Duncan,Tim: 244668:Bryant,Kobe: 355779:Durant,Kevin: ****************** ***grades.txt*** 122334 1 98 222223 1 86 244668 1 89 355779 1 90 122334 2 96 222223 2 88 244668 2 92 355779 2 96 122334 3 97 222223 3 96 244668 3 95 355779 3 94 122334 4 97 222223 4 96 244668 4 95 355779 4 94 122334 5 97 222223 5 96 244668 5 95 355779 5 94 **************** #!/usr/local/bin/perl #Assign class roster file to variable. $students = 'students.txt'; # Open class roster. open (NAMES, "<$students") || die "Couldn't open $students $!"; # Create and populate arrays. while (<NAMES>) { ($id,$name) = split(':',$_); $name{$id} = $name; # Monitor name length for purpose of print formatting. if (length($name)>$longestname) { $longestname = length($name); } # Creat group size variable for later use with class avera +ges. $groupsize = $.; } # Arrays are complete. Close file. close NAMES; # Assign grade spreadsheet to variable. $grades = 'grades.txt'; # Open grade spreadsheet. open (GRADES,"<$grades") || die "Couldn't open $grades $!"; # Create, populate and assign arrays. while (<GRADES>) { ($id,$exam,$grade) = split; $grade{$id,$exam} = $grade; # Monitor exam counter. if ($exam > $lastexam) { $lastexam = $exam; } } # Arrays are complete. Close file. close GRADES; # Create, format and print table headings. printf "%6s %-${longestname}s ", 'ID#','Name'; foreach $exam (1..$lastexam) { printf "%4d",$exam; } printf "%10s",'Total'; printf "%8s",'Avg'; printf "%8s",'Min'; printf "%8s\n\n",'Max'; # Define alphabetical sort subroutine. sub alpha { $name{$a} cmp $name{$b} } # Print formatted student data. foreach $id ( sort alpha keys(%name) ) { printf "%6d %-${longestname}s ", $id,$name{$id}; # Set total point counter to zero. $total = 0; foreach $exam (1..$lastexam) { printf "%4s",$grade{$id,$exam}; # Counter increment. $total += $grade{$id,$exam}; $examtot{$exam} += $grade{$id,$exam}; # Calculate minimum grades. if ($grade{$id,$exam} < $mingrade) { $mingrade = $grade{$id,$exam}; } # Calculate maximum grades. if ($grade{$id,$exam} > $maxgrade) { $maxgrade = $grade{$id,$exam}; } } # Print student's point total. printf "%10d",$total; # Print student's average. printf "%8d",$total / $exam; # Print student's minimum exam grade. printf "%8d", $mingrade; # Print student's maximum exam grade. printf "%8d\n", $maxgrade; } # Print heading for class averages. printf "\n%6s %${longestname}s ",'',"Average: "; # Calculate and print class averages. foreach $exam (1..$lastexam) { printf "%4d",$examtot{$exam} / $groupsize; } # Exit script. exit(0);
last update time of hardware clock (Windows and Linux) with the Server
2 direct replies — Read more / Contribute
by thanos1983
on Sep 21, 2014 at 17:49

    Hello Monks,

    I am looking for a function that can provide me the last update time of the hardware clock on Windows/Linux OS through Perl.

    Update: The last update time that the OS was synchronized with a time server.

    I have been looking over the web and I can not find something similar. I can find modules to play around with the hardware clock such as Test::MockTime or Time::Mock but they are not suitable from my request.

    I want a function that will reply back with the epoc seconds since the last update time. For example since last update time of hardware clock was 5.7 sec.

    Thank you in advance for your time and effort.

    Seeking for Perl wisdom...on the process of learning...not there...yet!
Why isn't this simple method to join elements of 2 arrays not working
3 direct replies — Read more / Contribute
by Axlex
on Sep 21, 2014 at 10:35
    Hello wise Monks; i am trying to concatenate the lines of 2 files and came up with this simple code
    my (@In, $In, @Out, $Out, $InFile, $OutFile); + # declare variables open $InFile, "<", "e:/File1.txt"; # open the exported +file in read mode open $OutFile, ">>", "e:/File2"; @In = <$InFile>; @Out = <$OutFile>; close $InFile; close $OutFile; for my $k ( 0 .. $#In ) { $Out[$k] = "$Out[$k],$In[$k]"; } open $OutFile, ">", "e:/File2.txt"; # open the outfile, + deleting all content (writemode) print $OutFile @Out; close $OutFile;

    but i am getting the error: "Use of uninitialized value within @Out in concatenation(.) or string at join.pl"

    I know, my programming skills are bad but please, i dont know any other way.


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!
  • 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?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (8)
    As of 2014-09-22 18:19 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

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











      Results (198 votes), past polls