Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
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
Get the number of the current test when debugging a test script
4 direct replies — Read more / Contribute
by Dumu
on Jun 30, 2015 at 07:00

    I'm testing a module I'm developing.

    To run the module, I have a test script which initialises the module.

    e.g.:
    • tests.t
    • module.pm

    There's a bug in the module that is causing the test to fail after a certain test number.

    I'd like to run the test using the Perl debugger perl5db.pl and break after the nth test. Is there a way to monitor the variable showing how many tests have been run?

    Test::Builder has a $current_test package variable but I can't seem to access it. I'm using Test::Most.

how to get the local variable value outside the box
3 direct replies — Read more / Contribute
by bhushanQA
on Jun 30, 2015 at 05:53
    I have this code:
    if ($resp->is_success) { my $location_id= $resp->header( 'Location' ); #my $str = print "Received reply: $message\n"; # print "$message\n"; $location_id=~ /.*\/(\d+)$/; my $location_id= $1 || ''; print "$location_id\n"; }
    The variable location_id's scope is inside the box only, but I want to use the same variable and its value. How Can I use that variable and its value outside the box.
How to pass variable in the LWP module
3 direct replies — Read more / Contribute
by bhushanQA
on Jun 30, 2015 at 05:10
    I am writing code using LWP module ( to send the HTTP request) I am sending HTTP request with following content: $req->content('{"type":"mcc","expression":"716*","order":1,"match-type":"regex-match","category"->'$location_id'}') I want to pass the variable to the "category" part, how Can I pass the variable "$location_id" ( variable is already defined and having some value.)
[perl]how to do using threads to write worksheets of excel
3 direct replies — Read more / Contribute
by L_WC
on Jun 30, 2015 at 04:23
    It can't be wrote in threads in different worksheet, like "$workbookNodeList->sheets()->2->write(0,0, 'j8', $formatNodeList;" it does not work. could anyone help me? How to write worksheets on same time by threads? thanks.
    my $nodeList = [ ['AMS', 'a'], ['APJ', 'ap'], ['EMEA', 'e'], ]; my $workbookNodeList = Excel::Writer::XLSX->new("Node_List.xlsx"); $workbookNodeList->set_properties( title => 'Node List', author => 'L_WC demo', comments => 'Node List', ); my $formatNodeList = $workbookNodeList->add_format(bg_color => 44); $formatNodeList->set_align('center'); my $worksheetNodeList = $workbookNodeList->add_worksheet('AMS'); my $worksheetNodeList1 = $workbookNodeList->add_worksheet('APJ'); my $worksheetNodeList2 = $workbookNodeList->add_worksheet('EMEA'); my @arr = ($nodeList->[0], $nodeList->[1], $nodeList->[2]); my @ar = ('fff'); foreach (@arr) { $_ = threads->new(\&doSomething, $_->[0], $_->[1], $workbookNodeLis +t, $formatNodeList); } foreach(@arr){ $_->join(); } $workbookNodeList->close(); print "Node List is Done."; sub doSomething{ my ($region, $sql, $workbookNodeList, $formatNodeList) = @_; if($region eq 'AMS'){ [$workbookNodeList->sheets()]->[0]->write(0,0, 'rrrrrr', $formatNo +deList); print "AMS -----DONE.\n"; } if($region eq 'APJ'){ [$workbookNodeList->sheets()]->[1]->write(0,0, '1', $formatNodeLis +t); print "APJ -----DONE.\n"; } if($region eq 'EMEA'){ [$workbookNodeList->sheets()]->[2]->write(0,0, 'j8', $formatNodeLi +st); print "EMEA -----DONE.\n"; } }
reading a text file into hash
3 direct replies — Read more / Contribute
by Anonymous Monk
on Jun 30, 2015 at 03:50

    I am new to perl.I have a text file.I want to read it into hash and array.Please help

    { "InstanceStatuses": [ { "InstanceId": "i-308c0b3c", "InstanceState": { "Code": 16, "Name": "running" }, "AvailabilityZone": "us-west-2b", "SystemStatus": { "Status": "ok", "Details": [ { "Status": "passed", "Name": "reachability" } ] }, "InstanceStatus": { "Status": "ok", "Details": [ { "Status": "passed", "Name": "reachability" } ] } } ] }
Perl Scripts Terminates unexpectedly
2 direct replies — Read more / Contribute
by gvbals
on Jun 30, 2015 at 02:13
    We have a set of perl scripts. We don't have any exception handling. Sometime the scripts terminates unexpectedly. How to find out the reason for the same/
multiple backreferences in a substitution
No replies — Read more | Post response
by wrinkles
on Jun 29, 2015 at 23:02
    Gentle Monks,

    I wrote a (perl6) script that collects class definitions from the HTML head in a hash, and inlines the style by substitution into the body. Here's the substitution:

    UPDATE: match is actually coming from the "if" and "while" statements, not the repeated regex as I thought. Works without capture braces in repeated block. Yikes, never mind!

    repeat { # Replace class with inline styles (repeatedly) $new ~~ s/ class \= \" \w+ \" / style="%classes{ $0.Str }" /; } while $new ~~ / class \= \" (\w+) \" /;

    Yes it works, I'm just not convinced there isn't a slicker way. In particular, is there a simple way to substitute a capture at the corresponding match location, using a global substitution ( or something else entirely)?

    TIA! The full script is below:

FOSDEM 2015 - any news on the party?
2 direct replies — Read more / Contribute
by polettix
on Jun 29, 2015 at 17:52
    Hi,

    since when it happened, I'm regularly checking the FOSDEM website for the video of the talk from Larry Wall "get ready to party". It's a bit depressing that so far nothing appeared, and that of all the "main tracks" the one on languages - where the talk should appear - is still empty. I'm using this link: https://video.fosdem.org/2015/.

    Does anyone know if there is some not-so-evident reason that is preventing the release of those videos? Is it just that I need to have some little more patience?

    Thanks, Flavio.

    perl -ple'$_=reverse' <<<ti.xittelop@oivalf

    Io ho capito... ma tu che hai detto?
Restricting access to Perl sacripts based on PKI certs
1 direct reply — Read more / Contribute
by rgwest61
on Jun 29, 2015 at 16:42
    I have a security requirement to limit access to developed Perl scripts within a Linux environment based on a user's PKI certificates. Does something already exist to do such, or is this more of a system security acti
Type::Library messages lost when used with named parameters in Type::Params
1 direct reply — Read more / Contribute
by 1nickt
on Jun 29, 2015 at 15:05

    Hello monks,

    I've noticed that when I use Types that I make with Type::Library, to validate named incoming arguments, with Type::Params, using a slurpy Dict, per the docs, I lose the custom error message set in the library.

    # in package MyModule::Types declare DBPrefix, as Optional[StrMatch[ qr/ \w+_ /x ]], message { 'The table prefix must end in an underscore. ' }; # in package MyModule use Type::Params qw/ compile /; use My::Types qw/ DBPrefix /; state $validate = compile( DBPrefix ); my ($param) = $validate->( @_ ); # in foo.pl $obj->method( 'bar' ); # output: # The table prefix must end in an underscore. (in $_[0]) at ./foo.pl +line 11 # "DBPrefix" is a subtype of "Optional[StrMatch[(?^x: \w+_ )]]" # Value "bar" did not pass type constraint "Optional[StrMatch[(?^x: + \w+_ )]]" (in $_[0]) # $_[0] exists # "Optional[StrMatch[(?^x: \w+_ )]]" constrains $_[0] with "StrMatc +h[(?^x: \w+_ )]" if it exists # Value "bar" did not pass type constraint "StrMatch[(?^x: \w+_ )]" + (in $_[0]) # "StrMatch[(?^x: \w+_ )]" is defined as: do { !ref($_) and $_ =~ $ +Types::Standard::_StrMatch{"(?^x: \\w+_ )"} }

    That's a little more than I really need, but it gives me my custom message at the beginning.

    Now, when I want to go to named arguments, I follow the manual:

    state $validate = compile(slurpy Dict[ prefix => DBPrefix ]); #per the + docs for named args my ($param) = $validate->( @_ ); # in foo.pl $obj->method( 'bar' ); # output : # Reference {"prefix" => "bar"} did not pass type constraint "Dict[pre +fix=>DBPrefix]" (in $SLURPY) at ./foo.pl line 11

    I need to use named args because some of them are completely optional. But I want to be able to return an error that tells the user how to fix the error!

    Has anyone figured a way around this? Thanks ...


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
  • 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 imbibing at the Monastery: (19)
    As of 2015-06-30 17:44 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      What kind of chocolate gives you the most pleasure?















      Results (796 votes), past polls