Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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
Extract data using snmpget with hash array
1 direct reply — Read more / Contribute
by ivancheng
on Sep 02, 2015 at 06:30
    I would like to make use of snmpget to the MIB data as below
    my ($result, $err) = snmpget( hosts => \@ARGV, snmp => \%snmparam, oids => \%hash );
    The oids information will be read from the file as below. MIB_OID.dat file: interface:. in_octet:. out_octet:. :
    use Net::SNMP::Util; open $input_fh, '<', "MIB_OID.dat" or die 'Could not open file: ', $OS +_ERROR; my %hash; while ( my $line = <$input_fh> ) { chomp $line; last if ! $line; my ( $word1 , $word2 ) = split /:/, $line, 2; $hash{$word1} = $word2; }
    Kindly advise how I can extract the oids data from the $result as I have no idea for it. Ivan
XML Entity Injection with SOAP::Lite
No replies — Read more | Post response
by Scheiy
on Sep 02, 2015 at 05:36

    Hey guys. I know u get this all the time but I'm new here so please be patient with me

    I'm trying to get rid of an entity injection problem using Perl/FCGI and SOAP::Lite 0.69. For this I tried to switch the $DO_NOT_USE_XML_PARSER from 0 to 1 within the SOAP::Lite modul. I tested this with a SOAP call from a web service using wget and it worked quiet nice for me.

    Now I'm trying the same thing with a SOAP Client - and it doesn't work. At least not always. The first request always looks fine, but any further request fail with an "500 Internal Server Error".

    My debugging failed completely. The request always looks nice - in the first call as well as in any further calls - but the response suddenly fails with a "Application failed during request deserialization: Unresolved prefix 'soap' for attribute 'soap:Envelope'" message. What bugs me the most is the different log messages in the error log and the console. The error log always prints out the following (I tried to format the output for u guys to make it easier to read):

    mod_fcgid: stderr: SOAP::Lite - deserialize - start decoding: <?xml version="1.0" encoding="UTF-8"?> <soap:Envelope xmlns:xsi="" xmlns:soapenc="" xmlns:xsd="" soap:encodingStyle="" xmlns:soap=""> <soap:Body> <ping xmlns="TRONServer"> <c-gensym3 xsi:type="xsd:int">42</c-gensym3> </ping> </soap:Body> </soap:Envelope>
    For the output on the console screen i get two different outputs. For the first (working) try I get
    SOAP::Lite - deserialize - start decoding: <?xml version="1.0" encoding="UTF-8"?> <soap:Envelope soap:encodingStyle="" xmlns:soap="" xmlns:xsi="" xmlns:SOAP-ENC="" xmlns:tron="" xmlns:xsd=""> <soap:Body> <pingResponse xmlns="TRONServer"> <numerPlusOne xsi:type="xsd:int">43</numerPlusOne> </pingResponse> </soap:Body> </soap:Envelope>
    while for the second and any other tries it prints out
    SOAP::Lite - SOAP::Parser - start decoding: <?xml version="1.0" encoding="UTF-8"?> <soap:Envelope soap:encodingStyle="" xmlns:soap="" xmlns:xsi="" xmlns:SOAP-ENC="" xmlns:tron="" xmlns:xsd=""> <soap:Body> <soap:Fault> <faultcode>soap:Client</faultcode> <faultstring>Application failed during request deserialization: +Unresolved prefix 'soap' for attribute 'soap:Envelope' </faultstring> </soap:Fault> </soap:Body> </soap:Envelope>
    Notice that in both cases I use the same STDERR method within the SOAP::Lite module:
    print STDERR "SOAP::Lite - deserialize - start decoding: $_[0]\n"; my $parsed = $self->decode($_[0]);
    For the first run this runs through nicely. For any further runs the call seems to crash during the decode process. The decode sub looks like the following:
    sub decode { SOAP::Trace::trace('()'); my $self = shift; $self->parser->setHandlers( Final => sub { shift; $self->final(@_) }, Start => sub { shift; $self->start(@_) }, End => sub { shift; $self->end(@_) }, Char => sub { shift; $self->char(@_) }, ExternEnt => sub { shift; die "External entity (pointing to '$_[1] +') is not allowed" }, ); # my $parsed = $self->parser->parse($_[0]); # return $parsed; # my $ret = undef; eval { $ret = $self->parser->parse($_[0]); }; if ($@) { print STDERR "SOAP::Lite - SOAP::Parser - Error Message: $@\n"; $self->final; # Clean up in the event of an error die $@; # Pass back the error } return $ret; }
    The eval part crashes with the following exit message:
    SOAP::Lite - SOAP::Parser - Error Message: Can't use string ("1") as a +n ARRAY ref while "strict refs" in use at (re_eval 159) line 1.
    Up to this point I couldn't figure out why this is the case and where it crash.

    I think I found the problem. I dogged into the XML::Parser:Lite modul a little deeper and stumbled about a compile sub that did not make much sense for me:

    sub compile { local $^W; # try regexp as it should be, apply patch if doesn't work foreach (regexp(), regexp('??')) { eval qq{sub parse_re { use re "eval"; 1 while \$_[0] =~ m{$_}go }; + 1} or die; last if eval { parse_re('<foo>bar</foo>'); 1 } }; *compile = sub {}; }
    Especially with the parse_re sub it didn't make much sense with me. So I replaced that sub with the XML::Parser::Lite parse_re sub I found in the 0.721 Version of the Lite Modul I found on CPAN - and now it works. I probably have some more testing to do to verify that but for now it seems to work. Thanks for listening :)

Trying to capture a value from a list of values
3 direct replies — Read more / Contribute
by parthodas
on Sep 02, 2015 at 04:48
    I'm trying to capture the first value from a list of values. My script has multiple sub sections. In one, we have declared global variables and then as per requirement we are using them. As per my requirement, I'm calling linux servers(which has 4 values), and try to capture the first value. It is not coming as expected.
    @mylnxsrvrs = split(',', $myhash{SBLLNXSRVRHOSTS}); @mywinsrvrs = split(',', $myhash{SBLWINSRVRHOSTS}); @mysblroot = split(',', $myhash{SIEBELROOT}); @mysblsrvrpath = (',',$myhash{SBLSRVRPATH}); foreach $a (@mylnxsrvrs) {my $lnxsrvr = "$a"; printf "$a $lnxsrvr\n\n";} printf "$lnxsrvr\n"; printf "@mylnxsrvrs";

    The output looks like this --
    dvapoms1 dvapoms1
    dvapoms2 dvapoms2

    dvapoms1 dvapoms2

    If I'm trying to assign the value, it is giving junk result --
    my $lnxsrvrs = "@mylnxsrvrs"; printf "$lnxsrvrs";
    The output shows -- 1
No recursion depth limit?
4 direct replies — Read more / Contribute
by Yary
on Sep 01, 2015 at 21:28
    I have this memory of Perl limiting how deep subroutine recursion could go, but the following test suggests not:
    perl -E 'sub f{say $_[0] unless $_[0] % 10000;exit if $_[0] > 30000;f( +$_[0]+1)};f(1)'

    on perl 5.12 and 5.20, on windows and NetBSD, they both run (and without apparent limit, if you remove the "exit")

    I got bit when debugging a recursive sub, and my perl process hard-froze my Windows 7 machine. The mouse moved but nothing else worked, not ctrl-alt-del, not "Fn-Sleep". I waited about 10 minutes, thinking it would run out of memory and exit, but the machine just stayed frozen :-(

    Just curious if there was a recursion limit, and if so, when was it lifted?

Parsing text string in Perl
4 direct replies — Read more / Contribute
by gbwien
on Sep 01, 2015 at 17:48

    I am trying to get back into Perl and I have a question regarding how best to parse the following

    I have a file which contains many of the following entries

    Time: 1/9/2015-09:01:43.010 Protocol: SMPP ESME: ehttp_rknoe Direction: Outgoing From: To: PDU Type: Full PDU PDU Length: 16 PDU Data: 00000010800000040000005800029a92 Decode Error 0x00000000 Decoded PDU: [ smpp hdr 16 octets ] 00000000: 00 00 00 10 command_length: 16 00000004: 80 00 00 04 command_id: 0x80000004 submit_sm_re +sp 00000008: 00 00 00 58 command_status: 0x00000058 ESME_RTH +ROTTLED 0000000C: 00 02 9A 92 sequence_number: 170642

    I want to parse the complete file in perl and print out time and only those entries that have ESME_RTHROTTLED.

    The file may contain many other entries but I only want to print out this entry

    Thanks tom
Problems with PDF::API2 and TextBlock
1 direct reply — Read more / Contribute
by dougconran
on Sep 01, 2015 at 17:41
    I have an application that uses PDF::API2 (amogst other things to display jpg images) and PDF::TextBlock which has been running without problems on perl5.10.1. However I've just (foolishly, probably) upgraded my server and perl to v5.22.0. I've installed the relevant modules but I'm getting some really weird behaviour. Sometimes the pdf document will print with data and image but as often as not it just prints the initial blank pdf page (which I load from a base pdf doc). After exhaustive testing it would seem that $pdf->image_jpeg is one culprit the other being the TextBlock ->apply method. As far as I'm aware the problem areas work fine in another similar program and sometimes in this one. What's going on and does anyone have any idea how to fix it?
Processing spreadsheet with some cells in ASCII, other cells in UTF-8
3 direct replies — Read more / Contribute
by Amphiaraus
on Sep 01, 2015 at 16:43

    I am writing a Perl program which takes input from a column in an Excel spreadsheet listing names of European cars. This column is named "MenuList". The names of European cars often contain letters with symbols above them that are not seen in English, and which must be encoded in UTF-8 (Examples: , , ). Other cells in the same column lack these foreign symbols and are encoded in ASCII. I am writing out the contents of this column to an *.ini file.

    I am finding that with the code shown below, the car names in ASCII are being written out to the *.ini file without problems, but the car names with foreign symbols - encoded in UTF-8 - are garbled in the *.ini file. These garbled strings are accompanied by the error message "Wide character in print"

    Is there a way to read input from an Excel spreadsheet with mixed encoding (some cells in UTF-8, other cells in ASCII), and write contents of these cells to an *.ini file, with no garbled output in the *.ini from the cells that contained UTF-8 encoding?"

    chomp $menuList[$i]; $decodedMenuList = decode("utf8",$menuList[$i]); $cfg_baselicense->newval($partNumList[$i],"MenuSelection",$decod +edMenuList); $cfg_baselicense->RewriteConfig();
Extracting network information
4 direct replies — Read more / Contribute
by Kasemodder
on Sep 01, 2015 at 12:57
    My apologies, I'm not a perl programmer (more of a bash scripter by trade), but I've inherited a set of perl scripts that need to be updated for a new OS release and I'm in a bit of trouble trying to fix them. What I'm trying to do is extract a number of relevant network parameters to use in other parts of the script.
    #!/usr/bin/perl chomp($syshost = `hostname`); chomp($sysip = `ifconfig | grep -i inet | egrep -v "inet6|127. +0.0.1" | head -n 1 | awk '{print $2}'`); chomp($sysnm = `ifconfig | grep -i inet | egrep -v "inet6|127. +0.0.1" | head -n 1 | awk '{print $4}'`); print "hostname : $syshost\n"; print "IP : $sysip\n"; print "Netmask : $sysnm\n";
    What I end up getting however, does not match the expected result.
    EXPECTED RESULT hostname : IP : Netmask : RECEIVED RESULT hostname : IP : inet netmask destination 1 + Netmask : inet netmask destinat +ion
    If I run the commands in the ` ` sections within my bash shell, I do get the expected result, but with the script, I do not. I've seen some stuff about awk and perl not getting along but it's what I know, and I'm in a bind with inherited code (with 0 comments), a language I am unfamiliar with, and tight deadlines, so any pointers into the right direction would be appreciated.
calling sub with object as param
1 direct reply — Read more / Contribute
by perlnewb4life
on Sep 01, 2015 at 09:38

    Hello i need some help understanding OOP Perl using Moose; i have created a class whose attributes are all subtypes , for validation purposes. Example code :

    package InputData; use Moose; use InputDataSubtypes qw(subtype); has 'attribute' => ( is => 'rw', isa => subtype, required => 1, ); 1;

    I want to pass InputData to a subroutine , then use InputData->attribute , as if i would be using a getter in Java. The InputData->attribute is used to do a query on a mysql database using prepared statement:

    package Operations; use DBI; use DBConnection; use InputData; use Moose; sub querryDatabase() { my($inputData) = @_; my $query = 'select stuff from myTable where attribute = ?'; my $dataSource = DBConnection->getConnection(); my $preparedStatement = $dataSource->prepare($query); $preparedStatement->execute($inputData->attribute) or die "SQL Erro +r: $DBI::errstr\n"; while (my @row = $preparedStatement->fetchrow_array){ print "@row\n +"; } $preparedStatement->finish(); $dataSource->disconnect(); } 1;

    i call the subroutine like this :

    package MainScript; use strict; use warnings; use v5.22; use InputData; use Operations; use Moose; my $myInputData = InputData->new( { attribute => 'caller', } ); #here i do the sub call; Operations->querryDatabase($myInputData);

    But i get the error Can't locate object method "attribute" via package "Operations" at line 28. Any help would be greatly appreciated, also sorry if i didn't format the question appropiatly

Delete entire row without using Win32::OLE
3 direct replies — Read more / Contribute
by ravi45722
on Sep 01, 2015 at 07:26

    I have a excel sheet in the format of XLSX. For reading this I am using Spreadsheet::ParseXLSX. I read the nodes Delete rows in excel & a lot. But all are suggested using Win32::OLE. I am working in RHEL 5. Is there any other module to delete entire row in excel sheets??

    Update: Module name changed

Add your question
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?

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

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (13)
    As of 2015-09-02 13:28 GMT
    Find Nodes?
      Voting Booth?

      My preferred temperature scale is:

      Results (83 votes), past polls