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

The Monastery Gates

( #131=superdoc: print w/ replies, xml ) Need Help??

Donations gladly accepted

If you're new here please read PerlMonks FAQ
and Create a new user.

Want Mega XP? Prepare to have your hopes dashed, join in on the: poll ideas quest 2013  (Don't worry; you've got plenty of time.)

New Questions
Copying and Running PERL SCRIPTS in Parallel
3 direct replies — Read more / Contribute
by rahulruns
on May 21, 2013 at 03:08

    I am trying to copy PERL SCRIPTS to hosts and then I need to run them in parallel. I am using Net::OpenSSH::Parallel to copy and run the commands. But I am not able to even copy the commands. It is a password less ssh. I am able to generate and store the host list in an array hosts.

    my $pssh = Net::OpenSSH::Parallel->new(); $pssh->add_host($_) for @hosts; $pssh->push('*', scp_put => '/root/cpu.pl', '/root/'); $pssh->push('*', scp_put => '/root/memory.pl', '/root/');
Android App Using Perl
1 direct reply — Read more / Contribute
by g4774g
on May 20, 2013 at 19:04

    Is there a perl module to help with writing an android app? Thx

Reading wrong value from excel sheet
4 direct replies — Read more / Contribute
by sandeep_car
on May 20, 2013 at 13:27

    Hi,

    We upload file in .xlsx or xls format. In this file there is one coloumn for which value is in decimal. For these value for some it shows differnet result while reading from excel file and for some it shows correct result.

    For example:

    at place of 1.14 it comes 1.139999999999999

    at place of 1.13 it comes 1.129999999999999

    where as for some it give correct result.

    Code used for reading .xlsx file is:

    $fileName = $_[0]; $fFnc = $_[1]; $logMsg = new LogMessage(); $logMsg->writeLog( $fFnc, "Reading $fileName \n" ); $FileData = ""; %FileHash = (); %source_headers = (); # For XLSX formats if( $fileName =~ /\.xlsx$/i ) { my $myConv = Text::Iconv->new ("utf-8" +, "windows-1251"); my %xlFileData = (); my $myBook = Spreadsheet::XLSX->new( " +$fileName", $myConv ); if( $myBook ) { foreach my $sheet (@{$myBook->{Work +sheet}}) { $sheet->{MaxRow} ||= $sheet +->{MinRow}; foreach my $row ($sheet -> +{MinRow} .. $sheet -> {MaxRow}) { $sheet -> {MaxCol} +||= $sheet -> {MinCol}; foreach my $col ($s +heet -> {MinCol} .. $sheet -> {MaxCol}) { my $cell = $ +sheet -> {Cells} [$row] [$col]; // At this place it gives incorrect result }

    Code used for reading .xls file is:

    if($fileName =~ /\.xls$/i ) { my $parser = Spreadsheet::ParseExcel-> +new(); my $workbook = $parser->parse( "$fileN +ame" ); if( defined $workbook ) { for my $worksheet ( $workbook->works +heets() ) { my ( $row_min, + $row_max ) = $worksheet->row_range(); my ( $col_min, + $col_max ) = $worksheet->col_range(); for my $row ( +$row_min .. $row_max ) { for my + $col ( $col_min .. $col_max ) { + my $cell = $worksheet->get_cell( $row, $col ); // At this place it gives incorrect result while reading. }

    Please help me on this.

    Thanks,

    Sandeep

Comparing spaceships (cmp and <=> as options)
5 direct replies — Read more / Contribute
by Random_Walk
on May 20, 2013 at 11:31

    Fellow Monks, I seek your Perls of wisdom.

    I have an array of arrays. the lower level arrays are records with values both numeric and alpha. I want to give the user the option to sort on any of these fields. I thought it would be nice to use a simple hash table referencing the record number to sort on and the comparator to use. I am having a problem using a variable containing comparator. Am I missing something or do I just need another approach?

    my $sort = 'hours'; # really comes from a switch my %map = ( # sorting map hours => [0, \sub {<=>}], code => [1, \sub {cmp}], name => [2, \sub {cmp}], ); # example data my @records = ( [10, 'xyz232', 'secret project'], [ 5, 'foo123', 'world domination'], [ 7, 'bar666', 'have a beer'], ); for ( sort {$a->[$map{$sort}->[0]] $map{$sort}->[1] $b->[$map{$sort}->[ +0]]} @records ) { print join ", ", @$_; }

    Update

    among many variations of syntax I also tried the following. I feel it may be getting closer, other than the fact it won't compile :)
    my %map = ( hours => sub {sort { $_[0] <=> $_[0] } };, number => sub {sort { $_[0] <=> $_[0] } };, name => sub {sort { $_[0] <=> $_[0] } };, task => sub {sort { $_[0] <=> $_[0] } };, );

    Cheers,
    R.

    Pereant, qui ante nos nostra dixerunt!
xml document preface
1 direct reply — Read more / Contribute
by fionbarr
on May 20, 2013 at 11:05
    xml_writer constructs this preface:
    <?xml version="1.0"?>
    Is there anything else that (advisedly) might be included?
Why upgrade perl?
6 direct replies — Read more / Contribute
by poulhs
on May 20, 2013 at 04:41

    We (as so many others) use perl intensivly, but we are currently stuck with the stock RHEL6 perl (that is 5.10.1).

    I am considering building our own perl (in /opt/somehwere), adding the modules that we need, and keeping that up-to-date (using jenkins to build our own RPMs for deployment). I have a feeling about the amount of work involved with this (been down that road before), and my boss asked the ultimative question:

    Is it worth it?

    So I started to prepare a what's-the-difference tutorial (from perldelta's), then 5.18.0 came along and threw given/when and ~~ into experimental::smartmatch, so now I am (almost) back to square 0. Almost all I got is some optimizations and some hash-key security...

    Compared to 5.10.1, why should I upgrade to 5.18.0?

    • I know the pain, what is the gain?
    • What do you think is the most important arguments for upgrading to 5.18.0?
    • How will 5.18.0 make us happier, our life easier and sun shine more frequently?
    • Or am I complete lost, and should I continue being stuck with the stock?
    Thank you Monks, for allowing a humble perler interrupt you.

Scalar followed by parenthetical...
3 direct replies — Read more / Contribute
by Anonymous Monk
on May 18, 2013 at 22:15
    Why doesn't the following produce an error??
    #!/usr/bin/perl use warnings; use strict; use Data::Dumper; my @h = ( { A => 1, B => undef }, { A => 2, B => 2 }, { A => 2, B => undef }, ); $_->{B} ||= $_{A} foreach @h; # Bug! print Dumper(\@h);
operation inside reference
3 direct replies — Read more / Contribute
by hegotf
on May 18, 2013 at 09:30

    Hi Monks

    Can anyone explain what does that do? @{$doc->{links} // []}

    I don't understand the // [] part.

    here is the link to entire code: https://gist.github.com/creaktive/4607326

XPath to XML
2 direct replies — Read more / Contribute
by tosaiju
on May 17, 2013 at 09:23
    Dear Perl Monks,

    Are there any modules or functionality to create a XML file from XPATH and Data?

    Lets take we have a list of XPath and Data associated to this, is that possible to construct a well formed xml from this?

    Thanks a lot for the help and guidence.

    Kind Regards,

how does perl handle variables
4 direct replies — Read more / Contribute
by jabirahmed
on May 17, 2013 at 07:27
    @a=qw( 1 2 3 4 a b c g f); $s=0; foreach $i(@a){ $s+= $i; } print $s; $perl a.pl 10
    > in this case it should ideally throw some error but it just considers > a,b,c... as 0 ? why does it do that
Storable alternatives
5 direct replies — Read more / Contribute
by salva
on May 17, 2013 at 07:16
    Are there any good alternatives to Storable?

    I need a serializer that can be instructed to replace some inner objects on the fly just before serializing then using a callback.

    Storable has the STORABLE_freeze and STORABLE_thaw hooks but they are not per-object but per-class and besides that, they are methods of the class, not something that can be controlled by the code calling the serializer.

    I was thinking of extending Storable, but frankly, its code its one of the worst examples of code rot I have ever seen and so, my question.

    update: an example of what I need to do:

    my $data = serialize $tree, sub { my $obj = shift; if (check_some_condition($obj)) { return replace($obj) } return (); # serialize $obj as is };
Try::Tiny catch block with $_ eq ''
3 direct replies — Read more / Contribute
by dd-b
on May 16, 2013 at 17:12

    I'm having trouble with ending up in my catch block without any indication of why. Code blocks like:

    try { $self->_run($self, $row_id, $subject) } catch { $logger->error("run($row_id): $_\n") }; $self->_clear_subject;

    (that $logger is from Log::Log4perl).

    Something happens down in $self->_run() and I end up in the catch block, but with no indication of why.

    So, what are the things that count as "errors" for Try::Tiny? The docs just say "error", which doesn't mean anything terribly precise. The obvious case I know about is die calls. I don't have any die calls with null strings as their arguments. (What I end up with in the catch block is a string that Data::Dumper prints as ''. I know that's not impossible; the error put in $_ may not be "true". But I don't have a die statement with a null string arg, and I wouldn't expect DBIC or any standard module to have a die call with a null string arg.)

    I'm using DBIC database stuff in there, and I know it throws errors (in fact that's the point of this whole setup, to catch any errors it throws), but I don't expect it to throw null string errors; does it sometimes?

    I may also be slightly wrong about how far my code got; I've run into at least one case (that I can't reproduce in a simple environment) where it seemed that $logger->trace("String with undefined $variable substituted"); would log nothing ($variable is undef; I'd expect it to log "String with undefined substituted" and give a warning on stderr about the undef, and that's what a simple program that does only that produces). Other trace level calls through the same $logger in the same module are logged. As I say, I can't reproduce this in a simple case, it may be another example of my getting confused.

New Meditations
What is the impact of 5.18.0?
2 direct replies — Read more / Contribute
by Tux
on May 19, 2013 at 06:53

    I use my laptop as test environment. When all (upgrades) pass on production/utility software, I upgrade my workstation. If that shows no problems after a few weeks, I start upgrading other production servers.

    So I installed 5.18.0 on my laptop as default perl, and then tried to install all CPAN modules I ever used in 5.16.x

    There are just a few things that stand out as a reason for FAILure:

    • Test files that use for $foo qw( … ) { which is now deprecated. The module autor should rewrite that to for $foo (qw( … )) {. I filed RT tickets for all I encountered. Lets hope the authors will fix their code.
    • POD failures. As the POD checker is now way stricter than the old version was, it shows more real trouble. And it should! The problem is that many authors ship the pod tests too, so the test suite will fail if Test::Pod and friends are installed, and thus cpan won't install those modules. That means manual work ignoring the pod errors (and when obvious file RT tickets). Authors: unless you keep in sync with reality and release often, please do not include pod tests in you distribution.
    • Loads of warnings when a module uses given/when as those are now marked experimental. I can ignore the warnings when testing, but will they fill up my logs when run in production code? When the module also uses Test::NoWarnings, one cannot install. A module like MooseX::App now won't install, and it causes many other modules that have this as a prerequisite to fail too.
    • XS authors that never updated ppport.h from Devel::PPPort. Easy to fix.
    • Modules that use Module::Install but ship ancient or incomplete versions of it in inc. The easiest solution for me was to just recursively remove inc/ and all problems vanish. I have no tuits to RT all of them.
    • Several modules fail because they declare optional deps that are actually hard deps, like using JSON::XS, Lexical::Sub or Data::Alias - which won't build under 5.18.0
    • Test failures, or maybe even code failures, due to hash randomization. Unless I am absolutely sure that the test is wrong, I cannot install these modules.
    • Some failures have been reported to the authors but the available fix has not (yet) been applied (like in Template::Toolkit RT#84778) or not yet released (Tk and SQL::Statement). When their repository is open, they build fine from the repo and I am confident the next release will build fine.

    The message is: perl-5.18.0 is awesome, but please please test the module you require before starting the installation on machines other than a test environment.


    Enjoy, Have FUN! H.Merijn
New Cool Uses for Perl
Batch Printing in Linux
1 direct reply — Read more / Contribute
by jmlynesjr
on May 15, 2013 at 15:26

    I had a bunch of music lyrics that I wanted to print and I didn't want to manually drive gedit. I did, however, want to retain the document formatting. I found a hint in Re^2: using Brother QL-570 printer with Perl and also found sample commands in an Ubuntu Community Documentation post for using the Open Office command line interface for batch printing or viewing. The are also posts out there for doing a similar thing with MS-Word.

    The following is what I threw together. It does the job for me, YMMV. I needed to print UTF-8 text files, but Open Office will try to print whatever file you give it using the file extension as a guide to the file format. I have also printed .odt files.

    James

    There's never enough time to do it right, but always enough time to do it over...

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 having an uproarious good time at the Monastery: (17)
As of 2013-05-21 11:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best material for plates (tableware) is:









    Results (431 votes), past polls