Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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
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\ (autosplit into blib\lib\auto\Net\SSLeay\ 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 (although when I verify using, it confirms 1.0.1g) .

    I would greatly appreciate guidance to resolve this issue.

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, 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?


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,
a perl code syntax help
3 direct replies — Read more / Contribute
by ghosh123
on Jul 28, 2014 at 06:58

    Hi monk,
    I am working with a Perl which looks like below :

    sub display { $self = shift; if(exists $error){ $html .= "<table border=0>"; $html .= "<tr>"; $html .= "<td align=center ><b>".$self-> {error} +."</b></td>"; $html .= "</tr>"; $html .= "</table><br>"; } $html .= <<END; <table border=0> <tr> <th bgcolor="#CCCCEE">Name</th><th>&nbsp; </th> +<th bgcolor="#CCCCEE">Address</th> </tr> <tr align=center> <td bgcolor="#EEEEEE">@{[ $qry->popup_menu(-id=>'ID +', -name=>'PS', -size=>10, -values=>$array_ref, -labels=>$hash_ref, +-onChange=>"fetchData(id,'','','')") ]}</td> </tr> </table> END return $html; }

    In the above code, what does this <<END and END mean ?
    how can I change the code which is in between that <<END and END, to insert a if-else condition for that popup_menu.

    To clarify further, depending on some values passed to that function, I want another popup_menu which will have a onload function instead of onChange.
    In this above code, how can I do that by writing a if-else condition.

subroutine ref while "strict refs"
5 direct replies — Read more / Contribute
by viffer
on Jul 28, 2014 at 04:37
    Hi all, I've seen a number of emails on this subject but unfortunately haven't managed to find a solution to the specific issue I'm having.

    Essentially I am loading data into a hash of hashes, one field of which contains a sub routine that I need to perform if all the keys match.

    That part is all working fine - except for the fact that unless I turn off strict I can't use it! :)

    Sample data I'm loading into the hash is:

    000.01|RECD_TYPE|01-03|CHAR(3)|RECORD TYPE|check_char 000.02|DATE_TIME| 05-21|CHAR(17)|TIME STAMP|check_time 000.03|DATE_ISSUE|23-30|CHAR(8)|DATE OF ISSUE|check_date 010.01|RECD_TYPE|01-03|CHAR(3)|RECORD TYPE|check_char 010.02|PROP_NUMB|05-11|PIC(9999999)|PROPERTY NUMBER|check_numeric

    I'm loading the data into my hash of hashes table via

    open( $record_layout, '<', $RECORD_LAYOUT ) or die "Open file $RECORD_LAYOUT failed $!"; #Load record formats into a hash. If record layout changes simply chan +ge layout while ($record = <$record_layout>) { chomp $record; my @fields = split(/\|/, $record); my @keys = split(/\./, $fields[0]); $keys[1] =~ s/\s*$//; $keys[1] = int($keys[1]); if (! $rec_layout_hash{$keys[0]}) { $rec_layout_hash{$keys[0]} = {}; } else { $rec_layout_hash{$keys[0]}->{$keys[1]} = {}; } $rec_layout_hash{$keys[0]}->{$keys[1]} = {'field_type' => $fields[1], 'chars_position' => $fields[2], 'field_length' => $fields[3], 'sub_routine' => $fields[5], }; } close $record_layout;
    Then reading the hashes to obtain and call the subroutine via

    my $input_file; my $line; open( $input_file, '<', $ARGV[0] ) or die "Open file $ARGV[0] failed $!"; while ($line = <$input_file>) { chomp $line; my @fields = split(/\|/, $line); #Check if record is a valid record type if ($fields[0] !~ /$record_types/) { fatal_error (2, "record contains invalid file type fields[0] - + Record: $line"); exit 0; } #Check if number of fields in record matches the number in the record +layout my $expected_nbr_of_fields_in_record = keys %{$rec_layout_hash{$fi +elds[0]}}; my $actual_fields_count = @fields; if ($actual_fields_count != $expected_nbr_of_fields_in_record) { fatal_error (1, "record does not contain correct number of fi +elds - Expected $expected_nbr_of_fields_in_record but record containe +d $actual_fields_count fields - $line"); exit 0; } #Process each field from the input data one field at a time for (my $i = 1; $i <= $actual_fields_count; $i++) { my $j = $i; $j -= 1; #$j is minus 1 becau +se the fields array starts at zero, whilst the actual field number in + the record array starts at 1 #Determine which sub routine is required to check the data from the re +cord_layout hash my $sub_routine = $rec_layout_hash{$fields[0]}{$i}{"sub_rout +ine"}; #Call sub routine and pass the actual field day and the expected lengt +h of the fiel my $value1 = $fields[$j]; my $value2 = $rec_layout_hash{$fields[0]}{$i}{"field_length" +}; &{ $sub_routine } ($value1, $value2); } }
    It's when I then call the sub routine that I get the message
    Can't use string ("check_char") as a subroutine ref while "strict refs" in use

    Is there any way I can call the sub routine - which will be in a separate module (not that that should make any difference) without turned off strict? Thanks for your time Kev

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
  • 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?

    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 romping around the Monastery: (8)
    As of 2014-07-28 22:55 GMT
    Find Nodes?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:

      Results (210 votes), past polls