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

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
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!

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'?
Win32::SerialPort install error on Strawberry Perl PDL
1 direct reply — Read more / Contribute
by derneue
on Aug 26, 2016 at 02:35
    Hi Monks, does anybody knows if Win32::SerialPort works with Win7x64 and the Perl Version noted in the title? I receive the following error after fetching from CPAN:
    Creating new t/ Creating new nomake_test Creating new nomake_install Checking if your kit is complete... Looks good Generating a dmake-style Makefile Writing Makefile for Win32::SerialPort Writing MYMETA.yml and MYMETA.json BBIRTH/Win32-SerialPort-0.22.tar.gz C:\strawberry-perl-\perl\bin\perl.exe Makefile.PL +-- OK Running make for B/BB/BBIRTH/Win32-SerialPort-0.22.tar.gz cp lib/Win32/ blib\lib\Win32\ cp lib/Win32API/ blib\lib\Win32API\ BBIRTH/Win32-SerialPort-0.22.tar.gz C:\strawberry-perl-\c\bin\dmake.exe -- OK Running make test "C:\strawberry-perl-\perl\bin\perl.exe" "-MExtUtils: +:Command::MM" "-MTest::Harness " "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib\lib', 'b +lib\arch')" t/*.t t/test1.t .. 1/309 # Failed test at t/test1.t line 534. t/test1.t .. 305/309 # Looks like you failed 1 test of 309. t/test1.t .. Dubious, test returned 1 (wstat 256, 0x100) Failed 1/309 subtests t/test2.t .. ok t/test3.t .. ok t/test4.t .. ok t/test5.t .. ok t/test6.t .. 1/? SetCommState failed at t/test6.t line 306. t/test6.t .. ok t/test7.t .. ok Test Summary Report ------------------- t/test1.t (Wstat: 256 Tests: 309 Failed: 1) Failed test: 195 Non-zero exit status: 1 Files=7, Tests=1808, 62 wallclock secs ( 0.11 usr + 0.22 sys = 0.33 +CPU) Result: FAIL Failed 1/7 test programs. 1/1808 subtests failed. dmake.exe: Error code 255, while making 'test_dynamic' BBIRTH/Win32-SerialPort-0.22.tar.gz C:\strawberry-perl-\c\bin\dmake.exe test -- NOT OK //hint// to see the cpan-testers results for installing this module, t +ry: reports BBIRTH/Win32-SerialPort-0.22.tar.gz Stopping: 'install' failed for 'Win32::SerialPort'. Failed during this command: BBIRTH/Win32-SerialPort-0.22.tar.gz : make_test NO cpan>
Code rendering issue with specific vars in MetaCPAN POD
2 direct replies — Read more / Contribute
by stevieb
on Aug 25, 2016 at 13:46

    I've found an interesting issue with POD rendering on MetaCPAN.

    I have the following snippet in the POD for one of my modules:

    =head2 send_cmd($command) Sends any arbitrary command to the LCD. (I've never tested this!). Parameters: $command Mandatory: A command to submit to the LCD. =head2 position($x, $y) Moves the cursor to the specified position on the LCD display. Parameters: $x Mandatory: Column position. C<0> is the left-most edge. $y Mandatory: Row position. C<0> is the top row.

    The $x and $y variables don't show up. The code block for them does, but the variables don't. Things work as expected for the $command variable in the send_cmd(), as it shows up fine. You can see that here.

    It works with Pod::Readme:

    position($x, $y) Moves the cursor to the specified position on the LCD display. Parameters: $x Mandatory: Column position. 0 is the left-most edge. $y Mandatory: Row position. 0 is the top row.

    ...and even in view source on meta:

    <h2 id="position-x-y">position($x, $y)</h2> <p>Moves the cursor to the specified position on the LCD display.</p> <p>Parameters:</p> <pre><code> $x</code></pre> <p>Mandatory: Column position. <code>0</code> is the left-most edge.</ +p> <pre><code> $y</code></pre> <p>Mandatory: Row position. <code>0</code> is the top row.</p>

    ...but doesn't render properly in any browser I've tested with.

    I'm wondering if I should just work around this, or whether this is a known issue (I couldn't find anything by searching), and if it's worth taking up the chain or not (perhaps other specific vars don't render correctly either).

    Can anyone please let me know if they are seeing what I am?

Printing an element of a list not an array
4 direct replies — Read more / Contribute
by raghuprasad241
on Aug 25, 2016 at 11:13
    GMAN all,

    GMAN (Good Morning, Afternoon, Night) depending on where you are :-)

    Is it possible to print individual elements of a list with out putting them into an array ? I think putting the list into an array is a wastage of memory if you are just trying to print it. For e.g. I am trying to do below with no success

    perl -e 'use v5.10; say (localtime)[1]' syntax error at -e line 1, near ")[" Execution of -e aborted due to compilation errors.

    Am I missing something simple ?

    A Monk!
Check multiple array elements for a single condition
5 direct replies — Read more / Contribute
by Anonymous Monk
on Aug 25, 2016 at 06:38

    Just a quick question - is there a shorthand form of this:

    if ($array[0] == 0 && $array[1] == 0)

    A statement that would check both elements [0] and 1 for the condition ==0 without having to repeat the statement?

howto parse (or determining end) of a line of perl
5 direct replies — Read more / Contribute
by perl-diddler
on Aug 24, 2016 at 20:26
    I have a little calc I wrote in perl that really just provides and eval & print loop for the user.

    I have made changes over the years, but one of the things that has always bothered me is, if I want to add a complex expression -- anything that is multi-lined, how to get my input loop to know when it needs more input OR when it doesn't (vs. _could_ take more input).

    My 'semi-model' for that would be something like bash, where if you type 'the beginning of a control structure, bash will change to a different prompt to indicate it wants more input.

    How might I do the same in my eval/print loop?

    As it is now, I can define functions on 1 line, for example, but there is no easy way to extend that to more than one line.

    I could force the use of an 'extend char', like backslash at the end of line -- but in bash, those are only needed if it is ambiguous -- i.e. if the line is already well formed, you need to enter '\' to tell bash to keep parsing. Ex. (using 'home>' as normal prompt):

    home> int a=1+1\ > +2; echo $a 4
    You can't enter partial *expressions* in bash and have it "auto continue" (that I know of). I.e.
    home> a=1+<cr> -bash: 1+: syntax error: operand expected (error token is "+")
    But I could enter a '\' at the end of line and continue it as I did above.

    Where bash works to auto-detect is in its control structures (or like if a quote is still open). Ex:

    home> for ((i=0;i<10;++i)); then<cr> > [...]
    On the 2nd line, it doesn't display the normal prompt, but a single greater than sign. How could I get my input/eval loop to get feedback from perl that I'm in the middle of a similar structure and change the prompt and not try to eval it?


    Clarification: how can I do that w/o writing an entire perl parser? ;-)

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
No replies — Read more | Post response
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 meditating upon the Monastery: (8)
As of 2016-08-29 21:07 GMT
Find Nodes?
    Voting Booth?
    The best thing I ever won in a lottery was:

    Results (409 votes). Check out past polls.