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.

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.

Post a new question!

User Questions
Perl Not returning SQL query result
3 direct replies — Read more / Contribute
by santoo
on May 11, 2021 at 08:07

    Hi All, I am trying to run some sql query on perl. I am not getting any error, at the same time also the result is always emty. But when I try same query on sql client I am getting data. Any idea to troubleshoot please

    my $conn = $OracleSqlData::connection{$OracleSqlData::server}; $sth =$conn->prepare("select * from users"); $sth->fetchrow_array()


    Actually above code is within the method and that method is being called in multiple places and it will return result-set... My problem is for some method calls its returning value but for other calls its giving empty result set... its not consistent across all calls also in log I check for any error randomly I get bellow error also ORA-03113: end-of-file on communication channel Session ID: 1168 Serial number: 37417 (DBD ERROR: OCIStmtExecute)
Net::FTP and Net::FTPSSL Lost data when transferring a large file
2 direct replies — Read more / Contribute
by duy.nguyen
on May 11, 2021 at 01:05
    Hi Monks,

    I use library Net::FTP to transfer a large file (about 7GB) to a remote server.

    But I always received a file that has a size about 5GB.

    If the file is 4GB, it is put to the remote server successfully.

    Is there any limit size for the file transferred by put method?

    I have tried using Net::FTPSSL and I got the same result.


[OT] github: testing PRs
2 direct replies — Read more / Contribute
by syphilis
on May 11, 2021 at 00:56

    I assume this must be a simple procedure.
    I want to obtain the same perl source code that CI ran in its automated testing of
    What is the simplest way for me to obtain that source ?

    Update: I probably should mention that I do already have a fully functional git utility.

Need advice on AD authentication confirguration in Dancer2 app.
1 direct reply — Read more / Contribute
by chandantul
on May 10, 2021 at 23:39

    Hello Smart Monks, I will need your help in AD authentication configuration in app.psgi file. I was able to conifugure simple authentication but not able to configure AD authentication. Please check my below code that is not not leeting me start the app.psgi.

    # use this block if you don't need middleware, and only have a single +target Dancer app to run here use webapp; use Plack::Builder; use Authen::Simple::ActiveDirectory; my $ad = Authen::Simple::ActiveDirectory->new( host => 'ldaps//', principal => '' ); builder { enable "Auth::Basic", authenticator => $ad; webapp->to_app; }; my($username, $password, $env) = @_; if ( $ad->authenticate( $username, $password ) ) { # successfull authentication } else { die "Wrong ID and Password\n" }

    Please check below error and help me to identify the issue if possible

    :Simple::ActiveDirectory::authenticate was an 'undef', which is not on +e of the allowed types: scalar at C:/Strawberry/perl/site/lib/Authen/Simple/ line 42, <DAT +A> line 755. Authen::Simple::Adapter::authenticate(undef, undef, undef) cal +led at C:\Users\Documents\Perl\webapp\bin\app.psgi line 26 require C:\Users\Documents\Perl\webapp\bin\app.psgi called at +(eval 6) line 3 eval 'package Plack::Sandbox::C_3a_5cUsers_5c503004671_5cDocum +ents_5cPerl_5cSynchrony_2dPerl_5cwebapp_5cbin_5capp_2epsgi; { my $app = do $_file; if ( !$app && ( my $error = $@ || $! )) { die $error; } $app; } ' called at C:/Strawberry/perl/site/lib/Plack/ line 120 Plack::Util::_load_sandbox("C:\\Users\\Documents\\Perl\\webapp +\\bin\\a"...) called at C:/Strawberry/perl/site/lib/Plack/ lin +e 136 Plack::Util::load_psgi("app.psgi") called at C:/Strawberry/per +l/site/lib/Plack/ line 181 Plack::Runner::__ANON__() called at C:/Strawberry/perl/site/li +b/Plack/ line 24 Plack::Runner::__ANON__() called at C:/Strawberry/perl/site/li +b/Plack/ line 24 Plack::Runner::__ANON__() called at C:/Strawberry/perl/site/li +b/Plack/ line 24 Plack::Runner::__ANON__() called at C:/Strawberry/perl/site/li +b/Plack/ line 24 Plack::Runner::__ANON__() called at C:/Strawberry/perl/site/li +b/Plack/ line 55 Plack::Loader::preload_app(Plack::Loader=HASH(0x65aa50), CODE( +0x2ca34c0)) called at C:/Strawberry/perl/site/lib/Plack/ lin +e 276 Plack::Runner::run(Plack::Runner=HASH(0x11aa248)) called at C: +\Strawberry\perl\site\bin/plackup line 7
I can't subtract one DateTime object from another to get a DateTime::Duration in days
2 direct replies — Read more / Contribute
by Cody Fendant
on May 10, 2021 at 18:17

    Oh the shame: my date objects weren't actually differing by more than one day because I'm an idiot and assumed that my inputs were what I thought they were! Thanks commenters for forcing me to go back and look at exactly what was in the objects. I leave this here as a memorial, or it can be reaped.

    This is a bug in an application I'm working on.

    The code creates two DateTime objects and subtracts one from the other to get a DateTime::Duration object.

    However the DateTime::Duration object can't return a difference in number of days, which is what I need.

    This is actually expected behaviour:

    my $dur = DateTime::Duration->new( years => 1, months => 15 ); $dur->in_units('years'); # 2 $dur->in_units('months'); # 27 $dur->in_units( 'years', 'months' ); # (2, 3) $dur->in_units( 'weeks', 'days' ); # (0, 0) !
    The last example demonstrates that there will not be any conversion between units which don't have a fixed conversion rate.

    I guess my question is, how do I get the difference in days between two DateTime objects?

    Updated: The current code just does

    my $diff = $dt1 - $dt2;
    Where both DateTime objects are specific fixed dates, like one is January 1, 2021 at 10 AM and the other is today at 11 AM. Surely there's a 'fixed conversion rate' in days between those? Note: They were essentially the same day!

    I can understand that if I create a duration object with years => 1, months => 15 that's not something where we can be sure of the number of days, but that's not what's happening in my code.

Combinations with variable length
4 direct replies — Read more / Contribute
by TryingTheBest
on May 10, 2021 at 16:54

    Hi everyone.

    I am working with a combination script that is giving me problems.

    This is as below:

    I have two static numbers: 1 and 2.

    And also I have a non-static number that represent the size of the combinations.

    Example: 3 (combinations of 3 characters).

    I need to perform ALL combinations using the static number, but considering the non-static number.

    In the example with "3" as non-static number, this will be:

    1 1 1
    1 1 2
    1 2 1
    1 2 2
    2 1 1
    2 1 2
    2 2 1
    2 2 2

    ( I think I don't forget any combination :P )

    Someone can help me with the code, please? I tried using use Algorithm::Combinatorics qw( combinations ); but I could not solve it.

    Thanks all!

Perl5.26 installing Tk module manually
3 direct replies — Read more / Contribute
by vinoth.ree
on May 10, 2021 at 04:04

    I have installed perl 5.26 on windows10 and trying to install Tk module manually, since my application uses Tk module, but getting below error.

    C:\Users\VinothG\Desktop\Tk-804.036>perl Makefile.PL Cannot find 'C:\TEMP\ActiveState--------please-run-the-install-script- +-------\lib/CORE/perl.h' have you installed C:\Perl64\bin\perl.exe? Compilation failed in require at Makefile.PL line 37. BEGIN failed--compilation aborted at Makefile.PL line 39.

    Could someone help me to fix this error, Am I doing something wrong here?

    All is well. I learn by answering your questions...
Counting characters within regexp
5 direct replies — Read more / Contribute
by Bod
on May 08, 2021 at 18:15

    Good evening fellow Monks

    I've just been writing a bit of code to partially hide an email address such that the owner of the address would recognise it but anyone else would find it difficult, at least to work out. I tried a simple substitution but hit a problem. How can I determine how many characters there are and replace them with that same number of full stops or asterisks or whatever?

    I have come up with a three line solution but it seems like the sort of problem that should be able to be done with a regexp substitution

    use strict; use warnings; my @email = ( '', '', '', ); foreach my $em(@email) { print "$em - "; my ($name, $comp) = split /@/, $em; $em =~ /^(\w[\w|\.]).*@(\w\w).*\.(\w+)$/; $em = $1 . '.' x (length($name) - 2) . "\@$2" . '.' x (length($com +p) - length($3) - 2) . $3; print "$em\n"; }
    This produces this result:
    C:\Users\joolz\Perl>perl - - -
    This is one of those problems that seems relatively trivial until you actually come to do it! It also suffers as a difficult one to search for as Google wants to tell me how to match a range of lengths {x,y} or count the number times one string occurs in another.

    Is there a nice, simple, succinct way to do this?

    I guess the nicest solution would change the number of characters properly displayed as a function of the overall length!

Attempting to use $_ in "sub" inside "map"
1 direct reply — Read more / Contribute
by NetWallah
on May 08, 2021 at 00:36
    I'm trying to automate building a dispatch table - or at least, to minimize keystrokes.

    Please suggest ways to achieve the desired result:

    use strict; use warnings; my %dispatch = ( normal => sub{"$_[0] Normal dispatch"}, map( {$_ => sub{"$_[0] Sub returns $_"} } qw| Uno Dos tres|), ); print $dispatch{"normal"}->(0),"\n"; # 0 Normal dispatch (as expected) + print $dispatch{"Uno"}->(1),"\n"; # WANT: "1 Sub returns Uno" print $dispatch{"Dos"}->(2),"\n"; # WANT: "2 Sub returns Dos"
    This currently prints:
    0 Normal dispatch Use of uninitialized value $_ in concatenation (.) or string at .\test line 5. 1 Sub returns Use of uninitialized value $_ in concatenation (.) or string at .\test line 5. 2 Sub returns
    Also - is there a NAME for what I am attempting ? "Early evaluation of $_" ?

                    "Avoid strange women and temporary variables."

PDF::API2 external objects
1 direct reply — Read more / Contribute
by dd-b
on May 07, 2021 at 23:40

    It appears that external objects (specifically, image files placed on the various pages) are not actually read until the pdf->save() call at the end. This may be problematic, in that I'm playing with a script that may generate a rather LARGE PDF containing more than 10,000 images.

    I'm wondering if anything like the $pdf->finishobjects(@obj) call might help; but the documentation doesn't really tell me very much about it!

    It does look like this module lets you insert pages in any order, and write on pages in any order, so maybe in fact nothing is really done until the end. It might not matter; I'm not actually that worried about the temp directory capacity on modern systems, and a BOTE calculation suggests the sum of the image files, at the size I'm currently proto-typing at, is a very few gigabytes. (Temp files are written out as a necessary step in re-scaling the files to sizes suitable to their appearance in the PDF; yes, using GD you can import an image file, re-scale it in memory, and put that directly into PDF::API2, without going through any temporary files, and it even works...but I was kind of shocked to discover that that was TWO ORDERS OF MAGNITUDE slower than using Image::Imlib2 to read, rescale, and write the image to a temp file and then reading it using the PDF::API2 method.)

    (As a side note--I'm kind of shocked how far I've gotten with this since starting to commit code this morning. PDF::API2, despite some documentation issues, which are frequently commented on, seems to be fairly easy to get somewhere with.)

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":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible editor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
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 chilling in the Monastery: (5)
As of 2021-05-11 17:16 GMT
Find Nodes?
    Voting Booth?
    Perl 7 will be out ...

    Results (120 votes). Check out past polls.