Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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
How do I determine if a variable contains a type glob?
4 direct replies — Read more / Contribute
by dpchrist
on Dec 04, 2016 at 15:52

    I would like to write a subroutine is_typeglob($) that returns true when passed a type glob and returns false when not passed a type glob. (I already have a subroutine is_typeglob_ref($).)

    This is a scratch program I wrote to experiment with some ideas:

    2016-12-04 12:35:05 dpchrist@debian ~/sandbox/perl $ cat #!/usr/bin/perl use strict; use warnings; use Data::Dumper; $Data::Dumper::Indent = 0; use Scalar::Util qw(blessed openhandle reftype); { no warnings 'once'; open (FH, '<', $0) or die "ERROR: open(): $!"; } for ( q(*ARGV ), q(*ARGV cmp '*ARGV' ), q(*ARGV cmp "*ARGV" ), q(*ARGV cmp '*::ARGV' ), q(*ARGV cmp "*::ARGV" ), q(ref *ARGV ), q(blessed *ARGV ), q(openhandle *ARGV ), q(reftype *ARGV ), ) { my $code = $_; my $r = eval $code; print Data::Dumper->Dump([$code, $r, $@], [qw(code r @)]), "\n"; } # $Id:,v 1.1 2016/12/04 20:35:04 dpchrist Exp $

    Here is a sample run:

    2016-12-04 12:42:14 dpchrist@debian ~/sandbox/perl $ perl $code = '*ARGV ';$r = *::ARGV;$@ = ''; $code = '*ARGV cmp \'*ARGV\' ';$r = 1;$@ = ''; $code = '*ARGV cmp "*ARGV" ';$r = 1;$@ = ''; $code = '*ARGV cmp \'*::ARGV\' ';$r = 1;$@ = ''; $code = '*ARGV cmp "*::ARGV" ';$r = 1;$@ = ''; $code = 'ref *ARGV ';$r = '';$@ = ''; $code = 'blessed *ARGV ';$r = undef;$@ = ''; $code = 'openhandle *ARGV ';$r = undef;$@ = ''; $code = 'reftype *ARGV ';$r = undef;$@ = '';

    How do I determine if a variable contains a type glob?

sane way to configure perlbrew and h2ph on Ubuntu
1 direct reply — Read more / Contribute
by glasswalk3r
on Dec 04, 2016 at 13:53

    Hello fellow monks!

    Meanwhile I'm working to release a new module to CPAN, I find out that Ubuntu and h2ph don't play nice with each other (at least when I using perlbrew).

    After running h2ph as documented, I find out that the perl was expecting to find the ph files in different locations that they are stored in /usr/include. Some research led me to find that this is because change to a "multiarch", whatever that means). Unfortunately, I didn't find anything that would help fix the issue.

    I was getting errors like:

    # Error: Can't locate bits/ in @INC (did you run h2ph?) + (@INC contains: /home/me/Projetos/Linux-NFS-BigDir/.build/MHr69O96uB +/blib/lib /home/me/Projetos/Linux-NFS-BigDir/.build/MHr69O96uB/blib/a +rch /home/me/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/x8 +6_64-linux /home/me/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5. +24.0 /home/me/perl5/perlbrew/perls/perl-5.24.0/lib/5.24.0/x86_64-linu +x /home/me/perl5/perlbrew/perls/perl-5.24.0/lib/5.24.0 .) at /home/me +/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/sys/ + line 9.

    In order to fix such things, I searched for the corresponding ph file generated by h2ph in $Config{'installsitearch'} and created a symbolic link to the directory by using the expected alias, for instance:

    ln -s /home/me/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/x +86_64-linux/x86_64-linux-gnu/bits /home/me/perl5/perlbrew/perls/perl- +5.24.0/lib/site_perl/5.24.0/bits

    That works... but I had to repeat that three times to fix all the errors. An educated guess is that I'm going to repeat the process for every instance of Perl installed with Perlbrew (I have several).

    Is there a cleaner way to do that? Maybe a different options when compiling perl?

    Thanks in advance,

    Alceu Rodrigues de Freitas Junior
    "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill
Perl debugging initialization: did I just reinvent the wheel?
5 direct replies — Read more / Contribute
by mpersico
on Dec 01, 2016 at 14:53

    I have worked out a system that allows me to maintain breakpoints in the Perl debugger from session to session and load them up next time I run the debugger:

    First, I create a ~/.perldb file that contains:

    ## -*- cperl -*- sub afterinit { use Cwd; my $dbg = getcwd(). "/.perldb"; print "$dbg...\n"; if ( -e $dbg ) { no strict; do $dbg; } }

    Then I create a local .perldb file in the current working directory where I run  perl -d:

    ## -*- cperl -*- push @DB::typeahead, 'f', 'b 75', 'f bin/mymainscript', 'b 180', 'b 192', 'L';

    So, my questions are:

    1) Is this technique widely enough known that I would look like an idiot for blogging about it?

    2) Is the usage of @DB::typeahead unsafe in that it's a direct tap into the DB module that may be changed and, therefore, should not be promoted?

    Thank you.
basic question: regular expression
4 direct replies — Read more / Contribute
by Anonymous Monk
on Dec 01, 2016 at 02:08

    Hi Monks,

    I played with regular expression and perl does something different as I would expect. Only the "+" operator worked as expected. When the "*" or "?" is at the end of a expression, is seems it is sometimes not greedy. Please see my example:

    use strict; use warnings; $_="kkkaaabc"; print "String = $_\n"; print "1 $& Expected: ka ?? /k?a?/\n" if /k?a?/; print "2 $& Expected: kkka OK\n" if /k*a?/; print "3 $& Expected: kaaa OK\n" if /k?a+/; print "4 $& Expected: kkkaaa OK\n" if /k+a+/; print "5 $& Expected: kaaa ?? /k?a*/\n" if /k?a*/; print "6 $& Expected: kkkaaa OK\n" if /k*a*/;

    The result is:

    String = kkkaaabc 1 k Expected: ka ?? /k?a?/ 2 kkka Expected: kkka OK 3 kaaa Expected: kaaa OK 4 kkkaaa Expected: kkkaaa OK 5 k Expected: kaaa ?? /k?a*/ 6 kkkaaa Expected: kkkaaa OK

    Why do I get in case 1 and 5 no "a" at the end of the matching circuit ??. Many Thanks for any help !

Formatting quotes in a String
4 direct replies — Read more / Contribute
by pavan474
on Nov 30, 2016 at 08:48
    Hi All,

    I am new working with PERL. I have a requirement where i have a string having double quotes where it will be open but not closed i.e.,

     $string = '"testing the data available';

    I need to format the string in such a way that it shoul look like

    $string = '"testing the data available"';

    can you please suggest me rather than looping through each word in the string and update the closing string.

Digest::CRC giving unexpected result
1 direct reply — Read more / Contribute
by NickGribble
on Nov 30, 2016 at 08:24

    I'm sent data files that have CRC32Q validation on each line. I wrote a script to check each line and it used to give the same value as the checksum in the file but now it doesn't and the code hasn't been changed. Checking the data online shows that the CRC in the file is correct so it's clearly my code that's wrong, but where? In this snippet I've created a page to check that the basic code is correct for just one line. The checksum should be 0x19F112C6 but I'm getting 0x1D094D45. Many thanks.

    #!/usr/bin/perl -w use CGI ':standard'; use CGI::Carp qw(fatalsToBrowser); use Digest::CRC; use strict; my $dataToCheck = 'EGCJOBSTHANGAR534712.29N0011243.02W65.26214.10N4520 +18.84432555.4217.0255.84100503/03/2015'; my $crcOnFile = '19F112C6'; my $ctx = Digest::CRC -> new( width => 32, poly => 0x814141AB, refin = +> 0, refout => 0, xorout => 0, init => 0 ); # Convert $dataToCheck to hex. $dataToCheck =~ s/(.)/sprintf("%X",ord($1))/eg; $ctx -> add( $dataToCheck ); my $crc = uc( $ctx -> hexdigest ); print "Content-type: text/html \n\n"; print '<html><body>'; print "Calculated value = $crc, correct value = $crcOnFile"; print '</body></html>';
split problem
6 direct replies — Read more / Contribute
by rmarkman
on Nov 29, 2016 at 17:13

    Perl 5, version 22, subversion 0 (v5.22.0) built for MSWin32-x64-multi-thread gives this error

    Modification of a read-only value attempted at test.plx line 6.

    With this program:

    use strict; my $value = "A\tB\tC\tD\tE\tF\t\t\t\t"; my @flds; @flds = split(/\t/,$value); $flds[16] = undef; $flds[8] = 0;

    No error is generated if any of: eliminate the trailing tabs in $value; eliminate the call to split; call split with a -1 limit. I am mystified.

twig_print_outside_roots replaces " with &quote; and ' with &apos;
6 direct replies — Read more / Contribute
by dimitarsh1
on Nov 29, 2016 at 12:05
    Hello, When reading and HTML file with TWIG and the twig_print_outside_roots enabled, all " are replaced with &quote; and all ' are replaced with &apos;. Even if I enable the keep_encoding option nothing changes. Does anyone have any idea? Thanks in advance, Dimitar.
How to restart a while loop that is iterating through each line of a file?
7 direct replies — Read more / Contribute
by cookersjs
on Nov 28, 2016 at 16:51

    Greetings monks,
    I am currently trying to solve a loop riddle that has bested me.
    The problem: I am trying to take the first 16 lines of a single file, and populate those same 16 lines in 34 different (but incrementally named) files. My current code:

    my $filename = "../../Annotation_output"; for (my $i=0; $i<=33; $i++) { my $file_count = $i; open(my $new_fh, '>>', ("$filename" . "$file_count" . ".vcf")); my $count = 0; while (<$fh>) { print $new_fh "$_"; $count++; if ($count == 16) { last; } } }
    $fh is the file im trying to take the 16 lines from, FYI

    I have had the first file (Annotation_output0.vcf) gain the 16 lines needed, but never any files afterward.

    Common outputs have included having each of the 34 files gain 16 lines with the while loop never reseting (So Annotation_output0.vcf = lines 0-15, Annotation_output1.vcf = lines 16-31, Annotation_output2.vcf = lines 32-47, and so on), as well as seeing just output0.vcf gain 16 lines while output1.vcf gains the entirety of the while loop, never advancing past $i = 2

    Any help is appreciated!

New Meditations
(Placeholder) Imagine!
5 direct replies — Read more / Contribute
by BrowserUk
on Nov 29, 2016 at 22:24

    This place excels in starting with a single, clearly defined, abstracted problem, and refining the set of proposed solutions down to a clear, concise, efficient solution. Many hands make light work!

    Now, imagine if each of the Perl(5) opcodes was proffered here -- say: one per weekend -- on a Friday night - say: US West Coast time -- in the form of a hack-a-thon task for that weekend.

    What might result from that exposure of a clearly defined task to the assembled (and usually quite bored on weekends), diverse populous?

    If those more enlightened tolorant members of p5p were enthused to cast a critical eye over the proceedings -- to catch the less obvious pitfalls in the evolution of solutions -- then the results might be usefully fed back into the p5p process and result in benefits for all.

    Thoughts on: Is the idea viable?

    Thoughts on: Are any members of p5p willing to participate?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
    In the absence of evidence, opinion is indistinguishable from prejudice.
Propose addition to use warnings?
6 direct replies — Read more / Contribute
by perldigious
on Nov 28, 2016 at 09:30

    I'm not sure what the official mechanism for making such a suggestion would be, but I recently had to go on a bug hunt in my code that left me surprised use warnings didn't give me some sort of, "are you SURE you aren't doing something silly here at line x?" message. Maybe it isn't practical to expect use warnings to save me from myself in this case, but I figured I'd throw it out here as a meditation for discussion and to get opinions from Monks far wiser than I am.

    I'm of course simplifying and paraphrasing, but essentially I had some code that did the following:

    open(my $first_fh, "<", "file1.txt") or die "Cannot open \"file1.txt\" +: $!."; open(my $second_fh, "<", "file2.txt") or die "Cannot open \"file2.txt\ +": $!."; my @file1_lines = <$first_fh>; close $first_fh; while (my $line = <$second_fh>) { my @data = my_sub($first_fh, $line); # copy/paste error, should ha +ve passed $second_fh here # and of course a bunch of non-relevant stuff here }

    So I accidentally passed the $first_fh that I had previously closed to my_sub, but as it turns out use warnings didn't make a peep about this. I did of course get warnings from inside my_sub when it attempted to make use of the filehandle, but the kicker was that any such use was wrapped inside of a conditional that actually made it very rare it would ever get used (maybe once every 100,000 lines or so of typical data).

    DISCLAIMER: The fact that I didn't have something in my standard test data that ensured the conditional that used the filehandle was exercised is entirely on me (forgive me, for I have sinned). I accept full responsibility for that mistake and the initial copy/paste laziness error that forced me to engage in my bug hunt. I'm only pointing out that usually use strict, use warnings, or perl itself is pretty good about preemptively saving me from myself, and in this case it didn't.

    Any thoughts from the Monastery?

    Just another Perl hooker - will code for food
New Cool Uses for Perl
picwoodpecker -- a Tk program to choose and modify your photos
3 direct replies — Read more / Contribute
by Discipulus
on Nov 30, 2016 at 03:37
    Hello monks,

    after months of sparetime works I'm proud to present you picwoodpecker my last Tk effort (now also on github).

    It is application to review and copy pictures with many features.

    Suggestions are welcome.Tests with exif tags from different cameras are even more welcome.

    The post is splitted in 3 parts: here you have the rendered documentation, below there is the code and finally the POD that must be pasted after the __DATA__ token of the program.

                   This software is dedicated to my parents, who need to see printed pictures -- 6 July 1966 




    perl [-s -d -debug -pr -wr -p -x -y -nothumbs -e -quality -pngcompression -df]


         -s|src|source        path
                        the path where search for jpg files to be loaded
                        Can be modified in the Tk interface

    -d|dest|destination path path used to save files Can be modified in the Tk interface

    -debug print more information on the screen Can be modified in the Tk interface

    -pr|phratio floating point the ratio used to display the current photo Can be modified in the Tk interface

    -wr|winratio floating point the ratio to size the window where the photo is displayed Can be modified in the Tk interface

    -p|preload integer how many photos load in memory after and before the current one. Can increase drawing speed time

    -x|gridx integer how many columns in the thumbnail grid

    -y|gridy integer how many rows in the thumbnail grid

    -nothumbs does not load thumbnails at all

    -e|extension jpg|gif|png|gd|gd2 the exstension of saved files Can be modified in the Tk interface

    -quality|jpegquality 0-100 the quality of the file used by GD when saving the current photo in jpeg format An empty value let GD to choose a good default Can be modified in the Tk interface

    -pngcompression 0-9 the compression factor used by GD when saving the current photo in png format -dateformat|df string the format used for dates. It defaults to %Y_%m_%d_%H_%M_%S in such way resulting pics can be ordered correctly. See C<strftime> in L<POSIX> to more hints about formatting.


    The program is aimed to let you to easely choose among photos and save one (or more) copy in the preferred format (jpg as default; gif png gd and gd2 are also available). The name of the copy is crafted using the timestamp when the photo was taken.

    Basically the program will load all jpg files found globbing the path given with command line parameter -source or entered in the graphical interface, and foreach file will examine some exif tags to get sizes, timestamps and the thumbnail (if not present showing a black empty one).

    Orientation of the image is handled automatically for thumbnails and main photo.

    Advanced options are available to manipulate how many photos are copied, in which format and let you to postprocess via exiftool each created image.

    The program uses GD for image manipulation and Image::ExifTool to load infos from photos and in the postprocess of them.


    A main control window and a display one are created. Optionally a third window is created to access the advanced copy options. The display window tends to take the focus being the program focused on displaying photos.

    control window

    The control window contains:

    • all controls to manipulate the photo list (&#39;browse&#39; &#39;new list&#39; &#39;view list&#39; &#39;add to list&#39; and &#39;clear list&#39;) Note the that the &#39;browse&#39; does not fill the list; you need to use &#39;new list&#39; or &#39;add to list&#39; after using it.
    • an entry to choose the destination folder (that will be checked for existence)
    • the photo ratio and the window ratio controls and the debug switch
    • an informative text about the current displayed photo or about the grid of thumbnails
    • the editable name of the current photo (and an eventual suffix) used to save it
    • an information text about the status of the main program (with only relevant information about copying and loading operations as eventual errors)
    • the save button and the advanced options one.
    • controls to navigate the photo list

    display window

    The display window will starts showing a grid of thumbnails. The first one is selected. You can navigate the grid using right arrow and left arrow of the keyboard to move the current selection on or back.

    up arrow and down arrow let you load previous or next grids of thumbanails.

    Enter key will open the currently selected thumbanil in a bigger resolution ( determinted by photo ratio parameter) photo filling the whole window.

    When just one photo is displayed right arrow and left arrow of the keyboard can be used to show next and previous photo while up arrow and down arrow bring you back to the thumbnail view.

    In both control and display window space bar can be used to save the current photo and p key can be used to toggle autoplay. If autoplay is active the time between photos can be set in the control window. Please note that specifying a short amount of time (shorter than the time needed to load photos data) can produce weird showing behaviours.

    advanced copy options

    This menu lets you to have a granular control about how original photo will be copied.

    The allow overwrite if checked silently overwrite a photo wich has the same name of what is composed for the current one.

    bypass original file elaboration (simple copy) make a copy of the original file using the new name but without processing it with GD

    output file type lets you to choose among different file fomrmats (jpeg, gif, png, gd and gd2) and to set the quality (0-100) for jpeg ones. For png files the compression factor (0-9) can be specified only via the command line parameter -pngcompression

    enable multiple copies is trickier. If enabled lets you to choose to copy the file many times, each one with a different resolution. In the multi copies pattern you can specify different resolutions in the format widthxheigth as in 800x600 or 1024x768 and for each format a copy will be created.

    enable post processing can be used to postprocess every image with exiftool program that ships with Image::ExifTool module. You can use alternative program to postprocess your image inserting the full path in the program field. Arguments to such program can be also specified where $ can be used to refer to the full path of the original image. In the exiftool command line you can also specify @ to refer to the current file. So you can postprocess every copy using the following arguments:

    -overwrite_original -all= -tagsFromFile $ -ImageSize -ImageWidth -ImageHeight -ThumbnailImage -Orientation -DateTimeOriginal

    This exiftool command will be issued for every copy made, overwriting each exif tags in the copy, removing them all but taking some tag frome the original file and applying them to the copy. See the exiftool page for a lot of options this wonderful program lets you to use.


    The program was tested against few different camera formats; i dont know if exif tags extracted are widely valid.

    The autoplay feature does not plays well with little time intervals: infact when the interval is smaller than the overall time taken to load the the photo and to redesign the display i'll notice photos and information skipped and the timer going on. I tried fixing this using waitVisibility Tk method, with no luck.


    This software and icons are copyright of Discipulus as found on You may redistribute or modify it under the same term of Perl itself.


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 having an uproarious good time at the Monastery: (11)
As of 2016-12-05 14:18 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (84 votes). Check out past polls.