Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

The Monastery Gates

by gods
on Mar 23, 1999 at 10:47 UTC ( #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
Formalizing an array type problem, looking for solution
2 direct replies — Read more / Contribute
by melmoth
on Aug 31, 2016 at 20:08

    An array of hashes, each hash containing one path, its ID, and its order ( foreward (F) or reverse (R) )

    each path is initialized in the F position

    my @paths = [ { id => 1, path => [A,B], order => 'F' }, { id => 2, pat +h => [C,D,E], order => 'F' }, { id => 3, path => [E,B], order => 'F' +} ];

    each node or vertex of each path also has an orientation ( + or - )

    my %plus_minus; $plus_minus{1}{A} = '+'; $plus_minus{1}{B} = '+'; $plus_minus{2}{C} = '+'; $plus_minus{2}{D} = '-'; $plus_minus{2}{E} = '-'; $plus_minus{3}{E} = '-'; $plus_minus{3}{B} = '-';

    You can reverse the order of a path ( e.g., A, B to B, A )

    When you reverse order from F => R or R => F you also switch the orientation of each node in the path from + to - or - to +

    The paths with orientations look like this:

    1 .A+ : B+

    2. C+ : D- : E-

    3. E- : B-

    this is the problem input for output, i'd like to know whether or not it is possible by reverseing path orders to create a consensus path and also what is the way to do this such that you are guaranteed to find the consensus path

    for example, if we reversed path 1 we'd get:

    1. B- : A-

    2. C+ : D- : E-

    3. E- : B-

    and the resulting consensus path would be:

    C+ : D- : E- : B- : A-

    but it's not clear to reverse path 1 first; for example; what if started by reversing path 3? So you can't proceed randomly. Does anyone recognize this problem? Does it have a solution? Thanks.

print unicode characters from hex format
3 direct replies — Read more / Contribute
by sistermaryguacamole
on Aug 31, 2016 at 16:38

    I have what I thought would be a simple issue. I'm reading a YAML file full of user names, email, phone, etc. Many are French-Canadian, and have accented characters. In the file I'm reading, it looks like:

    jean-fran\xe7ois chr\xe9tien

    I know that \xe7 is "", and \xe9 is "", etc., but it prints to the terminal as just \xe7, \xe9.

    I've looked up all sorts of stuff: use utf8; use Encode; binmode(STDOUT, ":utf8"), blah blah blah.

    I just want to print the stupid messed up characters the way they're supposed to look; for the love of God, please, help me.

    (The next step, of course, is to forbid our French-Canadian employees to use ridiculous non-english characters when creating user accounts - but one thing at a time).

    Regards & God Bless,

    Sister Mary Guacamole

regex with /s modifier does not provide the expected result
2 direct replies — Read more / Contribute
by hunagyp
on Aug 31, 2016 at 10:02
    Hi Monks, I've the following code snippet:
    sub splitLine { my $line = shift; my $pattern = shift; # by default, it is "ERROR" my %header; # DD.MM.YYYY HH:MM:SEC USEC + ERROR/WARN [pool-def] class-name msg my $sPattern = '(\d{2}.\d{2}.\d{4}).*?(\d{2}:\d{2}:\d{2}).\d{0,3}. +*?\*(' . $pattern . ')\*.*?(\[.*?\]).(.*?\..*?\s+?)(.*)'; if ($line =~ /$sPattern/s) { my $ts = parseLogEntryTimeStamp($1, $2); %header = ( 'timestamp' => $ts, 'date' => $1, 'time' => $2, 'severity' => $3, 'thread' => $4, 'class' => $5, 'msg' => $6); print "$7 \n"; #doTrace %header; } return %header; }
    The example input PARAM ($line) for this is:
    30.08.2016 08:00:00.004 *ERROR* [pool-7-thread-5] +.impl.snapshots.SnapshotServiceImpl Error accessing repository during + creation of report snapshot data javax.jcr.LoginException: Cannot derive user name for bundle +q.cq-reporting [313] and sub service null
    My goal is: cut into meaningful pieces this example text. My regex above works almost fine, except the last capture group. In perl, the last capture group only gives back this: 'Error accessing repository during creation of report snapshot data' In an online tester ( with the /s modifier, the last capture group gives back everything until the last char. Does anyone have any idea, why perl does not do the same? (or can you suggest another approach on this regex? It might be quite "messy" :D) Thanks a lot in advance for any advice!
How to get a better error message from LWP::UserAgent on missing SSL certificates?
4 direct replies — Read more / Contribute
by moritz
on Aug 31, 2016 at 05:45

    I just spent several hours debugging some code using LWP::UserAgent. The code could be reduced to this:

    use strict; use warnings; use LWP::UserAgent; my $URL = 'https://myhost.local/'; my $ua = LWP::UserAgent->new; $ua->ssl_opts( verify_hostname => 0 ); my $response = $ua->get($URL); if ($response->is_success) { print $response->decoded_content; # or whatever } else { die $response->status_line; } <code> <p>So pretty much a copy&paste from the LWP::UserAgent docs.</p> <p>The error message I got was:</p> <code> Can't connect to myhost.local:443\n\n 500 Can't connect to myhost.local:443 at line 15.

    After some debugging, strace finally showed me an ENOENT for an SSL CA file, which nudged me into the right direction.

    So, my questions are:

    • Why does a missing CA file cause the request to fail, even though I've used ua->ssl_opts( verify_hostname => 0 );?
    • What do I have to do to get a better error message out of LWP::UserAgent? Is this a bug in LWP::UserAgent?

    This is on a Debian Jessie box with perl 5.20.2, and LWP::UserAgent 6.06.

How to stuff space separated column into Hash
4 direct replies — Read more / Contribute
by dirtdog
on Aug 29, 2016 at 14:22

    Hi Monks

    I'm having a very hard time trying to get some results from a sql statement using WriteExcel module into a Hash.

    The results from my sql statement yield 2 columns: Client is column 1 and Month followed by total orders for that month as column 2

    for example,

    Client|Counts by Month

    IBM | February 1 March 5 July 4

    Oracle| January 3 March 4 April 6 May 5

    RedHat | March 2 June 3 August 1

    The first result would be in @row so @row[0] would be equal to IBM and @row1 would be equal to 'February 1 March 5 July 4'.

    Somehow I need to split the values of @row1 into a hash so the Key->value pair would be February->1, March->5, July->4, but that is where I'm getting stuck.

    Any help would be greatly appreciated!

pdf libraries for Strawberry Perl
3 direct replies — Read more / Contribute
by Dr. D
on Aug 29, 2016 at 14:18
    Hello, I'm using Strawberry Perl v.5.10.0 under 64-bit Windows Server 2008 R2. I wrote a script which generates some output, and my goal is to generate a pdf file. I tried to install different CPAN libraries, but they all have same issue - they require NMake utility. It used to be available from Microsoft, but no longer is. I did extensive search but couldn't find a single place where I could download it from. Please help. How can I use pdf format in my script. Thank you!
Reading Excel with different format
1 direct reply — Read more / Contribute
by 9mohit2
on Aug 29, 2016 at 08:16
Archive::Extract - error handling
2 direct replies — Read more / Contribute
by luxs
on Aug 28, 2016 at 21:21
    I'm using Archive::Extract, as in the original example.
    use Archive::Extract; my $ae = Archive::Extract->new( archive => 'myfile.tgz' ); my $ok = $ae->extract or die $ae->error;
    And the file myfile.tgz is broken. This code produce error on the screen
    Unable to extract 'myfile.tgz': at ./ line 156.
    and continue to execute the further code, but it should die!!! What was wrong? How to catch this error?
Feedback for programming a UI in Perl
2 direct replies — Read more / Contribute
by stevieb
on Aug 28, 2016 at 19:52

    I'm looking for recommendations on which UI platform to use under Perl.

    As someone who has developed or used Perl-based User Interfaces, please share your experiences with what you have found.

    Feedback on all aspects welcome... integration, ease-of-coding, ease of use, look, feel, documentation, availability of help/guidance here at PM or external etc.

    I'm looking at writing small, short and simple GUI apps that'll be on touch-screens to control events and situations with button pushes. Ease of configuration of text, grey-out, displaying small images etc is what I'm looking for.

    After you have an opinion, answer this...

    What led you to choose what you're using?

Embedded function or subroutine - which is better?
4 direct replies — Read more / Contribute
by Linicks
on Aug 27, 2016 at 12:51

    Hi All

    I don't know how perl pre-parses code on the fly - is it quicker (i.e. will perl map out a call to a sub-routine on pre-parse) such as

    sudo code if ($debug == "true") { &debugit; # call the routine } or if ($debug == "true") { ** do all the debug code here and/or carry on ** }



Using unpack on Windows with external data
2 direct replies — Read more / Contribute
by locinus
on Aug 27, 2016 at 07:33

    Hi monks.

    I'm new using unpack function to get data from an external binary source. I'm having trouble getting the right values.

    My first value is coded as an unsigned 16-bit integer, little-endian. When I open it with my hex editor, I can see that the two first bytes are coded "DC 20", which represents 8412, which is the value I expect.

    My perl code is the following:

    my $fh = FileHandle->new; open ($fh, '<', $filename) or die 'missing file'; binmode $fh, ':raw'; my @values = unpack 'S<', $fh; print @values;

    and provides the value 26950. I really can't figure out where this data comes from. Same if I provide '<:raw' to the open function.

    I'm running on Windows 7 64-bit, Perl 5.12.3.

    Any idea/suggestion? I'm clueless right now.

How do I replace the camel icon on Windows exe built with pp?
2 direct replies — Read more / Contribute
by perltux
on Aug 27, 2016 at 05:52
    I use 'pp' to build self-contained exe files of my graphical (Tk) Perl applications for MS Windows. The icons in the task bar and in the top left corner of the application window show up correctly when setting them with $mw->iconimage($icon), but on the desktop and in the windows file browser I still get the default camel icon.

    In the past 'pp' supported the '--icon' switch which allowed to specify a custom icon, but recent versions of 'pp' no longer support that switch.

    So how do I replace this camel icon with my own custom icon with recent versions of 'pp'?
New Meditations
My appreciation for PerlMonks
1 direct reply — Read more / Contribute
by stevieb
on Aug 26, 2016 at 20:13

    I started my foray into Perl in ~2001 when I started my job as a network engineer at an ISP. I had never heard of Perl before that. The predecessor that I took over for had written (looking back) a really shitty, redundant "application" to do the management of clients in what some might say is Perl 4 code.

    I quickly realised that automating most of the sysadmin duties out of the way so I could engineer my core network peering via BGP was critical. I picked up a "Learn Perl in 21 Days" book off of a shelf, and practised everything in it. Two-arg open it had, and no mention of strict, my or anything. I mastered the simplicity of that book in about four days.

    I quickly grew fond of Perl, writing up scripts that automated basic things, as to rid myself of sysadmin duties so I could focus on what I loved; networking.

    Wasn't long before I found PerlMonks, and for eight years, I lingered around as an observer. Why I didn't join, I'll never know. Over time, I did start taking part in the newsgroups and email lists, then one day in 2009, I either saw a question that I could answer, or had a question... I can't remember. (I had been an active member in many other forums, particularly cisco-nsp, NANOG, and numerous FreeBSD lists).

    In retrospect, of course, I should have joined earlier, but I didn't. Not long after I joined was the whole hack fiasco. I stuck with it. I started answering questions that I could to give back. I absorbed the criticism given to me in my mistakes, which was crucially valuable in how I approach things today.

    Due to the people of PM, and the culture of PM itself, I believe that I am a more genuine person online, am willing to admit mistakes everywhere, willing to correct others (politely), and willing to apologize when I've been an asshole.

    To me, Perlmonks is a place where we can learn, have fun, get angry at each other, but at the end of the day, we're all here for one reason... to help the newb while helping each other.

    No matter how much one knows, there's always more to learn.

    Thanks to all those here (way too many valuable people to mention personally), the p5p team, the pumpking (SawyerX at time of writing, took over for Ricardo Signes in the not-so-distant past), Larry, and everyone else who has had any part in aiding and abetting the Perl community by answering questions, writing distributions, writing books (special shout out to merlyn) or just throwing their two cents in.



    ps. Back when, I'd claim myself as "not a programmer". Although I still am "not a programmer", looking back, the most memorable aspects of my technical career are the CPAN contributions I've made, and the work I've done to further the progress of Perl programmers, old and new.

    pss. This post isn't perl5 specific; love goes out to the perl6 crew all the same ;)

New Cool Uses for Perl
Battleship solitaire puzzle generator
1 direct reply — Read more / Contribute
by toolic
on Aug 29, 2016 at 15:11


    This is a battleship solitaire puzzle generator. It creates a puzzle grid with a random number of clues. It also can display the corresponding puzzle solution. The solution has 10 ships on a 10x10 grid.


    Mostly because I felt like it. Also because I could not find anything that already existed online to easily do exactly what I wanted. There are some puzzle generators available which have GUI's with nice features, but they limit you to one puzzle per week (or month, or whatever), and it is difficult to annotate hard puzzles on the screen. This generator allows you to play as many puzzles as you want and to print them on paper to make annotations.


    Run the generator and redirect the output to a file. You can edit the file and fill in the ships directly in your editor. Or, you can print the file onto a piece of paper. Alternately, you could redirect the CSV output to a file, then use the conversion script to create an Excel file. Then you can complete the puzzle in Excel or print the Excel file onto paper.


    Consider this alpha code. Since I did not create any tests to automatically check the code, there are likely bugs. The approach is probably naive, and the ASCII representation is ugly. Any suggestions for improvements are welcome.

    Code for generator

    Code for Excel conversion

redirecting Molicious app to https
No replies — Read more | Post response
by Ea
on Aug 25, 2016 at 10:03
    (Quick post)

    Searched the fine web and didn't find a quick answer to how to redirect an http request to https in Mojolicious. I wanted to insure that logins were always secure. Finally cobbled together a solution and thought I should share and maybe get some improvements.

    1. Run 2 webservers: one to handle http and the other to handle https, which for me is two incantations of hypnotoad
    2. Add a route in your http App
    3. Add a sub to the http Controller
      sub https_redirect { my $self = shift; my $secure = $self->req->url->to_abs->scheme('https')->port(443); $self->redirect_to($secure); }
    4. Profit!

    All the sub does is redirect the request to the new protocol at the same url. I've seen a method in the docs to a is_secure method which could be useful somewhere. Also, I tried using $r->any('/login'), but it doesn't work for me and I'm moving on.

    Yes, I probably could've gotten a better answer inside 2 minutes on IRC (people are so very helpful), but it never occurs to me until afterwards.

    Sometimes I can think of 6 impossible LDAP attributes before breakfast. It's that time of year again!

New Monk Discussion
Who stole Perl News?
1 direct reply — Read more / Contribute
by Athanasius
on Aug 27, 2016 at 03:27

    The Perl News section appears to have disappeared! Yes, that link takes you to a page for adding a news item, but all the actual items appear to be missing.

    For example, I have twice posted items to Perl News:

    1. [id://1097781] Project Euler Returns (2014-08-18)
    2. [id://1151268] Strawberry Perl 5.22.1 released (2015-12-29)

    — but now the Search button can’t find them by their node IDs, and Super Search can’t find them by their titles. :-(

    I mean, sure, I know that “no news is good news,” but still...

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

How was perlmonks built?
2 direct replies — Read more / Contribute
by QuillMeantTen
on Aug 25, 2016 at 10:02

    I am wondering, does perlmonks use an existing framework? How has its architecture been decided? What are the design principles that are still applied to this day and been there since its inception?

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 about the Monastery: (6)
As of 2016-09-01 06:38 GMT
Find Nodes?
    Voting Booth?

    No recent polls found