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
Using Perl to automate GDB
2 direct replies — Read more / Contribute
by eloc
on Jul 28, 2014 at 19:46
    Monks, I humbly come before seeking your great wisdom. I essentially want to use Perl to send input commands to GDB, read the output GDB supplies from these commands, and based on that output send more commands to GDB. I believe open2() or open3() may be of use to me. Is this possible? If so could you show me a simple example? However, I am new to Perl, and would deeply appreciate any examples or advice you can provide.
Error with Net::SSLeay
1 direct reply — Read more / Contribute
by grektokomus
on Jul 28, 2014 at 16:38

    Hello Monks,

    I'm working on a simple script to retrieve JSON from an HTTPS web service. The code is being developed on a Windows 2008 server with Active Perl. The script reports an error on compilation, but then successfully retrieves the desired JSON from the Server. I've put substantial effort into eliminating the error and now seek assistance. Here is the declaration and the error:

    #!/usr/bin/perl -w use strict; #use diagnostics; use JSON -support_by_pp; use LWP 6.04; use LWP::UserAgent; use LWP::Protocol::https; use Net::SSLeay 1.63; use IO::Socket::SSL 1.997;
    Use of uninitialized value in subroutine entry at blib\lib\Net\SSLeay.pm (autosplit into blib\lib\auto\Net\SSLeay\randomize.al) line 912.

    Based on a few similar problems found on the internet, I have verified my LWP modules. I have updated to the latest SSLeay Module (which required force install with ppm). I have also installed OpenSSL 1.0.1h from slproweb.com (although when I verify using https://gist.github.com/dolmen/10096474, it confirms 1.0.1g) .

    I would greatly appreciate guidance to resolve this issue.

Spreadsheet::WriteExcel how to maintain row number
2 direct replies — Read more / Contribute
by terrykhatri
on Jul 28, 2014 at 16:14
    My apologies !!

    Original content (below) and title restored by GrandFather.

    Hi,

    First here is the related snippet of code I want to ask your assistance for :

    my $row=1; while ($a = $sth->fetchrow_hashref()) { $worksheet->write_url($row,0, qq({internal:'$a->{OrderID}'!A1})); $worksheet->write($row,0, $a->{OrderID}, $bold); $worksheet->write($row,1, $a->{OrderDate}); $worksheet->write($row,2, $a->{ShippedDate}); $worksheet->write($row,3, $a->{CustomerName}); $worksheet->write($row,4, $a->{ShipVia}); $worksheet->write($row,5, $a->{ShipName}); $worksheet->write($row,6, $a->{ShipAddress}); $worksheet->write($row,7, $a->{ShipCity}); $worksheet->write($row,8, $a->{ShipRegion}); $worksheet->write($row,9, $a->{ShipPostalCode}); $worksheet->write($row,10, $a->{ShipCountry}); $worksheet->write($row,11, $a->{Freight},$number); $freight = $a->{Freight}; $ordttl = $a->{'Total'} + $a->{'Freight'}; $worksheet->write($row,12,$ordttl,$number); $row++; print "Current row number is $row\n";

    After $row++ loop how do I maintain the current $row number so I can add other stuff like grand total to be positioned just after $row++ loop in the same worksheet.

    As you can see above I am printing the current $row after $row++ loop and it shows that current row is 2 this is not I want, I want the next row after $row++ loop, I hope I have made my question clear enough.

    Many many thanks for your help !!

    Terry
Connecting to an instance after spliting it with a regexe
1 direct reply — Read more / Contribute
by jo5621
on Jul 28, 2014 at 14:12

    I have two instance on my cfg file that I am already calling, but I want to take the second argument from my string (which is the password) decrypt it, with a variable we use within the organization and then connect into that instances to run a query which get some info, this is the piece of code I have so far and the format of the instances, user/password@instnace:

    my %options=(); getopts("c:f:h",\%options); my $instance_file = $options{'f'} if defined ($options{f}); my $CollConnect=$options{'c'} if defined ($options{c}); my $CollTableName = 'CCPM_TABLE_SPACE_COLL'; my $DateOraFmt="'YYYYMMDD HH24:MI:SS'"; if (!open(INSTANCES,"$instance_file")) { Amoc::logit("Unable to open file: $instance_file"); } else { while(my $string_inst = <INSTANCES>){ chomp($string_inst); if($string_inst =~ /(.*)\/(.*)@(.*)/) { do { my $pass = (~/path DEC $2); print "$pass\n"; } } } }
Visual Perl/Tk???
5 direct replies — Read more / Contribute
by Anonymous Monk
on Jul 28, 2014 at 13:51

    I am relatively new to Perl, I have used it on and off for a number of years, but never did anything very complicated. I am attempting to create an application for my own use that requires a GUI. I started writing native Perl/Tk, but am becoming a tad overwhelmed, especially with the Geometry managers, I came from an environment where we had tools to create the GUI. I have found and attempted to use several, but most of them require almost as much understanding of Perl/Tk as writing it natively. The only two tools that I have found that seem to do what I want is visual Camel and Eclipse SWT. Camel is unacceptable because it doesn't support very much, and Eclipse SWT appears to generate only Java code. Does anyone know of a free tool that has the functionality of Eclipse SWT, but will generate Perl/tk code? If Eclipse has this functionality, I could not find it. Documentation for most of these type products leave much to be desired. Any help in this direction would be appreciated.

Code Interpretation
6 direct replies — Read more / Contribute
by Perl_Ally
on Jul 28, 2014 at 11:32

    I'm hoping somebody can help me interpret what's going on in the following line of code:

     my @refs = @allrefs[ sort {$a <=> $b} values %uni_refs ];

    As far as I understand,  sort {$a <=> $b} values $uni_refs will sort $uni_refs by its values, numerically descending. Is this a correct interpretation?

    Assuming I'm correct so far, what does it then mean to have @allrefs outside of the square brackets containing the sort?

    Help greatly appreciated.

installing DBD::Sybase
2 direct replies — Read more / Contribute
by fionbarr
on Jul 28, 2014 at 10:02
    I'm having a great deal of trouble installing DBD::Sybase. I have download the sybase libraries, got the latest GCC and C++ compilers from MinGW.org, updated CPAN. most of the errors look like:
    sybase.:Sybase.c ...undefined reference o '_inp_Perl_mg_size' 'sybase.o had bad reloc address 0x20 in section '.eh_frame'
    I am using ActiveState Perl 5.18.2 on Windows 7 I am using ActiveState Perl 5.18.2 on Windows7.
Linear Report with Devel-NYTProf
1 direct reply — Read more / Contribute
by McA
on Jul 28, 2014 at 08:49

    Hi all,

    I couldn't find an answer to the follwing problem, so I hope that someone of you has some pointers.

    I have a script which iterates over an array and does some functionality with every entry. The log shows that the performance per entry degrades very fast. With Devel-NYTProf I was able to identify the portion of code wasting most of the time. The problem was solved after some refactoring. What I couldn't identify was the fact that the performance degraded over time (in the solution before).

    My question now is: Is there a way to see the profiling data written by Devel::NYTProf in a not aggregated but linear way, where I could see at which part of the program the timings get worse?

    Regards
    McA

Trying to navigate the asp page
1 direct reply — Read more / Contribute
by Anonymous Monk
on Jul 28, 2014 at 08:39
    Dear Monks, I try to navigate the search page (an .asp-page, made with MS FrontPage) in our intranet. The navigation buttons are in the html table as follows:
    <TR> <TD ALIGN=LEFT VALIGN=MIDDLE COLSPAN=4> <FORM NAME="fpdbr_0" ACTION="/information/participant.asp" TARGET="_se +lf" METHOD=POST><NOBR><INPUT TYPE=Button NAME="fpdbr_0_PagingMove" VALUE=" -- "><INPUT TYPE=Button NAME="fpdb +r_0_PagingMove" VALUE=" -- "><INPUT TYPE=Submit NAME="fpdbr_0_PagingMove" VALUE=" > "><INPUT TYPE=Submi +t NAME="fpdbr_0_PagingMove" VALUE=" >| "> [1/100]</NOBR><INPUT TYPE=HIDDEN NAME="Name" VALUE=""> </FORM> </TD> </TR>
    I would like to click the third button (with " > ") to move to the next page until there is one. An attempt:
    $mech->click_button( name => 'fpdbr_0_PagingMove', value => ' > ' +);
    brings only:
    No clickable input with name fpdbr_0_PagingMove at ... .
    Another attempt:
    $mech->submit_form(form_name => 'fpdbr_0', button => " > ",);
    and the output:
    No clickable input with name > at ... .
    I tried:
    use Data::Dump; my @forms = $mech->forms(); dd \@forms;
    with the following output:
    [ bless({ accept_charset => "UNKNOWN", action => bless(do{\(my $o = "http://our.intranet/information/part +icipant.asp")}, "URI::http"), attr => { botid => 0, method => "POST" }, default_charset => "UTF-8", enctype => "application/x-www-form-urlencoded", inputs => [ bless({ name => "Name", size => 20, type => "text", value => "", value_name => "", }, "HTML::Form::TextInput"), bless({ type => "submit", value => "Search", value_name => "" }, + "HTML::Form::SubmitInput"), ], method => "POST", }, "HTML::Form"), bless({ accept_charset => "UNKNOWN", action => bless(do{\(my $o = "http://our.intranet/information/part +icipant.asp")}, "URI::http"), attr => { method => "POST", name => "fpdbr_0", target => "_self" } +, default_charset => "UTF-8", enctype => "application/x-www-form-urlencoded", inputs => [ bless({ name => "fpdbr_0_PagingMove", type => "button", value => " -- ", value_name => "", }, "HTML::Form::SubmitInput"), bless({ name => "fpdbr_0_PagingMove", type => "button", value => " -- ", value_name => "", }, "HTML::Form::SubmitInput"), bless({ name => "fpdbr_0_PagingMove", type => "submit", value => " > ", value_name => "", }, "HTML::Form::SubmitInput"), bless({ name => "fpdbr_0_PagingMove", type => "submit", value => " >| ", value_name => "[1/100]", }, "HTML::Form::SubmitInput"), bless({ name => "Name", readonly => 1, type => "hidden", value => "", value_name => "", }, "HTML::Form::TextInput"), ], method => "POST", }, "HTML::Form"), ]
    The first form is on top of the page, simply a search form. The second form is the form I wish to navigate (click on " > " to move on ). Seeking your advice.
Find the row with shortest string for a given input in a csv file.
2 direct replies — Read more / Contribute
by Anonymous Monk
on Jul 28, 2014 at 08:06
    Hi all, So I have a csv file which looks like this:
    A, texttexttext, col3, col4, B, textt, col3, col4, A, text, col3, col4, B, texttex, col3, col4,
    Im concerned with column 1 and 2 only. So as you can see, in row 1 there are two unique ids only -A & B. So for each of the unique ids I want to save the rows which have shortest string in column two. So for above input the output would look like this:
    B, textt, col3, col4, A, text, col3, col4,

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.