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
Unable to load LibXSLT.dll on Perl 5.16
1 direct reply — Read more / Contribute
by jes
on May 24, 2013 at 02:34

    I had installed LibXSLT module in a 32 bit Windows machine which worked fine with perl 5.6 but Perl 5.16 (Active state) could not load LibXSLT.dll.

    Is it possible to upgrade from 5.6 to 5.16 with the same dll files?

    I wanted to use the same perl for 64 bit machine as wel. Is it possible to use single perl for both 32 & 64 bit machine?

    ERROR Cant Load 'C:/PROGRA~2/Data/lib/perl5/site/lib/auto/XML/LibXSLT/LibXSLT.xs.dll' for module XML::LibXSLT: load_file:The specified module could not be found at C:/PROGRA~2/Data/lib/perl5/lib/DynaLoader.pm line 191. at C:/PROGRA~2/Data/lib/perl5/site/lib/XML/LibXSLT.pm line 44. BEGIN failed--compilation aborted at C:/PROGRA~2/Data/lib/perl5/site/lib/XML/LibXSLT.pm line 44.

    CODE: LibXSLT.pm
    38 bootstrap XML::LibXSLT $VERSION; 39 40 # the following magic lets XML::LibXSLT internals know 41 # where to register XML::LibXML proxy nodes 42 INIT_THREAD_SUPPORT() if XML::LibXML::threads_shared_enabled(); 43 $USE_LIBXML_DATA_TYPES = 0; 44 }

    Please suggest how to solve this error

    Thanks in Advance
help with simplifying program
3 direct replies — Read more / Contribute
by crunch_this!
on May 24, 2013 at 01:06

    Hi again

    I've got this part of my program, which is meant to go through all possibilities of w, x, y, z, except for when they're evenly spaced apart, or in arithmetic sequence if that makes sense to you. Since I already know those cases won't give me what I'm looking for I want to save perl the trouble of considering them. Here's what I've come up with, but I have a feeling there's a way to make it go faster. I wonder if I really need that s variable since it's just one more thing to deal with:

    foreach my $w (3..100) { foreach my $x (2..$w-1) { foreach my $y (1..$x-1) { foreach my $z (0..$y-1) { foreach my $s (1..20) { unless ( $x == $w + $s && $y == $x + $s && $z == $ +y + $s ) {

    I can add more context if you want, this is just part of the program which works fine I just thought I'd see if there's a way to streamline it.

Client-Side HTTP Handlers
1 direct reply — Read more / Contribute
by konnjuta
on May 23, 2013 at 20:20

    I've got a closed source client/server software that communicate through HTTP. Unfortunately, neither the client nor the server has any authentication module for HTTP communication.

    To overcome this I've set up an nginx proxy on the server. However I still need a HTTP handler clientside to capture all outgoing client requests and manipulate it to encompass the authentication mechanism used by the proxy.

    How can I use Perl to do this?
Win32::GUI make file test fail
2 direct replies — Read more / Contribute
by hurnhu
on May 23, 2013 at 19:29

    bean trying to install Win32::GUI, have tried force, uninstalled and reinstall of strawberry, tried to build it, but here is the error i get when i cpan Win32::GUI

    In file included from Scintilla.xs:8:0: ../GUI.h:768:22: warning: 'ImageList_Duplicate' redeclared without dll +import att ribute: previous dllimport ignored [-Wattributes] Scintilla.xs: In function 'CallWndProc': Scintilla.xs:199:101: error: 'GWL_USERDATA' undeclared (first use in t +his functi on) Scintilla.xs:199:101: note: each undeclared identifier is reported onl +y once for each function it appears in dmake: Error code 129, while making 'Scintilla.o' dmake.exe: Error code 255, while making 'subdirs' ROBERTMAY/Win32-GUI/Win32-GUI-1.06.tar.gz C:\strawberry\c\bin\dmake.exe -- NOT OK CPAN: YAML::XS loaded ok (v0.39) Running make test Can't test without successful make Running make install Make had returned bad status, install seems impossible Stopping: 'install' failed for 'Win32::GUI'.

    perl vr: 5.16.3

How do I synchronize data to common timestamp
1 direct reply — Read more / Contribute
by lewnewby
on May 23, 2013 at 18:47

    Let me get this over up front, I am a relatively new perl user (Starting over after 15 years).

    I have been working on extracting data from a management server via an API supplied by the vendor. So far that is all working great, I am able to get the data. My problem arises in that when I receive the data it will have some odd offset in the time stamps.

    I make a call requesting data at the default sample rate of 60 seconds over a period of 1 day. The API returns the data in a sequence of Key:Value pairings for each counter I am retrieving. The first counter may have X secs:Value and proceed through at 60 second increments. Ok great so far, the second and forth counters may return to the top with the first and X is the time stamp but the third counter returns to the top and may be X+6 secs instead of X.

    The data ends up looking like this:

    2013-05-21 18:46:44,221.667,9.041,92.133,4.008,84.450,6.220,8.983,2.57 +0,5.917,6.710,87.067,6.133 2013-05-21 18:46:45,7.519,5.069 2013-05-21 18:47:44,33.617,2.817,70.900,2.931,161.000,9.811,8.233,2.28 +0,5.617,6.010,86.117,8.108,6.067,5.304 2013-05-21 18:48:44,26.417,1.758,38.933,2.550,42.900,3.526,5.750,1.515 +,4.867,6.132,86.433,6.067 2013-05-21 18:48:45,7.562,5.068 2013-05-21 18:49:44,42.683,2.308,33.633,2.208,42.983,3.807,6.033,1.751 +,4.900,6.042,87.300,8.118,5.983,5.207 2013-05-21 18:50:44,86.983,8.791,103.417,7.851,62.900,8.295,15.500,4.4 +21,8.300,9.368,87.800,7.697,6.050,5.202 2013-05-21 18:51:44,50.033,2.840,63.350,3.071,36.817,3.134,6.217,1.480 +,4.783,5.444,88.433,6.150 2013-05-21 18:51:45,7.725,5.275 2013-05-21 18:52:44,50.017,3.071,61.033,2.538,45.317,4.027,6.233,1.769 +,4.767,5.653,88.383,8.086,5.550,4.966 2013-05-21 18:53:44,38.850,2.265,43.100,2.051,42.683,3.795,5.883,1.403 +,4.850,5.667,89.700,6.000 2013-05-21 18:53:45,7.164,5.061 2013-05-21 18:54:44,22.000,1.741,42.817,2.352,41.700,3.430,5.700,1.543 +,5.567,5.756,87.517,7.939,6.300,5.188 2013-05-21 18:55:44,62.700,6.359,78.267,6.949,58.883,6.804,12.350,3.60 +1,8.200,9.379,87.550,7.349,6.017,5.114

    I would like it to look like this:

    2013-05-21 18:47:00,30.400,2.157,9.900,1.315,39.917,4.201,6.383,1.798, +5.167,7.250,129.950,7.965,5.667,4.892 2013-05-21 18:48:00,33.917,2.276,7.017,1.052,40.150,3.489,5.233,1.440, +4.900,6.393,129.850,8.257,6.033,5.191 2013-05-21 18:49:00,31.867,2.567,10.367,1.337,45.467,4.138,6.417,1.796 +,5.267,7.148,124.867,8.340,5.983,4.897 2013-05-21 18:50:00,57.533,2.943,8.800,1.063,41.867,3.701,5.083,1.445, +4.900,6.176,129.517,7.715,5.867,4.925 2013-05-21 18:51:00,72.900,10.128,103.833,6.560,66.317,6.734,14.933,4. +398,11.267,11.092,119.767,7.753,6.100,5.121 2013-05-21 18:52:00,23.950,1.803,7.217,1.460,50.667,3.845,5.183,1.492, +4.583,5.481,124.500,9.369,6.017,5.030 2013-05-21 18:53:00,25.500,1.910,9.767,1.754,49.467,4.112,6.133,1.772, +23.117,17.196,127.583,8.158,6.067,5.076 2013-05-21 18:54:00,47.350,2.344,8.833,1.419,47.283,3.875,5.400,1.409, +4.867,6.035,148.567,8.428,5.883,4.940 2013-05-21 18:55:00,29.067,2.338,10.400,1.789,45.067,3.250,6.233,1.795 +,5.100,5.866,126.517,7.990,6.133,5.219

    Here is the code I am using to do this:

    my ($list, $obj, $server_ctx) = @_; my @objList = @{ $list }; my (@counter_arr,$objName,@perf_cnt_data,%perfhash); my $gen_time_arr = 1; my $gen_hash_hdr = 1; my $obj_i = 0; my ($rec,$tmpHDR,$tmpVAL); if ($obj eq "system") { $obj = "host"; } $perfhash{"Time"} = ""; foreach my $perf_out ( @objList ){ my $instance = $perf_out->child_get("perf-instances"); my @instances = $instance->children_get("perf-instance-counter +-data"); foreach $rec (@instances){ my $obj_id = $rec->child_get_string("object-id"); my $IterStart = NaElement->new("$obj" . "-list-info-iter-s +tart"); $IterStart->child_add_string("object-name-or-id","$obj_id" +); my $output = $server_ctx->invoke_elem($IterStart); if ( $output -> results_status()=~/failed/ ) { print "\n\n\tFailed to get list of $obj: Error: ".$out +put->results_reason(). "\n\n"; } else { my $records = $output->child_get_int("records"); my $tag = $output->child_get_string("tag"); $output = $server_ctx->invoke("$obj" . "-list-info-ite +r-next", "maximum", $records, "tag", $tag); if ( $output -> results_status()=~/failed/ ) { print "\n\n\tFailed to iterate list of $obj : Erro +r: ".$output->results_reason(). "\n\n"; } } my $aggregates = $output->child_get("$obj" . "s"); my @aggregateArr = $aggregates->children_get(); foreach my $aggr (@aggregateArr) { $objName = $aggr->child_get_string("$obj" . "-name"); $objName =~ s/\///g; } my $counters = $rec->child_get("counters"); @perf_cnt_data = $counters->children_get("perf-counter-dat +a"); my $rec1; # TODO If the counter is aggregate:pa_max_disk_busy and returns nothin +g get the max of disk:disk_busy for the aggregate foreach $rec1 (@perf_cnt_data) { my $counter_name = $rec1->child_get_string("counter-na +me"); my $counter_str = $rec1->child_get_string("counter-dat +a"); my @counter_arr = split (',', $counter_str); my $colName = $objName . ":" . $counter_name; chomp($colName); $tmpHDR = $perfhash{"Time"}; $perfhash{"Time"} = join( ',' , $tmpHDR , $colName); for (@counter_arr) { my ($time,$value) = split(':',$_); my @timestamp = ( localtime($time) )[0..5]; $time = POSIX::strftime( '%F %H:%M:%S', @timestamp +); if ($gen_time_arr == 1) { $perfhash{$time} = join('' , "," , $value); $gen_time_arr = 0; }else { if ($perfhash{$time}) { $tmpVAL = $perfhash{$time}; } else { $tmpVAL = ""; } $perfhash{$time} = join( ',' , $tmpVAL , $valu +e); } } } } } return(\%perfhash); }

    Thanks in advance

    Lew

Equivalent for delayed_job?
2 direct replies — Read more / Contribute
by parkan
on May 23, 2013 at 18:26

    I need to run background tasks at arbitrary points in the future, with queue behavior if multiple execute at or near the same time, ability to manipulate the task list, retry (ideally with exponentially longer retry window), etc.

    In Ruby, there is delayed_job (and php port djjob), which does this pretty much perfectly.

    The closest Perl solution I could find was Beanstalk::Job, but this doesn't appear to support execution in the "far future" (next week). There is also Schedule::At, which does (and also allows manipulation of the tasks) but it runs external commands and the jobs appear to be executed straight with no queueing mechanism

    Is there something that's more like delayed_job? Do I need to roll my own? Also: beanstalkd appears to be memory resident, mostly, and I'd prefer to have a db/disk backed queue
pagination script to work with SQL server
2 direct replies — Read more / Contribute
by pearlgirl
on May 23, 2013 at 16:57
    Hi everyone, I'm using this script for pagination:
    declare \@limit int declare \@offset int set \@offset = $offset; set \@limit = $limit; declare \@idxini int declare \@idxfim int select \@idxfim = \@offset * \@limit select \@idxini = \@idxfim - (\@limit-1); WITH paging AS ( SELECT ROW_NUMBER() OVER (order by table_ID) AS rowid, * FROM table ) select * from paging where rowid between \@idxini and \@idxfim order by rowid; ; END_ROW2
    I need to add joins, and specify other columns besides rowid and *, but it stops working ( no results returned) as soon as I modify it from the format below. It HAS to be 1 table and it HAS to be "select rowid, *"... Even just removing the * stops it from working. I tried running different variations of the script in SQL Server (joining other tables, changing columns, etc.) and it works just fine. It's only within the perl file that it starts acting finicky. I have no idea why. Can someone help me, please? Any recommendations on other pagination scripts that work with SQL Server are welcome too. Thank you!
Duplicate Results from Subroutine
2 direct replies — Read more / Contribute
by zenrhino
on May 23, 2013 at 16:12
    Greetings, Monks.

    I'm working my way through Learning Perl 6th Ed and doing an expansion of Probs. 1-3 on pp. 78.

    My problem is that is I use the @abvlist array as seen on list 16, I get the correct answer. If I call the function directly as on line 17, I get a duplicate set of the answer. I am at a loss as to why this happens.

    I suspect, that as with most things in Perl, it's going to be something simple and small I'm looking right over.

    Run as is, I get the following:

    The count of numbers in @numlist is 8.
    The total of @numlist is 40.
    The mean average of @numlist is 5.
    The list of numbers in @numlist over the mean is 7,9.
    The list of numbers that will probably be duplicates in @numlist over the mean is 7,9,7,9.
    The standard deviation of numbers in @numlist is 2.
    Finished in 0.1s

    I get the same results from the commandline in powershell as I do from the build run in ST2.

    I've searched for "duplicate results from subroutine" and "duplicate results from function" and didn't see anything.

    All the best,

    -ZR

    #!/C:\Perl64\bin\perl.exe use strict; use warnings; my @numlist = qw(2 4 4 4 5 5 7 9); my $numlist_avg = avg(@numlist); my @cands; my @abvlist = abv(@numlist); my $sigma = std_dev(@numlist); my @squares; my $len = $#numlist + 1; print "The count of numbers in \@numlist is ", $#numlist + 1, "\.\n"; print "The total of \@numlist is ", total(@numlist), "\.\n"; print "The mean average of \@numlist is ", avg(@numlist), "\.\n"; print "The list of numbers in \@numlist over the mean is ", join(',', + @abvlist), "\.\n"; print "The list of numbers that will probably be duplicates in \@numli +st over the mean is ", join(',', abv(@numlist)), "\.\n"; print "The standard deviation of numbers in \@numlist is ", $sigma, "\ +.\n"; sub total { my $endresult = 0; foreach my $x (@numlist) { $endresult += $x; } return $endresult; } sub avg { my $len1 = $#numlist + 1; return total(@numlist) / $len1; } sub abv { foreach my $cand (@numlist) { if ($cand > $numlist_avg) { push(@cands, $cand); } } return @cands; } sub std_dev { my $len2 = $#numlist + 1; foreach my $num (@numlist) { my $step1 = $num - $numlist_avg; my $step2 = $step1 * $step1; push(@squares, $step2); } my $start2 = 0; foreach my $num2 (@squares) { $start2 += $num2; } return sqrt($start2 / $len2); }

How to create a non uniform multi-dimention array with push?
1 direct reply — Read more / Contribute
by shaialo
on May 23, 2013 at 16:05

    I'm trying to create a non uniform multi-dimention array with push.

    The purpose is to create an array holding a histogram of error lines in a component log file.

    For example:

    Say I have a LOGFILE that I need to filer only the error messages out of it, but divide the times into groups, like: if the LOGFILE contain entries of 2 hours from 00:00:00 till 02:00:00, I need to check in every 10 min in that time period, how many error messages appeared and from which type.

    Therefore, for example I have 4 error types in an array, like "File not found", "File is empty", "Wrong permissions", "object is not a file", respectively as 0..4 .

    I'm trying to create the following structure:

    +------------------+---------------+------------------+ | Error Type index | Time interval | Number of errors | +------------------+---------------+------------------+ | 0 | 00:00:00 | 1 | | | 00:10:00 | 5 | | | .... | .... | | | 01:50:00 | 7 | +------------------+---------------+------------------+ | 1 | 00:00:00 | 21 | | | 00:10:00 | 34 | | | .... | .... | | | 01:50:00 | 11 | +------------------+---------------+------------------+ | | .... | .... | +------------------+---------------+------------------+ | 3 | 00:00:00 | 0 | | | 00:10:00 | 0 | | | .... | .... | | | 01:50:00 | 17 | +------------------+---------------+------------------+

    In this way, the 1 column size is 4, the 2nd and 3rd columns sizes are 12.

    I'm filling the data when reading the LOGFILE line by line and consider that this array doesn't exist and I need to create it using push.

    Is there any effective way of doing this in the right way?

    Thanks

Passing multiple arguments to CallBack routine.
1 direct reply — Read more / Contribute
by mr_p
on May 23, 2013 at 13:15

    Hi Guys,

    I wanted to add $depth into the @urls with separated by pipe '|' symbol, Is it possible to pass multiple arguments to the callback routine?

    So, I would like to pass $depth as argument to depth, if its possible.

    Thanks.

    Here is an Example code.

    Mojo::IOLoop->recurring( 0 => sub { for ($active + 1 .. $max_conn) { # Dequeue or halt if there are no active crawlers anymore return ($active or Mojo::IOLoop->stop or $totalPagesVisite +d > $maxPages) unless my $url = shift @urls; # Fetch non-blocking just by adding # a callback and marking as active ++$active; say "getting link: $url"; ($depth, $myLink) = split ('\|', $url); $ua->get($myLink => \&get_callback); } } ); sub get_callback { my (undef, $tx) = @_; ...... push(@urls, "$depth+1|$newLink"); ...... }

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.