Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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.

poll ideas quest 2020
Starts at: Jan 01, 2020 at 00:00
Ends at: Dec 31, 2020 at 23:59
Current Status: Active
6 replies 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
Perl in Stack Overflow 2020 Survey
on May 28, 2020 at 21:31
0 replies by RonW
IntraMine service suite
on May 26, 2020 at 13:59
0 replies by Anonymous Monk

    Dear suPerlatives,

    Allow me to introduce Intramine, an intranet service suite for Windows done in Strawberry Perl and JavaScript that provides sub-second local search of your half a million or more source and text files, among other things.

    Some other things:

    • five-second index update when you change a file, to keep searches current
    • automatic linking for all source and text and image file mentions, with minimal overhead (often none)
    • a really nice file Viewer to browse your files, and see search hits in full context (plus that automatic linking)
    • image hovers in your source and text files
    • Gloss, a markdown variant specifically for intranet use that takes advantage of autolinking and minimizes "computer friendly" overhead
    • scalable services: write your own IntraMine service, with or without a front end, and run multiple instances that can talk to other services
    • Search, Viewer, and Linker service support for 137 programming languages, as well as plain text
    • all original work is covered by an UNLICENSE.

    For a README and downloads see




Special character in file name -- die error messed up
3 direct replies — Read more / Contribute
by leszekdubiel
on May 28, 2020 at 04:53

    Is there any way to make "die" handle polish file names better? It's all about chars in file name. See:

    # cat ąćęłń.pl 
    #!/usr/bin/perl -CSDA
    use utf8; 
    die "language specific chars:  ąćęłń"; 
    # ./ąćęłń.pl 
    language specific chars:  ąćęłń at ./
        ó.pl line 5.
Adding items to arrays: best approach?
7 direct replies — Read more / Contribute
by geertvc
on May 28, 2020 at 03:28

    Being a beginning "Perl-learner", I want to do things the (most?) right/best way immediately.

    I have a question about the right/best way to append items to an already existing array. This is my initial array:
    $inputPathPrefix = "C:/Temp/xml"; @inputfiles = ( $inputPathPrefix . "/test1.xml", $inputPathPrefix . "/test2.xml", $inputPathPrefix . "/test3.xml" );
    I would like to extend the array. Therefor, there are 2 ways of doing this AFAIK:

    First method:
    @inputfiles = ( @inputfiles, $inputPathPrefix . "/test4.xml", $inputPathPrefix . "/test5.xml", $inputPathPrefix . "/test6.xml", $inputPathPrefix . "/test7.xml" )
    Second method:
    push(@inputfiles, $inputPathPrefix . "/test4.xml"); push(@inputfiles, $inputPathPrefix . "/test5.xml"); push(@inputfiles, $inputPathPrefix . "/test6.xml"); push(@inputfiles, $inputPathPrefix . "/test7.xml");

    Three questions:

    1. What's the best/preferred/Perl-ish method?
    2. Has the first method advantages over the second method or vice versa? What are the advantages, if any?
    3. What's the habbit in case of initial array declaration and first method: put the comma's at the back or at the front?

Identifying CJK Unified Characters
1 direct reply — Read more / Contribute
by audioboxer
on May 27, 2020 at 23:55
    Hi Everyone!

    I am trying to identify CJK Unified Characters in XML data I am parsing in order to skip over it. I have no clue where to start and looking for guidance. Web searches yield no helpful results (that I understand anyway). This is outside of my beginners realm.

    Characters for example, 端子

    Thanks in advance.

perl compile time options
1 direct reply — Read more / Contribute
by dheffx
on May 26, 2020 at 14:12

    We currently use 5.18.4 in production but as we move from Centos 6 -> Amazon Linux 2 there is a desire to bring our version of Perl up to date along the way. When I am building 5.30.2, I notice the compile time options by default are different than the ones used for the 5.18.4 package. I could not find any useful documentation on the Perl compile time operators. Am I just missing some documentation on these? If so a pointer in the right direction would be appreciated. If not, there are two in particular that were used for 5.18.4 but not 5.30.2 that I am having trouble digging up what they actually do: PERL_HASH_FUNC_ONE_AT_A_TIME_HARD and PERL_SAWAMPERSAND. Would appreciate some help understanding the impact of these two flags.

cpnam GD error
4 direct replies — Read more / Contribute
by Jerry_J
on May 26, 2020 at 11:12

    I just received the Martien Verbruggen bood "Graphics Programming with Perl". After reading the first 20 pages, I liked the book and decided to install the GD module. I am running Windows 10 with Active Perl: "perl 5, version 20, subversion 2 (v5.20.2) built for MSWin32-x64-multi-thread" When I try to install GD via cpanm I receive the following:

    C:>cpanm GD --> Working on GD Fetching ... + OK Configuring GD-2.71 ... N/A ! Configure failed for GD-2.71. See C:\Users\Jerry\.cpanm\work\1590342 +755.3924\build.log for details.

    The build log has the following error:

    cpanm (App::cpanminus) 1.7044 on perl 5.020002 built for MSWin32-x64-m +ulti-thread Work directory is C:\Users\Jerry/.cpanm/work/1590342755.3924 You have make C:\Perl64\site\bin\dmake.exe You have LWP 6.44 Falling back to Archive::Tar 2.04 Searching GD () on cpanmetadb ... --> Working on GD Fetching -> OK Unpacking GD-2.71.tar.gz Entering GD-2.71 Checking configure dependencies from META.json Checking if you have ExtUtils::PkgConfig 0 ... Yes (1.16) Checking if you have ExtUtils::Constant 0.22 ... Yes (0.23) Configuring GD-2.71 Running Makefile.PL Notice: Type perl Makefile.PL -h for command-line option summary. 'gdlib-config' is not recognized as an internal or external command, operable program or batch file. Package gdlib was not found in the pkg-config search path. Perhaps you should add the directory containing `gdlib.pc' to the PKG_CONFIG_PATH environment variable No package 'gdlib' found at Makefile.PL line 449. *** can not find package gdlib *** check that it is properly installed and available in PKG_CONFIG_PA +TH at Makefile.PL line 449. -> N/A -> FAIL Configure failed for GD-2.71. See C:\Users\Jerry\.cpanm\work\1 +590342755.3924\build.log for details.

    I searched my computer and the gdlib.pc file is not on my machine. Being very much a novice on debugging these types of errors, I am hoping other can help me with getting this GD module installed. Any help you can provide is appreciated.

Appending /*.* to default Perl variable $_
2 direct replies — Read more / Contribute
by geertvc
on May 26, 2020 at 03:35
    First time ever post here...

    I have an array with directory names:
    my @codeOutputDirs = ( "output/$harvester$flavour/layout", "output/$harvester$flavour/tabview", "output/$harvester$flavour/udw", "output/$harvester$flavour/values", "output/$harvester$flavour/udw/service", "output/$harvester$flavour/udw/cfg" );
    The variables $harvester and $flavour are passed as parameters on the command line when calling the Perl script.

    I want to use a for loop to go through the array and do some stuff like so:
    make_path "output/$harvester$flavour/layout"; unlink glob "output/$harvester$flavour/layout/*.*";
    And this, for each and every element in the array.

    For this, I'm using the following Perl-ish (I guess?) way of traversing through each and every element of the array:
    for (@codeOutputDirs) { make_path $_; unlink glob $_/*.*; }
    The first command, make_path $_; is fine.
    However, the second command has issues when I append /*.* to the default variable $_

    Can someone tell me how to accomplish this using the correct syntax? Putting $_ between {} doesn't seem to be the solution.

Drawing A Dichotomous Key
4 direct replies — Read more / Contribute
by varanasi
on May 25, 2020 at 15:52

    I would like to draw, and ultimately print, a dichotomous key. A dichotomous key works rather like a flowchart or decision tree with a yes/no choice at each node. There's an explanation with some nice examples of possible pictures here:

    I suspect that what I need is in cpan, but I've searched cpan without success.

How to substitute all tabs only in a specific field
6 direct replies — Read more / Contribute
by xuo
on May 25, 2020 at 09:33

    I'm asking again for your help.
    I know the title seems quite obvious but it is something I was not able to do.
    Here is my input file :
    a b x1 x2
    c d x2
    e f x3 x4 x5

    And I want it to become :
    a b x1,x2
    c d x2
    e f x3,x4,x5

    In other words, I want to substitute all <tabs/space> in the field that starts and ends with <double quotes> by <commas>.
    The number of fields between quotes can be of any value (practically it will never be greater than 6 or 7 but I'd like something generic).
    And I want to do this (if possible) on a unix command line ie :
    perl -pe 's/.../g' < input_file > output_file.

    Do you know how to achieve this ?


Two octal values for eacute?
2 direct replies — Read more / Contribute
by pianomonious
on May 23, 2020 at 16:16

    Friends... I'm slowing losing my mind trying to figure out why I must capture an eacute character (as in café) via two octal regex patterns.

    In short, I parse old text files and often come across some extended ASCII characters like en-dash, ellipsis, eacute, etc. which were encoded that way by some spreadsheet program like Excel or Open Office Calc.

    Here are the two regexes that capture eacute for me:

    if ($field =~ /\351/) { ... } if ($field =~ /\303\251/) { ... }

    The first variation (octal 351) agrees with the ASCII table shown here:

    My terminal program cannot display this character, and this online octal-to-ascii converter cannot either:

    Yet, my Firefox browser is able to render this eacute character properly, when reading it from a text file.

    The second variation (octal 303 251) is not mentioned in any ASCII table, but the eacute symbol is rendered correctly by my terminal program and can be properly converted by the octal-to-ascii converter mentioned above. As well, Firefox can render this properly from a text file.

    Could someone please shed some light on what is happening?

    Thanks in advance, and my apologies if I'm missing something obvious.

Some simple math and absolute values
6 direct replies — Read more / Contribute
by sidmuchrock
on May 22, 2020 at 21:55
    I'm wondering how to do this better than my 4 line method. Feels like I'm missing something obvious. But example code below works Basically I want to show weight * price = total but allow a minimum weight but if it's a negative weight it should be the reverse of the above Expected results: 2.3 = $23 .3 = $10 0 = $10 -.3 = -$10 -2.3 = -$23
    $wt = $ARGV[0]; $min = 1; $price = 10; while ($wt ne '') { $nwt = abs($wt); $nwt = $min if $nwt<$min; $total = $nwt*$price; $total = -$total if $wt<0; print "Price: $total\n"; print "Next Weight: "; chomp($wt = <stdin>); }
(Ab)using the Regex Engine
2 direct replies — Read more / Contribute
by jo37
on May 25, 2020 at 05:19

    The TASK #2 of perl-weekly-challenge-061 was to split a given string into certain subparts. There were two solutions that (ab)use Perl's regular expression engine to get all matches for the leading part of a regular expression. Though being one of the authors, I'm not so sure about this approach. How smart is the engine allowed to be? Is there a way to guarantee that it actually tries all possibilities?

    The section Embedded Code Execution Frequency in perlre says:

    How non-accepting pathways and match failures affect the number of times a pattern is executed is specifically unspecified and may vary depending on what optimizations can be applied to the pattern and is likely to change from version to version.
    This is a rather clear statement, that the proposed solutions may fail in future versions of Perl. But does this hold in any case? See examples in this program:

    #!/usr/bin/perl use strict; use warnings; my $match = qr[([ab]+)([ab]+)]; my $str = 'aba'; $str =~ /^ $match $ (?{ print "1: $1-$2\n" }) [c] /x; $str =~ /^ $match $ (?{ print "2: $1-$2\n" }) (?!) /x; $str =~ /^ $match $ (??{ print "3: $1-$2\n"; qr[(?!)] }) /x; __DATA__ 2: ab-a 2: a-ba 3: ab-a 3: a-ba

    Explanations to the numbered samples:

    1. There is a non-matched character class [c] at the end of the pattern. In my copy of the "Camel Book" (3rd Edition, 2000) it is stated that the engine is smart enough to optimize away the match attempt if there is a single character, but not if it is inside a character class. The engine has become smarter since then: the (?{CODE}) block is not executed.
    2. Currently, using a negative look-ahead assertion as a non-matcher outsmarts the engine into trying to match the string. I reckon that the matching attempt might be optimized away in future versions.
    3. With a small change, the resulting pattern remains the same but isn't known to the regex engine from the beginning, as the final part now is the returned value from a (??{CODE}) block. To decide if there is a match, the CODE has to be executed and thus cannot be optimized away. Would sniffing at the CODE and detecting that it always returns something non-matchable be "legal"? I feel kind of safe with this but I may be wrong.
    Would you agree with this statement, that seems to be in contrast to the quotation above?
    A (??{CODE}) block is guaranteed to be executed, if the failing or success of a pathway containing this block solely depends on the returned subexpression.
    Could we even have a zero-width assertion like (?!?{CODE}) that always fails but must not be optimized away in the sense of the previous proposition?

    I'd be glad to see your opinions.

    BTW: What matches and what is matched? Is a regex matching a string or is a string matching a regex? I don't know.


PerlMonks Discussions
Adding details with summary html tags
4 direct replies — Read more / Contribute
by Lady_Aleena
on May 22, 2020 at 14:23

    I was wondering if <details> with <summary> could be added as acceptable html here in PerlMonks. Those tags could be used when code or data examples are more than 10 or so lines. <readmore> is great for keeping long batches of code or data from the main list of posts, however, long batches of code might do well if kept in a <details> tag where the code or data can be hidden to keep page lengths from being over long upon initial load. So what do you all think?

    My OS is Debian 10 (Buster); my perl version is 5.28.1.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena
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 contemplating the Monastery: (9)
As of 2020-05-29 08:21 GMT
Find Nodes?
    Voting Booth?
    If programming languages were movie genres, Perl would be:

    Results (168 votes). Check out past polls.