Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

The Monastery Gates

( #131=superdoc: print w/replies, xml ) Need Help??

If you're new here please read PerlMonks FAQ
and Create a new user.

poll ideas quest 2021
Starts at: Jan 01, 2021 at 00:00
Ends at: Dec 31, 2021 at 23:59
Current Status: Active
1 reply by pollsters
    First, read How do I create a Poll?. Then suggest your poll here. Complete ideas are more likely to be used.

    Note that links may be used in choices but not in the title.

Perl News
Quadmath builds of perl for MS Windows
on Feb 20, 2021 at 23:14
2 replies by syphilis
    Not sure that anyone here is particularly interested in this, but I'll mention it anyway that, as of the release (on 20.01.2021) of perl-5.33.6, it's possible to build perl on MS Windows with an NV type of __float128.
    And it has become a little easier in 5.33.7 with a change to GNUmakefile that removed the need for a somewhat cumbersome configuration argument.
    With the release of perl-5.22.0, the NV type of long double was enabled on Windows, and now we finally get the additional option of having the __float128 NV type.
    All of this does, of course, rely on using mingw-w64 ports of gcc to build your Windows perl.

    I think that many of us, accustomed to simply using Strawberry Perl, don't realize just how easy it is to build perl from source on Windows.
    Strawberry Perl, itself, does provide us with the toolchain that's capable of building any recent version of perl (including blead releases) from source.
    The latest blead source can be obtained with:
    $ git clone blead_clone
    or the perl-5.33.7 development tarball is available from:
    Then, I place my C:\_64\strawberry-5.32.0\c\bin folder at the beginning of my PATH, and I have all that I need to build perl.
    Simply cd to the perl source's win32 folder and run:
    gmake INST_TOP=C:\bleadstraw CCHOME=C:\_64\strawberry-5.32.0\c CCTYPE= +GCC I_QUADMATH=define USE_QUADMATH=define test
    Then, to install perl into the location specified by INST_TOP, just run:
    gmake INST_TOP=C:\bleadstraw CCHOME=C:\_64\strawberry-5.32.0\c CCTYPE= +GCC I_QUADMATH=define USE_QUADMATH=define install
    And that's it - in C:\bleadstraw I now have a Windows perl that has __float128 as its NV.

    You may want to alter INST_TOP, and you probably need to alter CCHOME which should specify the full path to gcc's bin directory.
    NOTE that CCHOME does not include "\bin". (Failure to get CCHOME right will cause some test failures, but will not affect the perl that has been built.)

    If you want to do a 'long double' build instead, you would just remove the 2 gmake arguments that include the string "QUADMATH", and insert the USE_LONG_DOUBLE=define argument.
    If you don't request either a 'long double' or a 'quadmath' build, then the nvtype will be 'double'.

    If you're using a 32-bit compiler, you'll also need to insert the argument WIN64=undef, and you might also want to add the argument USE_64_BIT_INT=define if you want 64-bit integers and pointers.
    With 64-bit compilers, perl's integer and pointer will inevitably be 64-bit.

    I think that covers the most commonly exercised options ... but you'll find additional options laid out in the GNUmakefile.

    I don't know if it's a general issue, but (on 64-bit builds only) there's usually a couple of test scripts in cpan/IO-Compress/t that hang for me .
    Update: This issue is a long-standing one for me, and is not limited to just the "quadmath" builds.
    It's generally (but not always) the same test scripts that hang, and it has been happening for a few years. In perl-5.33.7, I'm finding that the problem has moved to a different couple of files.
    The Strawberry project have never, to my knowledge, complained about such an issue - so I'm hoping that it's just something in my particular environment.
    It would be nice to find out if it is "just me".
    It's quite annoying - I have to kill these hangs using process explorer in order to get the test suite to run to completion. (Killing them with Ctrl-C kills the entire 'gmake test' process.)
    These test scripts have always passed when run outside of the testing harness, and they've also passed even when I've run make test in the cpan/IO-Compress folder.
    There's also the same thing happening in the cpan/IPC-Cmd tests with t/01_IPC-Cmd.t.
    If I can find any evidence that it's also an issue for others then I'll try to get it fixed.

    Oh, one last thing - if you build a 32-bit perl with I_QUADMATH=define USE_QUADMATH=define but without USE_64_BIT_INT=define, then expect some failing tests in Math::BigFloat due to a Math::BigInt::Calc bug.
    This issue has been reported, with a proposed simple fix to

berrybrew version 1.33 released!
on Feb 12, 2021 at 18:10
1 reply by stevieb

    I've released berrybrew version 1.33. This version has significant enhancements, along with some bug fixes and handling of some uncaught exceptions. The changes reflect versions 1.30 to 1.33.

    Major changes include:


    • Allows you to install, switch to, remove and use Strawberry Perls directly
    • Can now spawn a CLI window for any Perl you have installed
    • Allows you to spawn a CLI window for the currently active Perl
    • Provides access to modify several of the core configuration options (debug, file association etc)
    • Allows you to disable all berrybrew Perls and restore to system default


    • Performs an upgrade on any previous berrybrew install
    • Adds any new configuration options, while preserving the values of any previously set existing ones
    • Provides facility to install the most recent version of Strawberry Perl
    • Allows you to have berrybrew manage the .pl file association
    • Allows you to have the UI run at system startup
    • Aborts if trying to install the same version that's already installed


    • You can now leave off the _32/_64 bit prefix on a Perl name, and we'll default to _64
    • All execution paths return a proper exit code
    • Added new berrybrew hidden command, lists all, well, hidden commands

    For all other changes, please refer to the Changes file.



SQL Placeholders - clarification
5 direct replies — Read more / Contribute
by Bod
on Feb 28, 2021 at 06:57

    Over on Re^6: Splitting the records into multiple worksheets, hippo pointed out the error of my ways and I have been going through some code that's being produced to implement placeholders. Can I please check that I am now on the right lines and doing things better...

    I had this line of code...

    $dbh->do("INSERT INTO Web_Page SET template = '$request', test = '$tes +t', source = '$data{'source'}', Visitor_idVisitor = $cookie{'_ls_visi +t'}") unless $$vars{'testpage'};
    All the variables are generated within the code except $data{'source'} which is derived from the HTTP query string and therefore potentially unsafe.

    I have replaced that line of code with this...

    unless ($vars->{'testpage'}) { my $query = $dbh->prepare("INSERT INTO Web_Page SET template = '$r +equest', test = '$test', source = ?, Visitor_idVisitor = $cookie{'_ls +_visit'}"); $query->execute($data{'source'}); }
    Is that the best approach or should I be using placeholders for every variable, even those I have declared and therefore know are safe?

Updated: Looking for something like DBD::HTML::Table
6 direct replies — Read more / Contribute
by talexb
on Feb 26, 2021 at 16:07

    I'm looking into a couple of different solutions for a problem, and one solution involves using an imaginary module called DBD::HTML::Table to load up a web page containing a big table. It would be smart enough to look at the top row for the column names, and the first column for each row's index value.

    I've just had a stroll through, and I didn't see anything like that. Is it cunningly hidden, or does it not exist at all?

    Update: Thanks for all of your thoughtful replies. I had a look at the HTML that was being generated by our internal CGI, and found that it was really, really easy to just write a very simple parser. Each opening and closing tr was on a line by itself, and t[dh] elements were either on a line by themselves (open, element, close) or they were in an easily grabbable format (open, elements, and close each on their own separate lines).

    I understand that my initial question was vague -- I was still working out what my solution might look like. I now have a much better idea of what the process is going to look like. Ideally, it's going to be something that will be as automated as possible. Sorry if this all sounds vague, it's work related, so I need to be a little circumspect about how I describe the problem. :)

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

Passing Variables
5 direct replies — Read more / Contribute
by catfish1116
on Feb 25, 2021 at 16:01

    I am running v5.12 and am trying to pass multiple args to a subroutine. Is this possible in v5.12? Here is my code

    ################################################### # # # 2/24/21 # # Program takes finds the average in an # # array and lists out the numbers that were # # above the average found. # # # ################################################### my @numbers = qw(4 12 18 21 35); my $average = &find_average(@numbers); print "The average found for this list is: $average \n " ; my @high_avg = &above_average($average, @numbers); print "The numbers that were found above average are: @high_avg \n" +; sub find_average { my ($sum, $number_count) ; foreach (@_) { $sum += $_; $number_count += 1; } my $avg = $sum / $number_count ; } sub above_average { my $average_num; my @final_list; foreach $_ (@_) { if ($_ > $average_num) { push @final_list, $_ } } }

    Here is the error message I am getting

    Use of uninitialized value $average_num in numeric gt (>) at ./Chapter line 36.

    TIA The Catfish

You won't believe what this regular expression does!
4 direct replies — Read more / Contribute
by salva
on Feb 25, 2021 at 05:44
ODBC problem
7 direct replies — Read more / Contribute
by Anonymous Monk
on Feb 24, 2021 at 08:47
    Hi, I have to access an old Sage MAS 90 database, I can connect fine with an ODBC query tool using the connection string "Driver={MAS 90 4.0 ODBC Driver};Directory=S:\v440\MAS90" But when I try with Perl I get:
    use strict; use warnings; use DBI; my $dbuser = "user"; my $dbpassword = "password"; # SOTAMAS90 my $CONNECT = 'Driver={MAS 90 4.0 ODBC Driver};Directory=S:\v440\MAS90 +'; my $dbh = DBI->connect("dbi:ODBC:$CONNECT", "$dbuser", "$dbpassword") or die "Cannot connect to $CONNECT: $DBI::errstr\n"; $dbh->disconnect
    It fails with:
    C:\> DBI connect('Driver={MAS 90 4.0 ODBC Driver}','user',...) failed: [Mic +rosoft][ODBC Driver Manager] Data source name not found and no defaul +t driver specified (SQL-IM002) at C:\ line 11. Cannot connect to Driver={MAS 90 4.0 ODBC Driver}: [Microsoft][ODBC Dr +iver Manager] Data source name not found and no default driver specif +ied (SQL-IM002)
    The driver is a 32bit on (if that's relevant) I've also tried using its user DSN name SOTAMAS90 instead but that fails as well. I've never used ODBC before and am not used to working on Windows so any help to helping me connect would be great!
Image rotation with GD: counter or clockwise?
3 direct replies — Read more / Contribute
by Discipulus
on Feb 23, 2021 at 08:29
    Hello folks!

    I'm experimenting with images again but I'm stucked at image rotation using GD. Documentation says:

    > $image->copyRotated($sourceImage,$dstX,$dstY,$srcX,$srcY,$width,$height,$angle) Like copyResized() but the $angle argument specifies an arbitrary amount to rotate the image clockwise (in degrees). In addition, $dstX and $dstY species the center of the destination image, and not the top left corner.

    The following code seems to rotate counter clockwise instead (pass to the following program a jpg image and optionally a degrees value):

    use strict; use warnings; use GD; print "GD version : $GD::VERSION\n"; print "libgd version: ",GD::VERSION_STRING,"\n"; my $original_jpg = $ARGV[0]; my $angle = $ARGV[1] ? $ARGV[1] : 90; my $gd = GD::Image->new( $original_jpg ); my $gdrot = new GD::Image($gd->width, $gd->height ); $gdrot->copyRotated( $gd, # source $gd->width/2, # X center of the destinat +ion image $gd->height/2, # Y center of the destinat +ion image 0, # X specify the upper left + corner of a rectangle in the source image 0, # Y specify the upper left + corner of a rectangle in the source image $gd->width, # final width $gd->height, # final height $angle # rotation angle clockwise + in degrees ); open my $fh,'>', "rotated_".$angle."_".$original_jpg or die $!; binmode $fh; print $fh $gdrot->jpeg;

    Did you see the same result as me? I see the resulting image rotated 90 counter clockwise (I'd say counter documentwise ;). In early tests I got a warning about older version of gdlib (like: libgd 2.0.33 or higher required for copyRotated ) and I upgraded my using cpan client and everything went fine.

    I currently have: GD version   : 2.66 libgd version: 2.2.4

    Any insight appreciated.


    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Assign valuse of array within array to variables
3 direct replies — Read more / Contribute
by g_speran
on Feb 22, 2021 at 20:29

    Good Evening Perl Monks, How can one assign the contents of an array within a multi-dimensional array to a set of variables passed to a subroutine?

    use warnings; use Data::Dumper; my @arr; $arr[0][4] = (["S","M","R","B"]); print Dumper @arr; my ($VAR1,$VAR2,$VAR3,$VAR4) = @{$arr[0][4]}; print "Var1: $VAR1\tVar2: $VAR2\tVar3: $VAR3\tVar4: $VAR4\n"; Testing($arr[0][4]); sub Testing () { my ($VAR5,$VAR6,$VAR7,$VAR8) = @{$_}; print "Var5: $VAR5\tVar6:$VAR6\tVar7: $VAR7\tVar8: $VAR8\n"; }
    OUTPUT ================= main::Testing() called too early to check prototype at C:\temp\arr_ref line 11. $VAR1 = [ undef, undef, undef, undef, [ 'S', 'M', 'R', 'B' ] ]; Var1: S Var2: M Var3: R Var4: B Use of uninitialized value $_ in array dereference at C:\temp\arr_refe line 14. Use of uninitialized value $VAR5 in concatenation (.) or string at C:\ +temp\ line 15. Use of uninitialized value $VAR6 in concatenation (.) or string at C:\ +temp\ line 15. Use of uninitialized value $VAR7 in concatenation (.) or string at C:\ +temp\ line 15. Use of uninitialized value $VAR8 in concatenation (.) or string at C:\ +temp\ line 15. Var5: Var6: Var7: Var8:
    Expecting output ============== Var1: S Var2: M Var3: R Var4: B Var5: S Var6: M Var7: R Var8: B
Semaphore puzzle
6 direct replies — Read more / Contribute
by jerryhone
on Feb 22, 2021 at 13:12
    I'm seeking wisdom and potentially flashes of inspiration... I have a process that receives files via NDM from an external partner in pairs - a data file and a status file. The files may arrive in any order, and could be anything from minutes apart to fractions of a second. I'm trying to create a process that populates the file content into an Oracle database via a Perl script triggered after each file arrives. Although the files can arrive in pseudo parallel, I need to process them in sequence, so I'm trying to semaphore lock them (IPC::Semaphore). If they arrive separated by, say, 1 second the lock works nicely, but if they arrive a tenth of a second apart, both Perl processes say that they're the first one and create and initialize the semaphore.
    $sem = IPC::Semaphore->new( 4321, 1, S_IRUSR | S_IWUSR ); if ( $sem ) { # Semaphore already exists so just open it print "Semaphore already exists - just open it\n"; $sem = IPC::Semaphore->new( 4321, 1, S_IRUSR | S_IWUSR ); } else { # The semaphore didn't already exit so create it print "Create semaphore \n"; $sem = IPC::Semaphore->new( 4321, 1, IPC_CREAT | S_IRUSR | S_IWUSR + ); print "Semaphore created\n"; $sem->setval(0,1); print "Semaphore initialised\n"; } print "Locking other threads\n"; $sem->op(0, -1, SEM_UNDO);
    Depending on exact timing, I see that it's possible for the first process to create the semaphore and attempt to lock the other process, but the other one running a fraction behind has not detected the creation so it does its own and sets the semaphore to 1, so revoking it's partner's lock! I can't see a fool proof way of getting around this, so any divine inspiration gratefully received.
Banal Configuration Languages
1 direct reply — Read more / Contribute
by jdporter
on Feb 26, 2021 at 14:10

    This is so great, I have to share it here. This guy nails it on the head. (Spring, we're looking at you.)

    I suspect a lot of abuse of config files comes from moving logic out of source code for bad reasons. There are good reasons for not hard-coding, say, ports and service endpoints in your source code, because it makes it easier to run the code in different environments. However, there are also bad reasons for taking things out of code. A couple that I have encountered:

    Pride in creating a "generic" system that can be configured to do all kinds of new things "without touching the code." Reality check: only one or two programmers understand how to modify the config file, and changes have to go through the same life cycle as a code change, so you haven't gained anything. You've only made it harder to onboard new programmers to the project.

    Hope that if certain logic is encoded in config files, then it can never get complicated. Reality check: product requirements do not magically become simpler because of your implementation decisions. The config file will become as expressive as necessary to fulfill the requirements, and the code to translate the config file into runtime behavior will become much more complex than if you had coded the logic directly.

    Hope that you can get non-programmers to code review your business logic. Reality check: the DSL you embedded in your config file isn't as "human readable" as you think it is. Also, they're not going to sign up for a Github account and learn how to review a PR so they can do your job for you.

    Marketing your product as a "no code" solution. Reality check: none for you; this is great! Your customers, on the other hand, are going to find out that "no code" means "coding in something that was never meant to be a programming language."


RFC: Devel::Trace 0.13
No replies — Read more | Post response
by shmem
on Feb 25, 2021 at 17:41

    Years ago I posted at Devel::Trace - TODOs done, trace per package some enhancements for Devel::Trace by Dominus. A few days ago I stumbled over the fact that Dominus added me as maintainer on PAUSE. Oh my, oh my... what to do? what to do?

    So I decided to make a new release. Features - you can:

    • make it behave just like 0.12 with argument "s" to import: perl -d:Trace=s scriptfile
    • limit trace to namespaces: perl -d:Trace=Foo::Bar,Baz,Quux scriptfile
      You have to add "main" also to trace scriptfile
    • limit trace to subroutines: perl -d:Trace=Foo=sub1:someothersub scriptfile
    • limit trace by line numbers and number ranges: perl -d:Trace=20-42:123..321,Foo=17-21
      This limits trace in "main" to lines 20 through 42 and 123 through 321 (you may use "-" and ".." for ranges) and to lines 17 through 21 in package Foo
    • trace the codepath stemming from limited traced lines: perl -d:Trace=20..42+:123-321
      Lines 123 - 321 are traced in main but not calls, whereas the entire codepath in lines 20 - 42 is followed
    • exclude packages from trace in the open codepath: perl -d:Trace=42-127+:somesub,Net::LDAP=0
      Codepath in lines 42 - 127 is followed as well as calls to "somesub" in main, excluding code in Net::LDAP
    • provide other filehandles to trace to (which comprises tracing to a variable) by assigning an open filehandle to Devel::Trace::FH
    • provide an alternative format for trace output by assinging a sprintf format to Devel::Trace::FORMAT
    • use a formatting function by assigning a function reference to Devel::Trace::FORMAT
      An ugly example is shown below

    Now it is possible to narrow down tracing to just the interesting parts of a program without touching the source. It is not fully tested and possibly has bugs. I'd be happy if you'd like to play with it and comment. Bug reports, critics, suggestions for improvement, code review etc are most welcome. Have fun!

    - changed the "simple" handling
    - removed useless code from

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
PerlMonks Discussions
Necroposting Considered Beneficial
4 direct replies — Read more / Contribute
by eyepopslikeamosquito
on Feb 24, 2021 at 23:43
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 drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2021-03-01 05:28 GMT
Find Nodes?
    Voting Booth?

    No recent polls found