Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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
Overriding Global Variables
4 direct replies — Read more / Contribute
by Mano_Man
on Nov 19, 2017 at 08:41

    Hi Monks,

    I'm looking for a way to have identical global variables in every package, and a single module that utilizes the data from them


    package my_first; use Debug; # Imports in sub debug our $DEBUG_FLAG =1; debug("Print me"); #prints: Print me 1; package my_second; use Debug; our $DEBUG_FLAG =0; debug("Print me"); #prints none 1; package Debug; our $DEBUG_FLAG =0; #Default value sub debug($) { if(DEBUG_FLAG){ say $_[0]; } } 1;

    Hope this is clear, appreciate any help.Looking for smart suggestions, better ways to do this (not OOP wise), and any other tidbit you can think of.

Mixing OR with conditional operator
2 direct replies — Read more / Contribute
by jockel
on Nov 19, 2017 at 05:12


    Can someone please explain this behavior. I was surprised with result of the following code. (And please help me come up with a better Title for this question)

    I think the variable $test should be set to $val1 (1) but instead it gets set to $val2 (undef)

    #/usr/bin/perl use strict; my $test; $test = 1 || (undef && undef != 0) ? undef : 0; print "test = $test\n";
    OUTPUT: test =
    -----BEGIN PERL GEEK CODE BLOCK----- Version: 0.01 P++>*$c--->---P6 > R >++++$M+>+++$O+++>+++$MA->+++$E > PU->++BD->-C+>+$D+>+$S->+++X >+WP >+++MO!PP n?CO--PO!>!(!)o?G!A--OLC--OLCC--OLJ--Ee !Ev-Eon-uL++>*uB!uS!uH-uo!w->!m+ ------END PERL GEEK CODE BLOCK------
Parsing DXF files for dimensional information
2 direct replies — Read more / Contribute
by talexb
on Nov 17, 2017 at 13:29

    It pains me that I know little about this area of technology, but I guess it's not possible to know everything. A colleague has a bunch of AutoCAD files that have to do with urban planning, and he wants to extract the following information from the equivalent DXF files:

    • Each corner point of each building lot with a latitude & longitude. Note that the lat. & long. may not be embedded in the file, but I am assuming the points are referred to on a relative scale so that they could be translated into lat & long data
    • The colour of each corner point (this is relevant information, added by the planner)
    • The area of each building lot - I believe that AutoCAD is calculating this.
    I have had a look at CPAN and haven't really found anything that will help me. My research on DXF tells me that it's a very low-level file, so I'm guessing that the information required may not even be available in the DXF file.

    If some monks have comments, thoughts, suggestions about where to begin, I'd appreciate it. Thanks!

    Alex / talexb / Toronto

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

Need a second set of eyes: Very odd failure
5 direct replies — Read more / Contribute
by blue_cowdawg
on Nov 17, 2017 at 11:57

    I must be missing something here so I'm asking for more eyes on something.

    I built a fairly simple straightforward module here and yet it is failing to work. This module does curls to an API (The Foreman) to extract some data from it. Nothing fancy here.... Here are the most important bits:

    package NCS::PuppetDB::Data; use 5.010000; use strict; use warnings; use JSON; our $curl="/usr/bin/curl -G 'http://localhost:8080/v3"; our $VERSION = '0.5.2'; sub new { my $self={}; bless $self,"NCS::PupptDB::Data"; return $self; } sub getHosts { my $self = shift; my $cmd=sprintf("%s/nodes 2>/dev/null",$curl); my $json = JSON->new->allow_nonref; my $jsonData=`$cmd`; my $decoded = $json->decode($jsonData); my $retval=[]; for my $entry(@$decoded){ push @$retval,$entry->{name}; } return sort $retval; } sub getHostFacts { my $self = shift; my $host = shift; my $cmd=sprintf("%s/nodes/%s/facts' 2>/dev/null",$curl,$host); my $json = JSON->new->allow_nonref; my $jsonData=`$cmd`; my $decoded = $json->decode($jsonData); my $retval = {}; for my $fact(@$decoded){ $retval->{$fact->{name}} = $fact->{value}; } return $retval; } sub getFact { my ($self,$host,$factname)=@_; my $facts=getHostFacts($host); return $facts->{$factname}; } 1;
    The one and only script using it (so far) is complaining:
    Can't locate object method "getHosts" via package "NCS::PupptDB::Data"
    What am I missing?

    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; Blog: Warning: No political correctness allowed.
How can increase number sequence in a variable
4 direct replies — Read more / Contribute
by yyy
on Nov 17, 2017 at 11:15
    Hi everyone,
    I have a few arrays naming @A_1, @A_2, @A_3.... I want to do a loop to for them, e.g.

    for(my $i =0; $i<10; $i++)
    { $A_$i[0] = 1234;

    I know $A_$i doesn't work. My question is how can I put $i into the array variable to make the sequence $A_1[0]=1234, $A_2[0]=1234,.......
Removing a test script from perl source
2 direct replies — Read more / Contribute
by syphilis
on Nov 17, 2017 at 06:59
    This question relates to a transient, ongoing problem that I have running 'make test' when building perl from source on Windows using mingw-w64 64-bit ports of gcc.
    (Never any such problem with the mingw-w64 32-bit ports of gcc.)

    In a nutshell, I often (but not always, depending upon the version of gcc) strike the problem that an IO-Compress test script will hang during 'make test'.
    My only means of escape from this hang (AFAIK) is to hit Ctrl-C, which kills the entire 'make test' process - meaning that none of the other ensuing tests are run.

    Currently, the offender is cpan/IO-Compress/t/105oneshot-rawdeflate.t when building 64-bit blead.
    No problem with 'make test' when blead is built using 64-bit gcc-7.1.0, but that script hangs when blead is built with 64-bit gcc-7.2.0.

    My question:
    How do I re-arrange the source so that 'make test' will skip cpan/IO-Compress/t/105oneshot-rawdeflate.t, and yet run all of the other test scripts ?

    I should add that AFAICS there's really no problem with either the actual hanging test script, or the perl that has been built.
    These hangs only ever occur when running the script under 'make test'.

resetting a foreach loop!
5 direct replies — Read more / Contribute
by lunette
on Nov 16, 2017 at 17:05
    hello, monks! it's been a little while, and i need some help with a small thing. i've figured out how to make this entire thing run, but i can't figure out how to clear the foreach loop for every new set of data it uploads from a file. the explicit package name for "@array" can't be moved into the loop because the subroutine below needs it as well, which seemed to be what everyone said would fix the problem.

    is there any other way to clear the data each time? i've tried 'next', 'last', and 'redo', and none of them seem to do anything besides mess the loop up entirely. i've also tried adding another array into the loop using the original array to manipulate the data into clearing that way, but as i thought, that did nothing.

    does anyone have any simple way of getting the data to clear for each loop? i'm sure it's something simple that i'm just overlooking. here's the code itself:

    #!usr/bin/perl use strict; use diagnostics; use warnings; my @array; my $average; while (1) { print "Enter an input file name: "; chomp (my $choice = <STDIN>); open (FH, '<', "C:/Users/tsukk/$choice"); while (my $data = <FH>) { push @array, $data; } my @largest = sort {$b<=>$a} @array; my @smallest = sort {$a<=>$b} @array; print "\nThe largest number is: "; print $largest[0], "\n"; print "The smallest number is: "; print $smallest[0]; print "The average of the numbers is: "; printf "%.1f\n", average(@array); print "\n"; $average = average(@array); foreach (@array) { chomp; if ($average > $_) { print "$_\t is below average.\n"; } elsif ($average < $_) { print "$_\t is above average.\n"; } elsif ($average = $_) { print "$_\t is equal to average.\n"; } } print "\nDo it again? (Yes or No): "; chomp (my $yesno=<STDIN>); if($yesno ne 'Yes') { print "Goodbye.\n"; exit; } } sub average { if (@array) { my @temp = @_; my $sum = 0; foreach (@temp) { $sum = $sum + $_; } return $sum/@temp; } }

    thank you!

Net::SMTP upgraded but with warnings
1 direct reply — Read more / Contribute
by bdegan2
on Nov 16, 2017 at 12:31

    We managed to upgrade Net::SMTP to 3.11 and IO::Socket::SSL to 2.052

    But we are getting these warning messages out when we call either of these modules:

    perl -MNet::SMTP -e 'print "$Net::SMTP::VERSION\n"' Constant subroutine IO::Socket::INET6::AF_INET6 redefined at /usr/lib/perl5/5.8.8/ line 65. at /usr/lib/perl5/vendor_perl/5.8.8/IO/Socket/ line 16 Prototype mismatch: sub IO::Socket::INET6::AF_INET6 () vs none at /usr/lib/perl5/5.8.8/ line 65. at /usr/lib/perl5/vendor_perl/5.8.8/IO/Socket/ line 16 Constant subroutine IO::Socket::INET6::PF_INET6 redefined at /usr/lib/perl5/5.8.8/ line 65. at /usr/lib/perl5/vendor_perl/5.8.8/IO/Socket/ line 16 Prototype mismatch: sub IO::Socket::INET6::PF_INET6 () vs none at /usr/lib/perl5/5.8.8/ line 65. at /usr/lib/perl5/vendor_perl/5.8.8/IO/Socket/ line 16 3.11

    We did have this issue during the upgrade:

    Went back through the install screens. even though I got an ok at the end, I found a MakeMaker version issue. I had to force install Make::Maker Net::SMTP is now installed,

    Our server is : uname -a Linux 2.6.18-53.1.6.el5 #1 SMP Wed Jan 16 03:56:15 EST 2008 x86_64 x86_64 x86_64 GNU/Linux

    Can these warning messages be disregarded ?? thank you

Looking for general pointers on Apache::Session
5 direct replies — Read more / Contribute
by nysus
on Nov 16, 2017 at 09:26

    I'm rolling my own little web development framework based on mod_perl 2 and jquery mobile. I've got a good start on making it easy to create navigation menus and generate forms and now I want to turn some attention to access control. I'm thinking of using Apache::Sessions to track user sessions to certain resources based on nothing other than that seems to be a possible solution based on what I've read. But before I do that, I wanted to check in with the Monks to see if I'm on the right track and offer some big picture guidance on using Apache::Sessions. Some specific questions I have to get started:

    1) What's the fastest way to store session data? In the DB? In a file? What are the advantages/disadvantages of the different methods?

    2) If I use a DB, do I have to set up the DB table for storing session data ahead of time or prep the DB in any way?

    3) There is a module called Apache::SessionManager. Not sure if that is the direction to take or not. It looks like it might do the same thing as Apache::Session but is built specifically for mod_perl. Is that right?

    Any other useful guidance or general pointers is appreciated. Thank you very much for your time.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

perl modules
6 direct replies — Read more / Contribute
by codestroman
on Nov 16, 2017 at 03:56

    Hi im new to perl, and im currently trying to create, and run my own module.

    Here is my module code .pm file

    #!/bin/usr/perl use warnings; sub dog { print "roof roof im a dog!\n"; } dog; 1;

    and here is my .pl file to run the simple module.

    #!/usr/bin/perl use lib '.'; use dog; dog;

    Every-time i try to run the code i get this message

    $ perl Can't locate in @INC (you may need to install the dog module) ( +@INC contains: . /usr/lib/perl5/site_perl /usr/share/perl5/site_perl /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5 +/core_perl /usr/share/perl5/core_perl) at line 4. BEGIN failed--compilation aborted at line 4.


    2017-11-17 Athanasius added code and paragragh tags

Strange behaviour of tr function in case the set1 is supplied by a variable
5 direct replies — Read more / Contribute
by likbez
on Nov 15, 2017 at 21:50
    Looks like in tr function a scalar variable is accepted as the fist argument, but is not compiled properly into set of characters
    $str1='abcde'; $str2='eda'; print "Test 1: strait set\n"; $diff1=$str1=~tr/$str2//; $diff2=$str1=~tr/eda//; print " diff1=$diff1, diff2=$diff2\n"; print "Test 2: complement set\n"; $diff1=$str1=~tr/$str2//c; $diff2=$str1=~tr/eda//c; print " diff1=$diff1, diff2=$diff2\n";
    This produces in perl 5, version 26:
    Test 1: strait set diff1=0, diff2=3 Test 2: complement set diff1=5, diff2=2

    Obviously only the second result in both tests is correct.

    Looks like only explicitly given first set is correctly compiled.

    Is this a feature or a bug ?

Access to standard module source code?
2 direct replies — Read more / Contribute
by chengchl
on Nov 15, 2017 at 18:08

    Hi Perl Experts

    I was wondering whether we have chance to look at the source code of the Perl standard modules like List::MoreUtils?

    I used some built-in functions and was amazed by how they work that well. Would be of great interest and curiosity to see what is inside but I searched online didn't get my luck. Any one knows? Thanks in advance!

New Meditations
Antiquitates - liber I - In memoriam Robert M. Pirsig
5 direct replies — Read more / Contribute
by Discipulus
on Nov 15, 2017 at 04:16

    Antiquitates - liber I - In memoriam Robert M. Pirsig


    This mediation is meant as the first of a short serie about antiquitates: good ancient things, knowledge. The central point of this is to focus on figures and ideas, or better pictures and schemas, that we have in our heads. This Pantheon is something we never speak about but is central in our approach to problems.

    Infact while in our past (i'm speaking of the western colture) this pantheon were very homogeneous (geographically speaking but also between distinct social classes) in the current, global and postmodern world is something very variegated and fragmented and almost each one has a pantheon on his own.

    Another point of this serie will be the importance of ancient wisdom. I totally disagree with the concept of human progress. I'm not speaking, obviously, of material conditions, but I believe the deepness reacheable by human thoughts has not improved over centuries. Only elements we play with have changed. Our fathers already discussed many still actual questions, useful also for us as programmers. I start here with an example in the near past, just to be kind with you, but other meditations will go far backward in time.

    In an era while the organisation of production is even more constrained into fixed binaries, where new methodologies are put in the field to force us to act in a precomputed manner, where technologies too reorganize themselves to be impersonal, becomes even more important to focus on which immaterial bricks are worth to be collected to build the unique construction of our creativity as programmers.

    Pirsig's Chautauquas

    Pirsig's recent death pushed me to ponder again about the importance of his discourse for my life and for my Perl programming activity. Pirsig is the author of the book Zen and the Art of Motorcycle Maintenance that I read many lives ago but which never disappeared from the background of my mind. Two central concepts still remain from his book as two rocks after thousand years of erosion.


    The first one is quality. Quality, if memory deserves, was what caused the protagonist's brain short circuit as filosophy professor. The research of quality and implicitly his definition, is something central in our lives. Ok but what this can be related to Perl and to programing? Is not maintainability just an aspect of quality? Readability over a clever jumble of hacks is not just another face of this concept? And why we prefer, well we love, Perl if not for a matter of overall quality? Quality of the programmer's activity while coding, not constrained by the interpreter's laws to double sign with blood the laguage way to code. Quality of the produced code in all it's phases: imagination, drawing, realizing, improving, testing and maintaining.

    Quality is everyday something less. As the programmer hired after he told the interviewer he was able to cut ten lines of code each day. Quality is polishing the diamond.

    But quality cannot be teach. We, well you, can show some incarnation of it. You can cast some light from your own quality and draw a beautiful picture on the white wall of ignorance. You cannot show directly the source of these rays, just the projection. Why? because quality is not a place but a path, a neverending one. Is a driving tension.

    Underlying form

    The second concept is underlying form. This is crucial concept for the programmer. We solve problems. Solutions must be aware of underlying forms. Problems are occurences of the reality in the platonic world of ideas and forms and even if such abstract world does not exists, it heavily concurs in our understanding and approaching of problems.

    Without the perception of something in the background our solution can just be a mere workaround or a color patch. A valid solution to a given, complex problem, can born only from the understanding of underlying forms.

    Here the discourse becomes even more actual. We are living in the end of the firts Internet generation. Most of us have born in a totally analogic world and will die, as late as possible, in a totally different world. What about the next generation? Who knows? An anecdote, inspired by real life, can show different aproaches to the same problem.

    Generational anecdote

    Tizio and Caio are both of the first internet generation. They share the usage of computer at home. Tizio, for fun, put an entry in the file HOSTS for the Caio's preffered website pointing to

    Some hours after Caio points his browser to the preferred website and he notices a connection error. He then issues a ping to the website name and sees it strangely resolves to localhost. He wonders a bit if the provider has blocked the website so he issues an nslookup to the website domain name and he is happy to see that nslookup returns a valid public IP address. He points the browser to this address and he sees his preferred website again. So he realizes the problem must be at level of local name resolution. He opens the HOSTS file and comment the incriminated entry, adding some bad words addressed to Tizio.

    Tizio make the same funny pun in a computer shared with Sempronio, a millennial second internet generation. Sempronio notices the error then tries some other websites and they are ok. Sempronio starts thinking that something is broken within the browser and he installs another browser but, with his big disappoint, the problem persists.
    So he opens the Bag Of All Answers website and searches for "preferred_website blocked" and he discovers a plethora of causes that can make a website to be blocked. He reads superficially a bunch of articles without invastigating why governments block websites. After three minutes he modifies the search: "preferred_website blocked solution" and he happily discovers that some software can circumvent the problem.
    So he installs a program named after the sligthly modified name of an ancient god, let say Marz. Sempronio does not know but this geeky program uses it's own nameservers and redistributes web requests over it's own network in a peer2peer way, Sempronio just complains it's a bit slow but finally the preferred website shows correctly again in the browser.
    So for him it is a happy end (not saying that an international agency intercepts all Marz's traffic and programtically breaks all computers using it, but this is whole another story..).

    With the above i dont mean all young people are stupid and all older ones are wise and spot everytime the rigth solution. I dont mean this at all. Just I want to highlight that if you know the underlying form of a web request probably you'll arrive to correct conclusions if experiencing some weird browsing behaviour.


    Quoting from Pirsig's book: Although motorcycle riding is romantic, motorcycle maintenance is purely classic. Author's work is full of examples of what he called classical and romantic types. I think such dichotomy is even too much stressed. I'm more in favor of the Humanistic Being, even as programmer. I dont want to be just another thooth in the gear not even knowing if I'm part of a clock or of a motorcycle. Knowing the big picture and to perceive underlying forms can make us better programmers.
    An old book by a philosofy professor is worth to read, probably even better to have in the books shelf than an aseptic manual of programing methodology.

    Roma 2770 AB URBE CONDITA / 8644 September 1993


    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.
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 drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2017-11-19 18:11 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (282 votes). Check out past polls.