Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

The Monastery Gates

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

Donations gladly accepted

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

New Questions
option control in script
2 direct replies — Read more / Contribute
by dideod.yang
on Jul 22, 2018 at 00:52
    Hi monks. I wonder that Can script control option by itself?? For example, when I want to use @F(automatic split line by line) , I operate option -ane "perl -ane". also there are many options such as -n -e ... Recently I write some script to open text file and really useful on @F. but I always forgot option -ane :(.. I know I am not man.. So I need your help. When I operate script "perl" then script is operated on "-ane" to use @F. Thank you :)
Perl/Tk Windows fonts for Linux?
1 direct reply — Read more / Contribute
by tlhackque
on Jul 21, 2018 at 16:08

    I think I have all the pieces, but not how to put them together:

    I have a Perl/Tk application that runs on Windows & Linux (Fedora, if it matters). Originally written on Windows.

    The Linux default fonts are causing some issues - they make a number of widgets larger, and aren't as readable for some. In any case, the goal is a common look and screen size.

    The application users (X display servers) are mostly Windows (VxXsrv), some Linux.

    So, I'd like to have the application request (and the clients use) the Windows fonts for the Tk widgets.

    What I (think I) know:

    • Perl Tk has "Tk Default, Text, Fixed, Monospace, Heading, Caption, Small Caption, Icon and Tooltip fonts.
    • On Windows, the "System" font is Arial, which is used for the widgets without custom fonts
    • The MS TT fonts (including Arial) can be obtained for use using the process at
    • There ought to be some mapping in .Xdefaults to connect the dots

    That's where I get lost.

    • A - having followed the process (built and installed the RPM), xlsfonts doesn't report Arial on Linux clients. It does report a bunch of other -microsoft fonts. xlsfonts | grep ^-microsoft | sort | head starts with -microsoft-comic
    • B - I assume I need to do something to get VcXsrv to recognize the fonts too. I have no clue what.
    • C - Even if it did - what do I put in .Xdefaults (or elsewhere) to have TK adopt the MS Arial (and Courier) fonts?

    I don't want to declare a custom font for every widget - I want the defaults for this application to switch to these as the "system" fonts"

    I don't know why I find all this stuff so confusing - OS internals are simple :-)

    Thanks in advance

XML::Twig - '#CDATA' attribute in hashref disappears after first call to XML::Twig::Elt->new()
2 direct replies — Read more / Contribute
by ateague
on Jul 20, 2018 at 17:56

    Good afternoon!

    I am experiencing a rather unexpected issue creating new elements with XML::Twig's XML::Twig::Elt->new() method where the '#CDATA' key in my attribute hashref gets undefined after passing it to new().


    my $attributes = $sibling_element->atts(); $attributes->{'#CDATA'} = 1; # '#CDATA' attribute is defined here my $elt1 = XML::Twig::Elt->new('present', $attributes, 'This is in CDA +TA'); # '#CDATA' attribute is undefined here my $elt2 = XML::Twig::Elt->new('missing', $attributes, 'This is not in + CDATA');

    Is this supposed to happen? I did not see anything mentioning this in the CPAN docs...

    Thank you for your time.

    Perl info:

    perl -v This is perl 5, version 26, subversion 0 (v5.26.0) built for MSWin32-x +64-multi-thread
    XML::Twig info: 3.52

PL_strtab/SHAREKEYS and copy-on-write leak
4 direct replies — Read more / Contribute
by sezal
on Jul 20, 2018 at 17:11

    Perl internally uses dedicated hash PL_strtab as shared storage for hash's keys, but in fork environment like apache/mod_perl this creates a big issue. Best practice says to preload modules in parent process, but nobody says it's eventually allocates memory for PL_strtab and these pages of memory tend to be implicitly modified in child processes. There are seems to be 2 major reasons of modification:

    Reason 1: reallocation (hsplit()) may happen when PL_strtab growths in child process.

    Reason 2: REFCNT every time new reference created.

    Example below shows 16MB copy-on-write leak in attempt to use hash. Attempts to recompile perl with -DNODEFAULT_SHAREKEYS fails ( I was able to get access to PL_strtab via XS module and ideally I'm looking for a way to downgrade all hashes created in parent to keep hash keys within a hash (HE object) rather than PL_strtab, i.e. turn off SHAREKEYS flag. This should allow to shrink PL_strtab to minimum possible size. Ideally it should have 0 keys in parent. Please let me know you think it's theoretically possible via XS.

    #!/usr/bin/env perl use strict; use warnings; use Linux::Smaps; $SIG{CHLD} = sub { waitpid(-1, 1) }; # comment this block { my %h; # pre-growth PL_strtab hash, kind of: keys %$PL_strtab = 2_000_000 +; foreach my $x (1 .. 2_000_000) { $h{$x} = undef; } } my $pid = fork // die "Cannot fork: $!"; unless ($pid) { # child my $s = Linux::Smaps->new($$)->all; my $before = $s->shared_clean + $s->shared_dirty; { my %h; foreach my $x (1 .. 2_000_000) { $h{$x} = undef; } } my $s2 = Linux::Smaps->new($$)->all; my $after = $s2->shared_clean + $s2->shared_dirty; warn 'COPY-ON-WRITE: ' . ($before - $after) . ' KB'; exit 0; } sleep 1000; print "DONE\n";
Efficient enumeration of pandigital fractions
5 direct replies — Read more / Contribute
by kikuchiyo
on Jul 20, 2018 at 16:51

    The fraction 6952 / 1738 has a curious property: each non-zero decimal digit appears exactly once in the expression, and the result of the divison happens to be the missing digit, 4.

    Are there, by any chance, other fractions that share this property? It is fairly simple to devise a semi-brute force solution to answer this question:

    restate the problem as abcd = efgh * i, generate all 5-element variations (k-permutations) of the set of digits 1..9, perform the multiplication and check that the result consists only of digits not in the sequence.

    Here is a somewhat optimized implementation:

    For base 10 this runs quickly enough to find that there is one additional solution. But for the obvious and straightforward generalization to higher bases this brute force solution is not going to cut it.

    Tinkering with the innards of the loop or using a different permutation engine might give us a speedup factor of two, while rewriting the whole thing in C might give us two orders of magnitudes. But we'd be still generating all permutations, and the number of those grows relentlessly as the base increases ((b - 1)! / (b/2 - 1)!):

    6 60
    8 840
    10 15120
    12 332640
    14 8648640
    16 259459200
    18 8821612800
    20 335221286400

    On my machine the program above needed 6 seconds to find all base-14 solutions, more than 3 minutes for base-16, and I dared not run it with higher bases.

    However, the number of actual solutions is much smaller:

    6 	1
    8 	2
    10 	2
    12 	18
    14 	136
    16 	188

    which suggests that there may be better, more efficient approaches that don't have to trudge through a lot of useless permutations to find the solutions. However, so far I haven't been able to find one.

    Any thoughts?

Can you limit the scope of require?
3 direct replies — Read more / Contribute
by taylorK
on Jul 20, 2018 at 14:58

    Hi Monks,

    First post so I apologize if I miss something or if there are small errors in the example I provided, I am just using it to explain my issue. I have run into this situation a few times now and have not been able to track down an answer. Let me be clear that this is for a work application so I cannot simply change the current setup of files etc...

    Background: We use multiple .conf files to house "parsers" for data files. Each of these .conf files has a sub that contains a header map in the form of an array. These .conf files are not packages.

    Question: I would like to write a program that will get that header map from one of these .conf files then get it from a different one as well but only for the purposes of a very simple operation. My current method is to use a require (as seen below) and grab the sub. The problem is when I use require a second time to get the second .conf file it completely overwrites the first require. Can I call this second one and have the scope of it limited to a particular subroutine or variable?


    if (-e "myfilepath/test1.conf") { require "myfilepath/test1.conf" or die("myfilepath/test1.conf - $! +\n"); } else { die("Missing provider config file: myfilepath/test1.conf\n"); } $header_map = &get_config; # grab a file to parse while (defined(my $line = <FILE>)) { my $second_file = &compare(); # split $line into the header if ($first_file{test} =~ /$seconf_file{test}/i) { # etc.... } } sub compare { if (-e "myfilepath/test2.conf") { require "myfilepath/test2.conf" or die("myfilepath/test2.conf +- $!\n"); } else { die("Missing provider config file: myfilepath/test2.conf\n"); } $header_map_2 = &get_config; # grab a file to parse while (defined(my $line = <FILE>)) { # split $line into the header } return "$parsed_line"; }


Constants lists in array slices
4 direct replies — Read more / Contribute
by LanX
on Jul 20, 2018 at 07:40
    The following code is surprising me in two ways:

    use strict; use warnings; use feature 'say'; use constant FL => 17,3,16; use constant FL2 => 22,4,13; my @row= "a".."z"; my @a = (" ") x 26; @a[17,3,16] = @row[22,4,13]; say "@a"; @a = (" ") x 26; @a[FL()] = @row[FL2]; say "@a";

    It seems like constant folding isn't happening at all!!!

    • I get a warning for FL2
      Scalar value @row[FL2] better written as $row[FL2] (ignoring that its a constant _list_)
    • Deparsing the code shows that FL and FL2 are called as functions
      @a[FL()] = @row[FL2()];
    Am I missing something?

    (This is perl 5, version 16,)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Writing IBM Mainframe floating point
3 direct replies — Read more / Contribute
by caden_varn
on Jul 20, 2018 at 06:19
    I need to create a file including single precision floating point fields in the IBM mainframe format (specifically to be read by the SAS s370frb4. informat). I am on an HP-UX 11 box which evidently uses a different floating point - when I use pack's 'f' option the value changes when read in by the SAS program on the other end. Is there an option or module that can do this easily? Any help greatefully received...
Perl dictionary
5 direct replies — Read more / Contribute
by dideod.yang
on Jul 19, 2018 at 20:03
    Hi monks. I am perl & python lover.. recently I made many scripy using perl.. So I want to know many functions as much as possible. Cpan give me many information about modules.. but function is not.. Do you monks have nice website? or manual? about perl function??
site_perl files
3 direct replies — Read more / Contribute
by yaklichk0719
on Jul 19, 2018 at 17:00
    Can somebody please explain me what should be in the folder perl5.10/lib/site_perl/? I have perl 5.10.1 under centOS 6.6 and it does not have site_perl. Another package that I have been been trying to run requires the presence of this path perl5.10/lib/site_perl. Where can I download files for this site_perl? Please help me to figure this out. I really appreciate it.
I need help installing DBD:Oracle and DBD
1 direct reply — Read more / Contribute
by gandolf989
on Jul 19, 2018 at 09:33

    I am trying to install DBD:Oracle and DBD so that I can write a script to clean up some attachments with our primary database, and change the pointers to show that the attachments are gone. But I ran into an issue with the above packages. I tried the initial install using cpan. but I did not have the environment variables set, so it did not compile correctly. I would like to remove and reinstall the packages, or mostly just get them working. I do have an Oracle client on the server. But I will be connecting to another server for the database.

    Can someone point me in the right direction. The server is Redhat 6.8. Thanks

    $:~/ ./ Can't load '/usr/local/lib/perl5/site_perl/5.28.0/x86_64-linux/auto/DB +I/' for module DBI: /usr/local/lib/perl5/site_perl/5.28.0/x86_6 +4-linux/auto/DBI/ undefined symbol: PL_sv_immortals at /usr/li +b64/perl5/ line 200. at /usr/local/lib/perl5/site_perl/5.28.0/x86_64-linux/ line 284 +. BEGIN failed--compilation aborted at /usr/local/lib/perl5/site_perl/5. +28.0/x86_64-linux/ line 284. Compilation failed in require at /usr/local/lib/perl5/site_perl/5.28.0 +/x86_64-linux/DBD/ line 20. BEGIN failed--compilation aborted at /usr/local/lib/perl5/site_perl/5. +28.0/x86_64-linux/DBD/ line 20. Compilation failed in require at /home/oracle/scripts/purge_proddoc_sc +ript/ line 16. BEGIN failed--compilation aborted at /home/oracle/scripts/purge_proddo +c_script/ line 16 (#1) (F) The module you tried to load failed to load a dynamic extensio +n. This may either mean that you upgraded your version of perl to one that + is incompatible with your old dynamic extensions (which is known to h +appen between major versions of perl), or (more likely) that your dynami +c extension was built against an older version of the library that i +s installed on your system. You may need to rebuild your old dynamic extensions. Uncaught exception from user code: Can't load '/usr/local/lib/perl5/site_perl/5.28.0/x86_64-linux +/auto/DBI/' for module DBI: /usr/local/lib/perl5/site_perl/5.28 +.0/x86_64-linux/auto/DBI/ undefined symbol: PL_sv_immortals at + /usr/lib64/perl5/ line 200. at /usr/local/lib/perl5/site_perl/5.28.0/x86_64-linux/ line 284 +. BEGIN failed--compilation aborted at /usr/local/lib/perl5/site_perl/5. +28.0/x86_64-linux/ line 284. Compilation failed in require at /usr/local/lib/perl5/site_perl/5.28.0 +/x86_64-linux/DBD/ line 20. BEGIN failed--compilation aborted at /usr/local/lib/perl5/site_perl/5. +28.0/x86_64-linux/DBD/ line 20. Compilation failed in require at /home/oracle/scripts/purge_proddoc_sc +ript/ line 16. BEGIN failed--compilation aborted at /home/oracle/scripts/purge_proddo +c_script/ line 16. at /home/oracle/scripts/purge_proddoc_script/ +line 16. $:~/scripts/purge_proddoc_script > cat /etc/redhat-release Red Hat Enterprise Linux Server release 6.8 (Santiago)
    #!/usr/bin/perl use strict; use warnings; use diagnostics; package purge_proddoc_script; use Getopt::Std; # use Sys::Hostname; use POSIX qw(setuid setgid); use English; use Carp; use Cwd 'abs_path'; use DBD::Oracle qw(:ora_session_modes); use DBI; use File::Basename; use IO::Handle; use Log::Log4perl qw( :easy ); use Text::Diff; local $SIG{__WARN__} = \&Carp::cluck; $SIG{__DIE__} = sub { # return if $^S; # ignore die in an eval block # Get the actual caller for the "die" and not the wrapper local $Log::Log4perl::caller_depth; $Log::Log4perl::caller_depth++; LOGDIE($_[0]); }; # possible log values: DEBUG, INFO, WARN, ERROR, FATAL my $debug_level="INFO"; # my $error_mail_list=',, vkamins@aire,'; my $error_mail_list=''; # Unbuffer STDOUT and STDERR select STDERR; $| = 1; select STDOUT; $| = 1;
Migrating from Windows Server 2003
6 direct replies — Read more / Contribute
by cochise33
on Jul 19, 2018 at 08:26
    I'm running Perl on a Windows 2003 Server. The time has come to finally move to a more current version of Windows and I was wondering if you guys have any suggestions or warnings. Am I going to have any problems with Windows Server 12 or 16?

    Though I've used Perl for 20 years, I've only installed/reinstalled it or any packages like GD or some .pdf scripts a couple of times, so from that angle I'm a beginner.

    We also use MDaemon for the email part of what we do.

    Thanks for any help,

New Meditations
use Memoize;
2 direct replies — Read more / Contribute
by Anonymous Monk
on Jul 16, 2018 at 15:18
    I was porting a script to a module and noticed it kept getting slower. The script could initialize its expensive data structure once at the top and be done with it, but in order to encapsulate, the module was calling the function several times. I remembered the core module Memoize and added one line to the top of the program and now it runs fast again, 4x faster than without Memoize!
    use Memoize; memoize('some_sub');
    Only 1.5 seconds to start a program that was taking 6 seconds!
Log In?

What's my password?
Create A New User
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2018-07-22 11:00 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (454 votes). Check out past polls.