Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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
print unicode characters from hex format
3 direct replies — Read more / Contribute
by sistermaryguacamole
on Aug 31, 2016 at 16:38
    Greetings,

    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
1 direct reply — 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] com.day.cq.reporting +.impl.snapshots.SnapshotServiceImpl Error accessing repository during + creation of report snapshot data javax.jcr.LoginException: Cannot derive user name for bundle com.day.c +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 (https://regex101.com/r/eB7cR3/1) 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 foo.pl 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 ./data_sort.pl 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 ** }

    Thanks,

    Nick

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 5.24.0.1-32bit
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/DefaultPort.pm 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-5.24.0.1-32bit-PDL\perl\bin\perl.exe Makefile.PL +-- OK Running make for B/BB/BBIRTH/Win32-SerialPort-0.22.tar.gz cp lib/Win32/SerialPort.pm blib\lib\Win32\SerialPort.pm cp lib/Win32API/CommPort.pm blib\lib\Win32API\CommPort.pm BBIRTH/Win32-SerialPort-0.22.tar.gz C:\strawberry-perl-5.24.0.1-32bit-PDL\c\bin\dmake.exe -- OK Running make test "C:\strawberry-perl-5.24.0.1-32bit-PDL\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-5.24.0.1-32bit-PDL\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>
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.

    Cheers,

    -stevieb

    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

    What

    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.

    Why

    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.

    How

    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.

    Status

    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
      $r->get('/login')->to('MyApp#https_redirect');
    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.

    http://act.yapc.eu/lpw2016/ 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

    Greetings,
    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?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2016-08-31 23:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The best thing I ever won in a lottery was:















    Results (437 votes). Check out past polls.