Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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
Statically build XML Parser embedded in Perl
1 direct reply — Read more / Contribute
by Chaks
on Nov 27, 2014 at 12:07

    I am adding a module XML::Parser statically in my Perl which I build from its source. To build Parser statically I removed DynaLoader and bootstrap from Parser.pm and Expat.pm files.

    I have included LINKTYPE => 'static' in Makefile.PL. It builds successfully. But when i am trying to use this module after build its throwing error as "Undefined subroutine &XML::Parser::Expat::ParserCreate called at C:/Perl/lib/XML/Parser/Expat.pm line 66."

    I have linked Expat.lib to my tool and included it as newXS("XML::Parser::Expat::bootstrap", boot_XML__Parser__Expat, file)

    What goes wrong after building the module statically. I tested using 'nmake test_static' which fails but 'nmake test_dynamic' passes without any error.

Retain global value across files
2 direct replies — Read more / Contribute
by Pavanai
on Nov 27, 2014 at 11:53

    i have 2 files A and B. From A, am trying to call a sub routine defined in B

    code snippet A

     verify($fh, 'host', 'state', 'testname');

    code snippet in B

    sub verify { my $fh = shift; my $routes = 375000; my $inet0_total = 3436701; my $inet0_active = 498151; my $inet6_total = 115803; my $pass_count = 1; our $count_adj = 0; our $count_bfd = 0; our $tc_count = 1; ............... $tc_count = $tc_count + 1;

    verify subroutine is called in file A at each testcase s, hence the tc_count should also be incremented. I defined tc_count as global using "our" hoping that tc_count will increment each time when the testcases are executed. But tc_count always shows as 1 for any testcases. Is there a way to retain the tc_count to its current value(after each increment), when the the subroutine verify is called from file A

    here is the output after the execution for reference

    .

    Testcase 1: Disable the process in the router

    ********************************************************** Verify ISIS adjacency(show isis adjacencies) ---------------------------------------- Interface System L State Hold (secs) SNPA ae1.0 paisa 2 Up 26

    Testcase 1: Enable the process in the router

    ********************************************************** Verify ISIS adjacency(show isis adjacencies) ---------------------------------------- Interface System L State Hold (secs) SNPA ae1.0 paisa 2 Up

Game related OO design question
2 direct replies — Read more / Contribute
by blindluke
on Nov 27, 2014 at 08:12

    I'm playing around with a game concept. Here is my basic enemy.

    package Enemy; use Moos; has wounds => (); has att_type => (); has def_type => (); sub BUILDARGS { my ($self, $type) = @_; my %monster = ( 'Rat' => { wounds => 1, att_type => 'light', def_type => 'dodge', }, ); die "Unknown monster type" unless exists $monster{$type}; $monster{$type}{'type'} = $type; return $monster{$type}; } 1; } my $monster = Enemy->new('Rat');

    I'm having some trouble with the design of the attack / defense traits of an enemy. I would like to have multiple attacks with some statistics of their own. Something like this:

    my %attack = ( basic_light => { type => 'light', damage => '1', defmod => { block + => '0', dodge => '0' } }, basic_heavy => { type => 'heavy', damage => '2', defmod => { block + => '0', dodge => '10' } }, );

    During the fight, I will call something like:

    $a = $attacker->choose_attack(); # with the intention of # $a == { type => 'light', damage => '1', defmod => { block => '0', do +dge => '0' } }

    Still, I don't want to pass anything too complex to the constructor. I think that I have to keep the attack definitions within the Enemy class, and to have something to translate the attack type to a pattern.

    For example: att_type => 'medium' would translate to an array of ( $attack{basic_light}, $attack{basic_heavy}), and the choose_attack() method would pick an attack from this array at random. Which would correspond to an enemy that hits heavy about 50% of the time.

    How can I add it to the code in an elegant way? Should I drop the att_type and just initialize the monster with an attack pattern? I humbly seek your words of wisdom. Any advice will be welcome.

    - Luke

How can I merge a number of text files into one in a particular sequence?
3 direct replies — Read more / Contribute
by SamSmith
on Nov 27, 2014 at 08:06
    How can I merge a number of text files into one in a particular sequence? The content of the files are ~ delimited. The files themselves need to be merged in a particular sequence; lowest first. The script needs to loop through a directory of a number of text files. The content of the files are ~ delimited. For example File1.txt File2.txt File3.txt File4.txt -The script needs to loop through a directory containing these files. -File1.txt is the lowest numbered file and should be merged into file File2.txt as well as removing all duplicates from file two. -This leaves us with a merged File1.txt. -File1.txt should ben be merged with File3.txt as well as removing any duplicates from file three. -File1.txt should then be merged with File4.txt as well as removing any duplicates from file four.. -This leaves us with a merged File1.txt containing unique vales off all four files. -The remaining files should then be deleted.
need helpo regarding regular expression
7 direct replies — Read more / Contribute
by praveenchappa
on Nov 27, 2014 at 02:08

    i had a perl script that traverses throuh the file hirarchy and searches for a particular string and gives the count of files the string is present,the problem is when the search string contains '.' the match is not being done ...please help

    $string="hai hello hello.doc yes hai hello.doc present in the file"; $oldstring="hello.doc"; if($string=~ m/\Q$oldstring\E/){ print "\nstring found in ...\n$File::Find::name"; $i++; }

    i am taking $oldstring from command line argunments and $string is contents of file i even tried "hello\.doc"but the match is not being done

merge with multiple row with same key
2 direct replies — Read more / Contribute
by tcheungcm
on Nov 26, 2014 at 21:13
    If I have a hash like:
    'abc,def' => { ,,,item4 , item1,,, , ,item2,, }
    'klm,mno' => { ,item2,, , ,,item3, , }

    I want to the merge the multiple rows with the same key as follow: how should I do it ?

    'abc,def' => {item1,item2,,item4 ,} 'klm,mon' => {,item2,item3, ,}
    how to do it using hash? thanks
regex match multiple line (updated question)
3 direct replies — Read more / Contribute
by natxo
on Nov 26, 2014 at 16:37
    hi, I need to match a series of wonderfully vague MS ldap errors in order to present some decent information to my users. The kind of errors I get is like this:
    00000056: AtrErr: DSID-03190F80, #1: 0: 00000056: DSID-03190F80, problem 1005 (CONSTRAINT_ATT_TYPE), da +ta 0, Att 9005a (unicodePwd)
    Anyway, I created a hash (incomplete, but just to get the idea) with the translations to normal language: So I want to match the key to the error, and I came up with this, but it never matches:

    Edit: I updated the question with a piece of code. The $error comes from the actual error method in Net::LDAP and if I add [] to print it it actually looks like this:

    [00000056: AtrErr: DSID-03190F80, #1: 0: 00000056: DSID-03190F80, problem 1005 (CONSTRAINT_ATT_TYPE), da +ta 0, Att 9005a (unicodePwd) ]
    with the last ']' as only character in the line.
    $error = "00000056: AtrErr: DSID-03190F80, #1: 0: 00000056: DSID-03190F80, problem 1005 (CONSTRAINT_ATT_TYPE), da +ta 0, Att 9005a (unicodePwd) "; my %pwd_reset_errors = ( '0000052D' => "new password does not meet complexity requirements" +, '00000056' => "wrong old password", ); while ( my ( $key, $value ) = each %pwd_reset_errors ) { if ( $key =~ m/^$error.*/ ) { app->log->debug("$value"); } }
    But it is obviously not working. What is wrong with my crappy regular expression? :-) Thanks in advance
Can't locate object method "getElementsByClassName" via package "HTML::TagParser::Element"
2 direct replies — Read more / Contribute
by Vonunov
on Nov 26, 2014 at 14:20

    v@vonunov ~/perl$ perl -v
    This is perl 5, version 16, subversion 3 (v5.16.3) built for amd64-freebsd-thread-multi

    Hi all,

    I don't really "know" perl, I just cobble things together by reading examples and documentation, promptly forgetting how and why I did everything unless I heavily commented it, so it could be that I'm only missing something very basic.

    The error in the title, '"Can't locate object method "getElementsByClassName" via package "HTML::TagParser::Element"', appears only after making a couple of small changes to a previously working script. First, the working version with usage demo:

    Now here's the script that fails. Notice the area around "my $html"; now we're getting #mainbody and *then* finding .type within it. This is to avoid taking in unwanted content that's kept in a sidebar area on the target site.

    [v@vonunov ~/perl]$ ./get-wus-bad.pl infile.txt outfile.txt Can't locate object method "getElementsByClassName" via package "HTML: +:TagParser::Element" at ./get-wus-bad.pl line 31, <$infh.

    (It isn't printing the ">" after infh?)

    After re-re-reading HTML::TagParser I'm still not sure why it's doing this. But see how it says: via package "HTML::TagParser::Element"? If you look at the documentation, getElementsByClassName is not inside "HTML::TagParser::Element SUBCLASS". I don't see anything before my use of getElementByClassName that would have put us in the context of that subclass, so to speak, if that is a thing that happens.

    My use doesn't line up exactly with the documentation, I think. They do "$html = HTML::TagParser->new( $file );" then "@elem = $html->getElementsByClassName( $class );" -- which works for me too -- but is the problem that I'm trying to also put it through another of these functions in turn, or is it something else?

    This script is only for generating a file to feed into another script, so I don't need to get it perfect, only working, but if you have any advice at all, it's welcome.

    Thanks.

    Edit:

    With use diagnostics;

    Still lost.

how is = treated in argument?
7 direct replies — Read more / Contribute
by cch
on Nov 26, 2014 at 13:45
    how does perl treat "=" in argument? when I pass "v=33" as argument "=" disappears.
Can PERL send a 3rd party cookie to a users browser?
3 direct replies — Read more / Contribute
by OpenSpace
on Nov 26, 2014 at 12:16

    Hi

    I am attempting to build an automated logon to a secure site. Users in my clients portal should be able to click a logon button and gain access to the site without any further action needed.

    I have succesfully achieved this using LWP. I am able to pass the page retrieved by LWP back to the user but if the user clicks on link in that page to another page within that secure site they are immediately logged out.

    The reason is because the required session cookie is sitting in LWP's cookie jar on my server and not in the users browser (on their PC)

    Is there any way I can pass the secure sites cookie back to the users browser and still have the browser believe that the cookie has come from the secure sites domain rather than the domain of my server and the LWP program?

    Or is that too much like criminal behaviour! :)

    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
  • 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 pondering the Monastery: (7)
    As of 2014-11-27 20:03 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My preferred Perl binaries come from:














      Results (187 votes), past polls