Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
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
Parsing with XML::Simple
2 direct replies — Read more / Contribute
by Anonymous Monk
on Aug 23, 2016 at 14:11
    Hi Monks!

    I am trying to get the value of a node that has an attribute, can not get it to work, here is a sample code on how I am trying:
    #!/usr/bin/perl use strict; use warnings; use XML::Simple; use Data::Dumper; use Data::Dump 'pp'; #my $content = $response->decoded_content(); my $content = qq|<?xml version=\'1.0\' encoding=\'UTF-8\'?><soap:Envel +ope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Header><ais:requestID xmlns:ais="http://com"> {7f000001-47db2420000001569783cdb88136} </ais:requestID> </soap:Header> <soap:Body> <soap:Fault> <faultcode>soap:Server</faultcode> <faultstring> check expression: </faultstring> <faultactor>CheckTwo</faultactor> <detail> <longDescription xmlns="http://com"> Exception occurred </longDescription> <MaxCode xmlns="http://com/Server">-2225</MaxCode> </detail> </soap:Fault> </soap:Body> </soap:Envelope>|; #my $parser = new XML::Simple; my $parser= XML::Simple->new( KeepRoot => 1, KeyAttr => [], ForceArray + => [qw( MaxCode )] ); my $result = $data->{'soap:Body'}->{'soap:Fault'}->{'detail'}->{'Error +Code'}; print $result; # I neet to print this::: -2225

    Thanks for looking!
Tie subroutine to a built-in function call?
2 direct replies — Read more / Contribute
by bcarroll
on Aug 23, 2016 at 12:57
    Is it possible to tie a callback/subroutine that will be automatically executed when another function/subroutine is called?

    For example: If I call the built-in open() function, it does it's thing.

    I would like to watch for calls to open() and execute my own subroutine at the same time (before or after, but automatically). Is this possible?

CSV column names
2 direct replies — Read more / Contribute
by Anonymous Monk
on Aug 23, 2016 at 12:21

    Hi, i am making a program that queries a csv file using the DBI module, but can't find out how to get the column names. Can someone help me out. tx.

    use DBI; $dbh = DBI->connect("DBI:CSV:"); $dbh->{'csv_tables'}->{'info'}={'file'=>'info.csv'}; $qu = $dbh->prepare("SELECT * From info"); $qu->execute(); while (@row = $qu->fetchrow_array){ print "@row\n";}
Advice wanted for debugging CPAN Testers failures
1 direct reply — Read more / Contribute
by pryrt
on Aug 23, 2016 at 11:59
    Fellow Monks,

    How do you go about debugging failures from CPAN Testers when your own configurations are not failing? I'd like advice, both in general, and anything you see in my specific examples below.

    For example, this test matrix has a bunch of failures -- but when I test on my machines, I cannot replicate the errors they are getting.

    Before releasing, I tested on a couple of different versions I have access to (strawberry perl 5.24.0_64 on Win7 and an ancient CentOS 4.6 linux 2.6.9-55 with perl 5.8.5), and neither failed my test suite. And since I've seen the CPAN Testers failures, I've started increasing my berrybrew installations to improve version coverage -- but so far, they've all passed, even when they've been on Perl versions that failed in the linux column.

    After I've exhausted available Strawberry installations, I will probably grab one of my linux virtual machines and start increasing perlbrew installations, and run through as many as I can there (I cannot install perlbrew or other local perls on the CentOS machine I noted, due to disk restrictions). But even with trying a new slew of versions, I cannot guarantee that I'll see the same failures that CPAN Testers is showing me.

    I know where I'll be looking for the specific errors: my expected values are wrong; the expected values were being generated by functions I thought were fully tested earlier in my test suite, so I'll have to look into that some more, and also see if maybe I should independently generate the expected values.

    But if I cannot replicate the exact failures from CPAN Testers, it's going to be harder to know I've solved the problem. When doing my last release to add features, I ended up submitting beta versions to CPAN, with extra debug printing, and waiting overnight while the CPAN Testers ran, then basing my fixes on changes in those results. But that's a rather slow debug process... and I noticed that every submission, I was getting fewer results from TESTERS: I think some of those auto-testers have some sort of submission limits, or otherwise remember that a particular module fails and stops testing new versions.

    Any advice, generic or specific, would be welcome.

adding a plus button to change perl GUI dynamically during press (Perl TK)
1 direct reply — Read more / Contribute
by Ganesh Bharadwaj1
on Aug 23, 2016 at 03:27
    Hi Monks,

    I have written the following code. In this code in the 'XY Co-Ordinates and Metal to trace' block, we are rewriting similar code over and over (4 times). I want the user to have a + button, which user can click to add a new X, Y, Metal options pane. This way, user can enter how many ever X, Y, Metal options he wants by clicking the plus button and not be restricted by the 4 X,Y options I have provided.

    But note that whatever value he types in, has to be retrieved when I press the push button. You can see that I am printing the values in the text bar based on the input values provided by the user. Is there a way to modify this code to achieve the required functionality?

    #!/usr/local/bin/perl use Tk; use Tk::widgets qw(LabFrame); use File::Spec::Functions qw(canonpath); use Tk::Optionmenu; use Scalar::Util qw(looks_like_number); use Cwd 'abs_path'; my $o_xco_ordinate; my $o_yco_ordinate; my $o_metal_layer=""; my $o_processoption = "180nm"; my $o_gdsname; my $o_mw = MainWindow->new; # File Entry and Getting File from location. my $o_file_lf = $o_mw->LabFrame( -label => 'File Name', -labelside => 'acrosstop', -foreground => 'blue', ); $o_file_lf->pack( -expand => 0, -fill => 'x', ); my $o_ent = $o_file_lf->Entry( -width => 35, )->grid( -row => 0, -column => 0, -padx => 5, -pady => 5, ); my $o_file_btn = $o_file_lf->Button( -text => 'Select', -command => sub { o_get_file() }, )->grid( -row => 0, -column => 1, -padx => 5, -pady => 5, ); #Entering the metal stack options and metal lines my $o_metaloption_lf = $o_mw->LabFrame( -label => 'XY Co-Ordinates and Metal to trace', -labelside => 'acrosstop', -foreground => 'blue', ); $o_metaloption_lf->pack( -expand => 0, -fill => 'x', ); my $o_frm_metalOption =$o_metaloption_lf ->Frame()->pack; # just for c +entering the buuton row #######################################SETTING DEFAULT################ +################################################ my $o_default_metal = "NONE"; my $o_default_x = ""; my $o_default_y = ""; ##########################################Co-ordinate and metal option +: Row 1 #################################################### #my $o_f_metal = $o_mw->Frame->pack; my $o_f_coord = $o_mw->Frame->pack; #my $o_f_coord = $o_mw->Frame->pack; $o_f_coord->Label(-text => 'X1:')-> grid(-row=>0,-column=>0)->pack(-si +de => 'left'); # Setting the default entry values. my $o_e_x = $o_f_coord->Entry(-textvariable => \(my $o_x = $o_default_ +x)) -> grid(-row=>0,-column=>1)->pack(-side => 'l +eft'); $o_f_coord->Label(-text => 'Y1:')-> grid(-row=>0,-column=>2)->pack(-si +de => 'left'); my $o_e_y = $o_f_coord->Entry(-textvariable => \(my $o_y = $o_default_ +y)) -> grid(-row=>0,-column=>3) ->pack(-side => ' +left'); my $o_o_metal = $o_f_coord->Optionmenu( -options => [[M1=>"M1"], [M2=>"M2"], [M3=>"M3"], [M4=>"M4"],[ +M5=>"M5"],[M6=>"M6"],[M7=>"M7"], [M8=>"M8"],[B1=>"B1"],[B2=>"B2"],[B3 +=>"B3"],[B4=>"B4"],[BA=>"BA"],[BB=>"BB"], [BD=>"BD"], [BE=>"BE"], [FA +=>"FA"], [FB=>"FB"], [L1=>"L1"], [L2=>"L2"], [L3 =>"L3"],[EA=>"EA"], +[EB=>"EB"], [LB=>"LB"],[NONE=>" "]], -variable => \ my $o_metal, -textvariable => \ my $o_t_metal, )-> grid(-row=>0,-column=>4) ->pack; # Set the default option. #$o_metal = $o_default_metal; $o_t_metal = $o_default_metal; ##########################################Co-ordinate and metal option +: Row 2 #################################################### my $o_f_coord2 = $o_mw->Frame->pack; #my $o_f_coord = $o_mw->Frame->pack; $o_f_coord2->Label(-text => 'X2:')-> grid(-row=>0,-column=>0)->pack(-s +ide => 'left'); # Setting the default entry values. my $o_e_x2 = $o_f_coord2->Entry(-textvariable => \(my $o_x2 = $o_defau +lt_x)) -> grid(-row=>0,-column=>1)->pack(-side => 'l +eft'); $o_f_coord2->Label(-text => 'Y2:')-> grid(-row=>0,-column=>2)->pack(-s +ide => 'left'); my $o_e_y2 = $o_f_coord2->Entry(-textvariable => \(my $o_y2 = $o_defau +lt_y)) -> grid(-row=>0,-column=>3) ->pack(-side => ' +left'); my $o_o_metal2 = $o_f_coord2->Optionmenu( -options => [[M1=>"M1"], [M2=>"M2"], [M3=>"M3"], [M4=>"M4"],[ +M5=>"M5"],[M6=>"M6"],[M7=>"M7"], [M8=>"M8"],[B1=>"B1"],[B2=>"B2"],[B3 +=>"B3"],[B4=>"B4"],[BA=>"BA"],[BB=>"BB"], [BD=>"BD"], [BE=>"BE"], [FA +=>"FA"], [FB=>"FB"], [L1=>"L1"], [L2=>"L2"], [L3 =>"L3"],[EA=>"EA"], +[EB=>"EB"], [LB=>"LB"],[NONE=>" "]], -variable => \ my $o_metal2, -textvariable => \ my $o_t_metal2, )-> grid(-row=>0,-column=>4) ->pack; # Set the default option. #$o_metal = $o_default_metal; $o_t_metal2 = $o_default_metal; ##########################################Co-ordinate and metal option +: Row 3 #################################################### my $o_f_coord3 = $o_mw->Frame->pack; #my $o_f_coord = $o_mw->Frame->pack; $o_f_coord3->Label(-text => 'X3:')-> grid(-row=>0,-column=>0)->pack(-s +ide => 'left'); # Setting the default entry values. my $o_e_x3 = $o_f_coord3->Entry(-textvariable => \(my $o_x3 = $o_defau +lt_x)) -> grid(-row=>0,-column=>1)->pack(-side => 'l +eft'); $o_f_coord3->Label(-text => 'Y3:')-> grid(-row=>0,-column=>2)->pack(-s +ide => 'left'); my $o_e_y3 = $o_f_coord3->Entry(-textvariable => \(my $o_y3 = $o_defau +lt_y)) -> grid(-row=>0,-column=>3) ->pack(-side => ' +left'); my $o_o_metal3 = $o_f_coord3->Optionmenu( -options => [[M1=>"M1"], [M2=>"M2"], [M3=>"M3"], [M4=>"M4"],[ +M5=>"M5"],[M6=>"M6"],[M7=>"M7"], [M8=>"M8"],[B1=>"B1"],[B2=>"B2"],[B3 +=>"B3"],[B4=>"B4"],[BA=>"BA"],[BB=>"BB"], [BD=>"BD"], [BE=>"BE"], [FA +=>"FA"], [FB=>"FB"], [L1=>"L1"], [L2=>"L2"], [L3 =>"L3"],[EA=>"EA"], +[EB=>"EB"], [LB=>"LB"],[NONE=>" "]], -variable => \ my $o_metal3, -textvariable => \ my $o_t_metal3, )-> grid(-row=>0,-column=>4) ->pack; # Set the default option. #$o_metal = $o_default_metal; $o_t_metal3 = $o_default_metal; ###################################################################### +############################################################ #Entering the metal stack options and metal lines ##########################################Co-ordinate and metal option +: Row 4 #################################################### my $o_f_coord4 = $o_mw->Frame->pack; #my $o_f_coord = $o_mw->Frame->pack; $o_f_coord4->Label(-text => 'X4:')-> grid(-row=>0,-column=>0)->pack(-s +ide => 'left'); # Setting the default entry values. my $o_e_x4 = $o_f_coord4->Entry(-textvariable => \(my $o_x4 = $o_defau +lt_x)) -> grid(-row=>0,-column=>1)->pack(-side => 'l +eft'); $o_f_coord4->Label(-text => 'Y4:')-> grid(-row=>0,-column=>2)->pack(-s +ide => 'left'); my $o_e_y4 = $o_f_coord4->Entry(-textvariable => \(my $o_y4 = $o_defau +lt_y)) -> grid(-row=>0,-column=>3) ->pack(-side => ' +left'); my $o_o_metal4 = $o_f_coord4->Optionmenu( -options => [[M1=>"M1"], [M2=>"M2"], [M3=>"M3"], [M4=>"M4"],[ +M5=>"M5"],[M6=>"M6"],[M7=>"M7"], [M8=>"M8"],[B1=>"B1"],[B2=>"B2"],[B3 +=>"B3"],[B4=>"B4"],[BA=>"BA"],[BB=>"BB"], [BD=>"BD"], [BE=>"BE"], [FA +=>"FA"], [FB=>"FB"], [L1=>"L1"], [L2=>"L2"], [L3 =>"L3"],[EA=>"EA"], +[EB=>"EB"], [LB=>"LB"],[NONE=>" "]], -variable => \ my $o_metal4, -textvariable => \ my $o_t_metal4, )-> grid(-row=>0,-column=>4) ->pack; # Set the default option. #$o_metal = $o_default_metal; $o_t_metal4 = $o_default_metal; ###################################################################### +############################################################ #Running the file my $o_run_lf = $o_mw->LabFrame( -label => 'Run', -labelside => 'acrosstop', -foreground => 'blue', ); $o_run_lf->pack( -expand => 1, -fill => 'both', ); my $o_but = $o_run_lf->Button( -text => "Go!", -command => \&o_push_button, )->pack; # clear my $o_but_clear = $o_run_lf->Button( -text => "Clear Text Box", -command => \&o_clearme, )->pack; #Text Box my $o_txt = $o_run_lf->Scrolled( 'Text', -width => 40, -height => 15, -wrap => 'word', -scrollbars => 'e', -background => 'white', ); $o_txt->pack( -expand => 1, -fill => 'both', -padx => 5, -pady => 5, ); MainLoop; #SUB PROCEDURES sub o_get_dir { # JFileDialog works better on Windows XP ;) #my @a_types = (["Layout files", [qw/.gds .oas .oas.gz .gds.gz/]]); my $o_dir_dlg = $o_mw->chooseDirectory(-initialdir => '~', -title => 'Choose a directory'); print "$o_dir_dlg selected as directory\n"; #return($o_file_dlg); # Use getOpenFile if that's not important # my $o_file_dlg = $o_mw->JFileDialog( # -Title => 'File name', # -Create => 0, # -Path => File::HomeDir->my_documents, # -FPat => '*.txt', # -ShowAll => 'NO' # ); # my $o_file = $o_file_dlg->Show(-Horiz => 1); my $o_dir = $o_dir_dlg; unless ($o_dir) { print "cancelled...\n"; return; } $o_dir = canonpath($o_dir); o_update_dir($o_dir); return($o_dir); } sub o_update_dir { my $o_value_dir = shift; $o_entdir->delete( 0, 'end' ); $o_entdir->insert( 0, $o_value_dir ) if defined $o_value_dir; return; } sub o_clearme { $o_txt-> delete("1.0",'end'); } sub o_push_button { if (($o_x eq "") || ($o_y eq "") || ($o_metal eq "")) { $o_metal = ""; $o_x = ""; $o_y = ""; } if (($o_x2 eq "") || ($o_y2 eq "") || ($o_metal2 eq "")) { $o_metal2 = ""; $o_x2 = ""; $o_y2 = ""; } if (($o_x3 eq "") || ($o_y3 eq "") || ($o_metal3 eq "")) { $o_metal3 = ""; $o_x3 = ""; $o_y3 = ""; } if (($o_x4 eq "") || ($o_y4 eq "") || ($o_metal4 eq "")) { $o_metal4 = ""; $o_x4 = ""; $o_y4 = ""; } if (($o_x5 eq "") || ($o_y5 eq "") || ($o_metal5 eq "")) { $o_metal5 = ""; $o_x5 = ""; $o_y5 = ""; } if (($o_x6 eq "") || ($o_y6 eq "") || ($o_metal6 eq "")) { $o_metal6 = ""; $o_x6 = ""; $o_y6 = ""; } if (($o_x7 eq "") || ($o_y7 eq "") || ($o_metal7 eq "")) { $o_metal7 = ""; $o_x7 = ""; $o_y7 = ""; } $o_txt->insert( 'end', "$o_x $o_y $o_metal\n" ); $o_txt->insert( 'end',"$o_x2 $o_y2 $o_metal2 \n"); $o_txt->insert( 'end',"$o_x3 $o_y3 $o_metal3 \n"); $o_txt->insert( 'end',"$o_x4 $o_y4 $o_metal4 \n"); $o_txt->update(); } sub o_get_file { my @o_types = (["Layout files", [qw/.gds .oas .oas.gz .gds.gz/]] ); my $o_file_dlg = $o_mw->getOpenFile(-filetypes => \@o_types) or retu +rn(); print "$o_file_dlg selected\n"; my $o_file = $o_file_dlg; unless ($o_file) { print "cancelled...\n"; return; } $o_file = canonpath($o_file); o_update_file($o_file); return($o_file); } sub o_update_file { my $o_value = shift; $o_ent->delete( 0, 'end' ); $o_ent->insert( 0, $o_value ) if defined $o_value; return; }
    thanks,
Good Perl-based web Calendar Frameworks?
1 direct reply — Read more / Contribute
by Cody Fendant
on Aug 22, 2016 at 22:31

    I'm trying to set up a calendaring system at work (various events start or finish on any given day and I need to be reminded of them) and I'd like it to be something created in Perl.

    Any recommendations for a web framework/module which has good calendar functions? Obviously, online calendar output by day, week, month etc. would be good but also email functions to say "don't forget X happens today".

reset libpath
1 direct reply — Read more / Contribute
by pdupre
on Aug 22, 2016 at 21:41
    Hello, I need to change my libpath. ldconfig -p|grep gsl libgsl.so.19 (libc6,x86-64) => /lib64/libgsl.so.19 libgsl.so (libc6,x86-64) => /lib64/libgsl.so I wish to change libgsl.so => /usr/local/mygsl/lib/libgsl.so How can I do ? thank
    Patrick Dupre Universite du Littoral, FR Dunkirk
CamelCase really that bad?
3 direct replies — Read more / Contribute
by gzartman
on Aug 22, 2016 at 21:05

    So, I started a pretty big project and decided to use CamelCase for vars and methods because some other classes I was using used it, and quite honestly I like it better. :)

    However, now I'm starting to question me decision. I'm starting to wonder if I should have followed the more traditional approach as detailed in the Camel. I'm still at a place I can convert over (with only moderate pain).

    I'm curious what you guys think? Is going with camelCase for vars and methods really that big of a deal?
Devel::Cover for myfile.pl with different command-line input arguments
2 direct replies — Read more / Contribute
by tito80
on Aug 22, 2016 at 15:08
    Hi PerlMonks,

    I am a newbie and pardon my ignorance. I am trying to use Devel::Cover (DC) to get an idea of the code coverage of my my_file.pl ran with arg1 arg2, etc. as command-line input arguments. I am using Perl 5.8.9 with 1.23 DC. The steps I executed successfully to generate the html file are:

    1) perl -MDevel::Cover my_file.pl -arg1 <arg1_value> -arg2 <arg2_value>

    2) Devel-Cover-1.23/bin/cover cover_db --report=html

    Now, I do not have packages/modules to test directly. But I have the my_file.pl file which invokes several packages.

    And I need to test my_file.pl with several different combinations of command line i/p arguments (i.e. <arg1_different_value1>, <arg2_different_value_2>, etc.). All these test combinations are a part of my regression suite (you can think of the options written in a test.txt file sequentially) and I am trying to see if Devel::Cover can assure that I have 100% code coverage with these tests.

    While I can run the above in a for-loop, each time with different arguments, I am not sure if that is the best way since I will end up with 100's of html/report files that need to be merged for any meaningful purpose.

    Could you kindly provide some pointers?

    Thanks, Tito

Leading empty array elements after splitting
3 direct replies — Read more / Contribute
by Anonymous Monk
on Aug 22, 2016 at 11:16

    I'm attempting to extract numbers from codes in this generalised format (always begin with MD:Z: but what follows is variable):

    MD:Z:4C3C7C0T2^T9C44

    Desired output (separate array elements):

    4 3 7 0 2 9 44

    As I need to maintain positional information and length of each number (i.e. it must be clear that 44 = 44 and not the product of something like 4T4 after screening out letters) i've tried to use split:

    my @test = split((/\D/g), $input);

    To split on any non-number; however this returns a set of leading empty array values arising from the consecutive matches on 'MD:Z:'. Is there a way to suppress these or a better way to go about getting the desired result?


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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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?
    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 rifling through the Monastery: (4)
    As of 2016-08-23 21:19 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      The best thing I ever won in a lottery was:















      Results (331 votes). Check out past polls.