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


( #480=superdoc: print w/ replies, xml ) Need Help??

If you've discovered something amazing about Perl that you just need to share with everyone, this is the right place.

This section is also used for non-question discussions about Perl, and for any discussions that are not specifically programming related. For example, if you want to share or discuss opinions on hacker culture, the job market, or Perl 6 development, this is the place. (Note, however, that discussions about the PerlMonks web site belong in PerlMonks Discussion.)

Meditations is sometimes used as a sounding-board — a place to post initial drafts of perl tutorials, code modules, book reviews, articles, quizzes, etc. — so that the author can benefit from the collective insight of the monks before publishing the finished item to its proper place (be it Tutorials, Cool Uses for Perl, Reviews, or whatever). If you do this, it is generally considered appropriate to prefix your node title with "RFC:" (for "request for comments").

User Meditations
What 'should' a professional PERL programmer know?
7 direct replies — Read more / Contribute
by perloHolic()
on Jan 09, 2015 at 07:08

    Hello fellow monks and monkesses.

    I am very new to the monastary as far as being a member goes, however have been a frequent part of the 'flock' if you like, for some time.

    My meditation today comes from my recent personal experience of applying for a proffessional role as a PERL programmer - which leads to my pondering, 'what do i have to know/should know in order to be qualified for such a position'? I have read many articles before such as Professional perl which are obviously inciteful in this area.

    I am really looking for specifics such as a minimum amount of required knowledge in certain areas such as OO Perl, or Database management with Perl, Optimisation, Threads or Web programming in Perl etc. I have only self tought knowledge of PERL, and of course with helpful textbooks, tutorials and articles in the monastary have grown this knowledge over time. I don't however, have any professional experience of PERL per say, other than small scripts I have written for my current job as a C language software Engineer.

    SO - I do have a relatively small amount of knowledge in some areas in comparison to, lets say, what I would class as the contrastingly very experienced monks around here, whom provide a vast array of knowledge in most if not all 'Areas' of PERL. I have yet to receive any feedback from my recent application, however 'I' feel like I may be underqualified. It would be very helpful if my fellow peers may be able to offer some incite into 'what the minimum requirements' may be for such a junior PERL programmer role.

    Apologies in advance if my question is unhelpful,in the wrong place, poorly titled or worded.

    Your ever faithfull functioning perloHolic.

RAM: It isn't free . . .
9 direct replies — Read more / Contribute
by sundialsvc4
on Jan 07, 2015 at 11:49

    In the earliest days of digital computing, memory was the most-scarce resource.   (After all, magnetic doughnuts could be made only so small, and they had to be strung upon three tiny wires by hand.)   Thus, when external storage devices – disk and tape and drum – were developed, they were referred to as “mass” storage.   Most of us remember the bad old days, of MS-DOS and even earlier, when programs had to be separated into “overlays” in order to be made to fit into the one-and-only place from which instructions could be executed.

    Well, fast-forward a few decades and “chips are cheap” now.   Gigabytes if not terabytes of semiconductor storage can fit into a space the size of a pencil eraser.   CPU architectures are especially designed to allow gigabytes of storage to be directly addressed.   Developers are eagerly taking advantage of this, because the days of “overlays” and then “virtual memory” (i.e. “paging”) appear to be long-ago and far-away.   After all, RAM has the unique advantage of being instantaneous.   If the data is available in RAM, disk-I/O does not occur.   (And, if the “disk” storage device is made of semiconductors, at least the “seek latency” and “rotational latency” does not happen, even though most semiconductor devices do have a certain form of “latency” of their own.)

    There is a fly in that ointment, however.   RAM capacity is not yet so enormous that concerns about virtual memory can be dismissed outright, especially in production situations where many possibly memory-hungry applications are running on the same box at the same time.   Virtual memory is still with us, and therefore we must be mindful of how to work “with” it and not “against” it, just as we were very-obliged to do in the 1970’s.

    When virtual memory is being used, “in-memory” data structures might involve disk I/O.   As you know, physical RAM is divided into equal-sized chunks called “pages,” and each page might be “resident” in memory or it might be “swapped out.”   When any virtual address is touched, a “page fault” might occur, and if so the process will be delayed until the necessary disk-I/O has been completed.   (And, in order to make room for the page, another page might have to be “stolen” from someone and written out to disk … thus, two or more disk-I/O’s must take place before the faulting process is allowed to proceed.)

    Virtual memory’s success relies upon the assumption that, while page-faults will occur, they will not occur so frequently that the disk-I/O delays add up too much in practice.   The term is “locality of reference,” and it means that programs typically make memory-references in very concentrated groups.   Once a page-fault is satisfied, things should settle-down for a while as the processes continue to refer, again and again, to the page(s) that have most recently been faulted-in.   “Least Recently Used (LRU)” pages, by comparison, are presumed to be good candidates for page-stealing.   The total set of pages that any process requires in order to run without delay, at any instant in time, is referred to as its current “working set” at that instant.

    There is, unfortunately, one data-structure mechanism in particular that flies in the face of “locality of reference,” and therefore of “small and tidy and predictable working-sets.”   That mechanism is:   the hash table.   Perl’s “hashref.”

    Hash tables work by permuting a key across some smaller key-space in order to arrive at a single “bucket” that is searched for the target value.   Hash functions are designed to spread the key values more or less uniformly, but randomly, across the key space.   Thus, the hash structure itself can represent a large working-set (although hash algorithm designers, including Perl’s, do seek to constrain this).   But in any case, the hash buckets also refer, by reference, to outside blocks of memory that are obtained using memory allocation functions e.g. “malloc().”   The memory addresses pointed-to by the (already, large) hash table will, over time, become quite-widely distributed.   And so we have a “very random-access” data structure:   a large hash-table referencing an even larger set of memory blocks whose individual addresses are not predictable.   (A highly volatile very-active data structure becomes less and less predictable as the hours and days go by.   Working-set sizes increase quickly.)

    (Perl’s designers know their stuff.   They know about these issues and carefully designed an industrial-strength system for all of us to enjoy.   We are well cared-for ... but the issues are still there, and, by definition, always will be.)

    Working-set sizes become very large, then.   So, what actually happens when such an application enters service in a production machine that’s using virtual memory?   Unfortunately, it becomes a million-pound elephant … using, shall we say, far more than its fair share of RAM.   A disproportionately large amount relative to the others.   And therefore, both a source of virtual-memory pressure and(!) an especially vulnerable victim of it.   If such a program is to run efficiently (as it was specifically designed to do), it must have “all that RAM.”   But, if it gets what it wants (and must have), the other processes can’t get (and keep) theirs.   Paging activity begins to increase, as does the number of processes that are stuck in page-wait and the frequency that each process is stuck in page-wait.   At a certain point, the processing grinds to a halt.   It “hits the wall.”   It is “thrashing.”   The offending application is especially taking it in the shorts ... being especially big and especially vulnerable, it is “punch-drunk.”   But it’s not the only one.   (If there were any subtle timing-related bugs in this or any other application, this is the time when those kinds of problems will really start to show up.)

    Given that, in a virtual memory setting, any “memory” reference can result in “disk” I/O, “memory” must in fact be treated as a “disk.”   Each memory-access, especially any access that might be widely-dispersed from other recent ones, must be considered as possibly taking several milliseconds to occur; not the microseconds or nanoseconds that are usually bantered-about by programmers who like to use the “time” command and discuss the third or fourth digit to the right of the decimal point.

    Software developers usually don’t experience these things personally when designing their software:   their systems are the biggest, fastest, and especially the fattest of all.   They’ve got two or three large monitors.   Multiple processors.   Gigs of RAM.   As much as the motherboard will support.   In short, a situation altogether unlike the rack mounted boxes where their brainchildren will labor out their appointed business duties.

    To run well, and to do so round-the-clock for days and weeks on end, all applications must be good virtual-memory citizens.   Whether their virtual memory allocations be large or small, their working-set sizes must be small … by design.   There are many possible ways to do that:   storing multiple entries in a single large structure rather than in many small ones; “batching” requests for even in-memory data stores; and, using disk-I/O directly instead of implicitly (as virtual-memory actually does).   All operating systems buffer disk-I/O operations, filling all available RAM with buffers but managing those buffers differently than they do VM page-frames.

    Probably the very worst thing that can happen to your program’s design is for it to be very splendid on your machine, but unworkable in production … or even, “a pain in the asterisk in production.”   This requires thinking of RAM as being “a thing that is not without-delay,” from the very earliest stages of your designs.

    HTH …

Dating .tar Archives
1 direct reply — Read more / Contribute
by oiskuu
on Dec 30, 2014 at 13:32

    Presenting two ways to skim tar format files: via direct parsing and using the specific module.

    The file date of an archive is useful to keep around for chronological listings, or determining its age at a glance. It is however often times lost as the files get downloaded, copied or moved. An obvious fix is to reset the date to that of the most recent member contained within. And a script to this end is what I implemented, years ago. If there is or was a proper tool for that already, I wouldn't know.

    But old TODOs came to my attention again recently. What better time to clean up some old code, perl-based and all? In particular, there was this bit to decompress the files with an external utility:

    ... ? ... : $file =~ /bz2$/i ? open($fh, '-|', 'bzcat', '--', $file) : open($fh, '<', $file);
    DOS-like logic, based on file suffix? Very un-unix and un-cool. IO::Uncompress::AnyUncompress to the rescue!

    Minutes later, there it is — the version II — shorter and neater by a fair bit.

    Hacking on them tar headers is entertaining for sure, but let's try Archive::Tar now — a module purpose-built for tasks like that. And behold: the version III.

    #! /usr/bin/perl # Usage: $0 [-z] [-n] files ... # -z also check gzip archive time # -n don't actually touch, show what would be done use Getopt::Std; getopts('zn', \my %opt); use List::Util q(max); use IO::Uncompress::AnyUncompress; use Archive::Tar; $Archive::Tar::WARN = 0; foreach (grep -f, @ARGV) { my $fh = new IO::Uncompress::AnyUncompress($_) or next; my $zt = $opt{z} && ($fh->getHeaderInfo||{})->{Time} || 0; my $tt = max map $_->{mtime}, Archive::Tar->list_archive($fh, +0, [q(mtime)]); my $t = max $zt, $tt; $t && ($t != (stat)[9]) && ($opt{n} || utime($t, $t, $_)) && printf "%-60s %s (%s)\n", $_, scalar localtime($t), ($t == $tt) ? q(tar time) : q(zip time); }
    One-third of the previous size! Cut loose the reporting, the gzip-time foo, and we'd arrive at a one-liner territory. But this brevity has some gotchas. Let's see:
    • Lots of memory is consumed reading big archives. Apparently list_archive method reads the uncompressed data in full. Is there no "metadata-only" flag one could peruse?
    • Another thing, list_archive has special cased the [q(name)] to return a flat list instead of hashes. Why not support both [qw(...)] and q(item) requests? Then one might simply write:
      my $t = max Archive::Tar->list_archive($file, 1, "mtime");
    • The lzma/xz modules need to be installed separately for those to work. Release 5.20.1 does not (yet?) include them.

    Giving it a second glance, the original script seems to do fine as it was. Some TODOs may stay a while longer, I think.

win32 exit code after a crash guide
2 direct replies — Read more / Contribute
by bulk88
on Dec 28, 2014 at 22:25
    Windows Perl doesn't have SIGSEGV or SIGILL or SIGBUS. This makes diagnosing a non-local crashed process very difficult. For example, on one of those CPANTesters boxes, you see
    t/middleware/connect.t ....... Dubious, test returned 5 (wstat 1280, 0x500) All 1 subtests passed Free to wrong pool 2e8aa90 not 6c4040 at C:/strawberry-perl- +erl/site/lib/AnyEvent/ line 1083, <> line 6. t/middleware/loadbalancer.t .. Dubious, test returned 5 (wstat 1280, 0x500) No subtests run Free to wrong pool 2e145e0 not 34f90 at C:/strawberry-perl- +rl/site/lib/AnyEvent/ line 1083, <> line 6. t/middleware/rewrite.t ....... Dubious, test returned 5 (wstat 1280, 0x500) No subtests run
    What on earth is 0x500? If you do the perl on Unix routine of 0x500 >> 8, you get 5. What is 5?

    Referring to errno.h
    #define EIO 5
    C:\perl521\bin>perl -E"$! = 5; say $!" Input/output error
    If I didn't tell you it is already is a crash, you would have thought the perl app did "exit($!);".

    The answer is, the bytes selected by the mask 0xFF00, after the child crashed, are truncated NTSTATUS codes AKA EXCEPTION_* codes. I wrote a test script which shows what all the common Win32 crashes look like.
    C:\perl521\srcnewb4opt>perl -Ilib disable_interrupts $? 9600 CHILD_ERROR_NATIVE 9600 illegal_instruction $? 1d00 CHILD_ERROR_NATIVE 1d00 deref_null $? 500 CHILD_ERROR_NATIVE 500 deref_neg1 $? 500 CHILD_ERROR_NATIVE 500 write_to_ro_mem $? 500 CHILD_ERROR_NATIVE 500 div_by_0 $? 9400 CHILD_ERROR_NATIVE 9400 call_c_debugger $? 300 CHILD_ERROR_NATIVE 300 C:\perl521\srcnewb4opt>
    0x96 = 0xC0000096 STATUS_PRIVILEGED_INSTRUCTION, valid machine op, but only allowed in kernel mode, not user mode

    0x1D = 0xC000001D STATUS_ILLEGAL_INSTRUCTION, this machine op doesn't exist on this CPU, you are probably trying to execute data pointer/garbage as a C function, without DEP

    0x5 = 0xC0000005 STATUS_ACCESS_VIOLATION, SEGV, bad address


    0x3 = 0x80000003 STATUS_BREAKPOINT explicit software call to C debugger, notice this code starts with 0x8, not 0xC, 0xC0000003 is STATUS_INVALID_INFO_CLASS, which means bad parameter to a function call, and will never cause an exception/crash

    Code used to generate above.

The Top Ten Perl Poems
2 direct replies — Read more / Contribute
by eyepopslikeamosquito
on Dec 26, 2014 at 02:04

    Following on from The Top Ten Perl Obfus, let's count down the top ten highest rated Perl Monks poems of all time.

    Since I cannot super-search by node reputation, please note that this list is based only on some non-exhaustive searching and my fallible memory. So it's quite likely I've overlooked a deserving poem. If so, please let us know, and I'll correct the root node. Note that, to make the top ten, a poem needs a reputation of at least 120.

    That said, please feel free to mention any poem you consider deserving of a wider audience, even if it does not meet the formal reputation criteria. For example, I'd like to recognize and congratulate liverpole for pulling off a brilliant stunt of posting a poem entitled 600000 nodes as the 600000th PerlMonks node!

    Unlike obfus, I discovered the top ten qualification criteria for poetry is not so clear-cut. For example, what many folks believe to be the finest Perl Monk node of all time, namely 1st Monasterians by Erudil, was posted not as a poem, but a meditation. Though somewhat poetic, I judged that this node did not qualify because it was not a Perl poem and was not posted in the Perl Poetry section. Curiously, a response to this node, namely Re: 1st Monasterians by japhy, did qualify because, though it too was not posted in the Poetry section, it was definitely a Perl poem. Conversely, though posted in the Perl Poetry section, I chose to disqualify Aaah, spring (A Very Special Perlmonks Contest) by boo_radley because it was a poetry competition, rather than a poem. Admittedly, these decisions were somewhat arbitrary, and someone else may have decided differently.

    Now to work.

    No 10: Stayin' Alive (with CPAN) by joecamel Feb 05 2004 rep:120+

    Well, you can tell by the way I use File::Lock
    I'm a Perl Monk: no time to talk
    Got DBI and Test::More,
    been reusin' code since version four

    You know it's all right. It's okay.
    With GD::Graph and Class::Flyweight.
    We don't have time to reinvent
    so we get it from CPAN.

    Whether you're a hacker or whether you're a slacker
    You're stayin' alive, stayin' alive.
    net communicatin' and input validatin',
    And we're stayin' alive, stayin' alive.
    Ah, ha, ha, ha, stayin' alive, stayin' alive.
    Ah, ha, ha, ha, stayin' alive.

    To the tune of Stayin' Alive by the Bee Gees.

Authentication with U2F Two-factor keys
No replies — Read more | Post response
by cavac
on Dec 19, 2014 at 07:43

    NOTE/EDIT: Package name will change to Crypt::U2F::Server (and Crypt::U2F::Server::Simple), because there will also be a client module to access the key itself.

    I just uploaded the first Alpha version of Crypt::U2F, which allows you to handle the server side cryptography of the FIDO alliance's Universal 2nd factor authentication method. See also here.

    This is the same one used by Google services and fully supported in Google Chrome.

    Internally, Crypt::U2F requires Yubico's libu2f-server library installed on your system. I implemented this in two Perl modules: Crypt::U2F is the low level module (sand subject to change), that let's you play around with the underlying library. Crypt::U2F::Simple is the one you should use in most cases.

    Let's have a look into the two examples provided with the tarball. For this to work, you need to install libu2f-server and also install libu2f-host, because we need the u2f-host binary to talk to the actual USB dongle. (I'm currently in the process of making a Perl module for libu2f-host as well, but this will only finish after the hollidays.)

    The whole thing is a two part process: First you have register a new key once, then you can authenticate as often as you like. Each part (registering, authentication) itself is a two-part process as well, first you generate a challenge and send it to the client, then you have to validate the response.

    Ok, let's start with registering a key. For this example, we pass around files to and from u2f-host and also save the registered keyHandle and public key into files as well. In a real world scenario, you will probably use HTTP and Javascript to communicate with the key and save keyHandle and the public key into a database. Here's the code:

    The reason we use Base64 is simple, yet annoying: Everything except the public key is either some sort of text or even ASCII JSON. The public key on the other hand is a binary blob. It's just a matter of convenience to turn it into Base64, because that we it works in textfiles and text columns in databases as well. It don't convert directly in the library, because that might make it problematic to cooperate with other implementations of U2F authentications that also use the original C library (which delivers a binary blob), including the u2f-server example binary that comes with it.

    All of the calls to Crypt::U2F::Simple may fail for one reason or another (including new() and DESTROY()), so make sure you check all the return values!

    Let's tackle the authentication part. We'll use the keyHandle.dat and publicKey.dat generated in the previous step:

    As you can see, the process is quite similar: We load the keyHandle.dat and publicKey.dat (the second one we decode_base64()) and initialize Crypt::U2F::Simple with it. Then we generate a challenge and verify it.

    If you want to make sure the verification step actually works, you can comment out the call can try to fuss the result of u2fhost in authReply.dat. Or just comment out the call to u2fhost after you you did one successfull authentication, this one should give you a u2fs_authentication_verify (-6): Challenge error.

    Limitations and Bugs: Currently (Version 0.10), each Challenge/Verify combo has to run in the same instance of the module. I'm still working on finding out how to fix that. Also, sometimes the USB keyfob seems to be in a strange state after plugging in, returning wrongly calculated authentication replies (at least mine does). Unplugging and replugging solves that problem.

    "For me, programming in Perl is like my cooking. The result may not always taste nice, but it's quick, painless and it get's food on the table."
The Top Ten Perl Obfus
3 direct replies — Read more / Contribute
by eyepopslikeamosquito
on Dec 14, 2014 at 03:24

    Following on from The First Ten Perl Obfus, I thought it would be fun to count down the top ten highest rated Perl Monks obfus of all time.

    Since I cannot super-search by node reputation, please note that this list is based solely on my memory of spectacular obfus I've seen over the years. So, if I have overlooked an obfu gem, please let us know, and I will correct the root node. Note that, to make the top ten, a node needs a reputation of at least 240.

    No 10: Fun With Reserved Keywords by blokhead Sep 11 2003 rep:200+

    #!/usr/bin/perl not exp log srand xor s qq qx xor s x x length uc ord and print chr ord for qw q join use sub tied qx xor eval xor print qq q q xor int eval lc q m cos and print chr ord for qw y abs ne open tied hex exp ref y m xor scalar srand print qq q q xor int eval lc qq y sqrt cos and print chr ord for qw x printf each return local x y or print qq s s and eval q s undef or oct xor time xor ref print chr int ord lc foreach qw y hex alarm chdir kill exec return y s gt sin sort split

    Constraints are the heart of obfu.

    Here blokhead constrains himself to using lowercase alphabetic characters only, no punctuation at all. Combining with an exact right hand margin produces a visually stunning and surprising block-shaped obfu.

The First Ten Perl Obfus
No replies — Read more | Post response
by eyepopslikeamosquito
on Dec 14, 2014 at 03:14

    Following on from The First Ten Perl Monks, I thought it would be fun to explore the origins of PerlMonks Obfuscated code.

    What was the first PerlMonks Obfuscated code?

    As far as I can tell, it was written on Oct 13 1999 by the early PM developers at the very end of this ancient command line examples faq. Of course, this was well before the PerlMonks official opening on 23 Dec 1999. So, if we disqualify this pre-historic (accidental) obfuscation, the first deliberately obfuscated PerlMonks node was probably OBFUSCATE!!! by the thirteenth Perl Monk jdube on Dec 30 1999 at 04:51.

    PerlMonks Obfuscation Founding Father: jdube

    As was typical of early Perl Monks, jdube also had an everything2 account. Curiously, jdube further authored a companion POETRY!!! node, presumably a crude attempt to pressure vroom into creating PerlMonks Obfuscated code and Perl Poetry sections. Well, by using all caps and three exclamation marks in the node titles he was certainly shouting at vroom.

    Anyway, it seems jdube's clever ploy worked because vroom did indeed create our much loved Obfuscated code and Perl Poetry sections later that same fateful day, Dec 30 1999. By the way, I was shocked to see that the historic Poetry and Obfuscated Sections by vroom has received just one up-vote (mine). If you feel this historic node is worth more than that, you know what you need to do.

    An interesting piece of trivia is that jdube's medieval OBFUSCATE!!!/POETRY!!! barrage took place in the (now obsolete) perlcraft arena. It seems this ancient "perlcraft" section has since been re-branded as Cool Uses For Perl.

    Tragically, our PerlMonks poetry and obfu founding father jdube does not appear in the first ten official Obfuscated nodes, listed below. Sadly, he never did write an official PerlMonks obfuscated node. Sadder still, Perl Monk number 13 jdube was last seen wandering around the monastery in May 2000, and his account now sits abandoned and disabled. Perhaps being the thirteenth user proved unlucky. I wonder what jdube is doing nowadays. Will he return one day to write us another obfu or poem?

    Obu No 1: #!/usr/bin/perl by BBQ (last here Apr 07 2009)

    Created: Dec 30 1999, Rep: 14, 3 replies.

    %A=('r'=>"\n","\t"=>'#','/'=> 's','f'=>'p',"b"=>'n');@C=qw (e ! r/ / e );foreach $k (sort keys %A){ @B=(" ",'u','i',"\b",'l');$s .=qq{$k$B[$x++]$A{$k}$C[$x] \b};if ($x==1){$t=$k.$B[$x-1].$A{$k};}#ops } print$A{r}.$s;#i h8 left over \s's

perl + Qt, the easy way
3 direct replies — Read more / Contribute
by vkon
on Dec 13, 2014 at 08:53
    here is a recently tried by me approach, which appears to be coolest thing since sliced bread.

    Code speaks louder than words.
    Here I go:

    runs just fine, wow...
    As for today - when there is no usable PerlQT on CPAN - this brings tons of possibilities.

    Yep, python is a nice lib... Long live Inline::Python !

Multi-stage flip-flop?
7 direct replies — Read more / Contribute
by RonW
on Dec 10, 2014 at 18:30
    In a response to a SOPW post, I wrote:
    while (<>) { if (/^#ERRORS/ .. /^CELLS/) { push(@errors, $_); } elsif (/^CELLS/ .. /^\s*$/) { push(@errors, $_); } else { ...; # other processing } }

    Which doesn't work.

    Occurs to me that it might be a useful enhancement to allow .. conditionX to be an additional stage to the preceding condition1 .. condition2, creating a linked cascade of flip-flops:

    if (/match1/ .. /match2/) { doStage1(); } elsif (.. /match3/) { doStage2(); } elsif (.. /match4/) { doStage3(); } else { doOtherProcessing(); }

    The semantics would be an extension of .. In the second example, match1 would trigger stage 1 (doStage1() will be called). Then match2 will end stage 1 and trigger stage 2 (doStage2() will be called). Then match3 ends stage 2 and triggers stage 3 (doStage3() will be called). Finally, match4 resets the cascade.


    Updated to mention the first example doesn't work.

    Updated second example and the description of the semmantics.

Would you suggest alternative names for Perl 6?
12 direct replies — Read more / Contribute
by rsFalse
on Dec 05, 2014 at 11:00
    I was upset when I knew that Perl 6 is a different language and not compatible with Perl and have the similar name, and appeared after Perl v5. Its is messy; practically humans think that number which goes after the name means version or something like that.
    I think that a name for that new language could have to match /^Perl\s?\D.*$/i or /^\w+\sPerl$/i, but not /^Perl\s?\d+$/i.
    Maybe it could be something like "Perlix", "Perlox", "Perl*". I liked Perlox or Perlex, where maybe -ex could mean 'extended', and -ox could mean that it has optimized (o) regexes (say DFA on simple search pattern), and it doesn't count spaces in regex by default (x).
    Now it is like forbidden for Perl v1..5 to have v6.

    UPD. Sorry for mis-searching. And thanks for very nice nodes, especially very funny very first!
Gaps in the Maps of pm.orgs
5 direct replies — Read more / Contribute
by wjw
on Nov 29, 2014 at 11:37

    I recently graduated to a situation where I might have time to explore Perl in a more 'social' context: by that I mean in meat-space. To my mild consternation, a look at the map of North American Perl Monger groups only to find that I am on the eastern edge of the great northern void.

    There are a couple of these desolate areas represented on the map, Some of these are perhaps more easily explained away than others I suppose. States with lower population densities or fewer urban areas are somewhat understandable as geographical deserts of Perl desolation. However, to my way of thinking, that does not explain all of these holes in the map of North America.

    Looking at the world map is even more strange to me. Perl is such a friendly, though quirky sort of language. It seems like it would bring people together more readily....

    One area in particular is odd to me, and the source of my mild regret. I currently reside on the Northwest corner of the Minneapolis/St. Paul area of Minnesota. This is not a massive or dense urban area, but it is not small either. There are numerous higher education institutions, a broad variety of industries are represented in the region, and yet no pm group. One would think that combined with the previously mentioned advantages, the winters we have here, would lend it to be an ideal place to attract a good number of Perl users interested in jaw-jacking over a beer or two. Come to think of it, there are some pretty good beers available here too....another reason which would support congregating on occasion.

    Apparently not.

    Searches on various engines indicate there have been efforts to establish such a group to no effect over the years. Once again, I find myself grateful for this site. I guess for now, my contact with the world of Perl will continue to be ethereal... . Not complaining, just saying... .

    PS. If someone knows of something my quick search missed, please do let me know. I could use a beer....

    Update:Thanks to those of you that responded. I am looking into opensource/linux and sundry tangential subjects in the area to see what might be leveraged. I do appreciate the encouragement, though I do want to investigate the reasons that it has not been done successfully previously first before I tackle something like this. Doing it poorly would probably be more damaging than not doing it at all...

    ...the majority is always wrong, and always the last to know about it...

    A solution is nothing more than a clearly stated problem...

Opinion: where Perl5 wasn't attractive for me
14 direct replies — Read more / Contribute
by rsFalse
on Nov 19, 2014 at 05:59
    As a newbie, I was dissapointed of:
    1) Perl does not have integer division operator. It must call "use/no integer" to change type. Python has: / - normal division, // - integer division. Sugar.
    To use things such as "ceil/floor", I need to "use POSIX"... Aren't they basic?
    2) It is not problem for me to read dollars in single variables. But it is annoying to read them in some-dimensional arrays (it's noisy), e.g. $array[$i][$j] > $array[$i][$j-1].
    3) It is strongly recommended to "use strict" and make variables "my", then why it is not default? Whay all the code must have so much my my my my...?
    4) Doesn't work - "$_ = reverse"; If in subroutine I can write "$_ = shift", why can't I write so in main (I need to write "$_ = shift @_").
    5) It was strange that "cho(m)p" returns last symbol, not a string w/o last symbol. Ruby's cho(m)p I like more, because I can proceed on string: gets.cho(m)p.split.do_smth...
    6) Can't use blocks using "and/or":
    "$i > 5 or {print "No"; last}" (overcome - "$i > 5 or (print "No"), last"; comma is tighter than "or" but it is counter-intuitive for me)
    7) It was suprise for me that when I used "$hash{length}" it interpreted (length $_) as "length"; Surprise was that ++ has magic (I need to know exceptions) and -- has not; Surprise that "use bigint" doesn't DWIM in some cases.
    8) Difficult exception is that "print (1+1)*2" != "print 2*(1+1)" == "print STDOUT (1+1)*2". I think "print(..." should better wait until the end of block or ";".
Sub signatures, and a vexing parse
2 direct replies — Read more / Contribute
by davido
on Nov 18, 2014 at 16:53

    I was experimenting with the experimental subroutine signatures feature of Perl 5.20 today along with the much maligned prototypes feature of old, and encountered a most vexing parse that interested me. So I wanted to mention it here.

    First, something that is not a problem:

    *mysub = sub : prototype(\@\@) ($left,$right) { ... };

    This parses correctly, and will generate a subroutine named mysub with a prototype of \@\@, and with named parameters of $left and $right, which when called will contain array refs. But this doesn't do much. My real goal was generating several similar subroutines, and called upon map in a BEGIN{ ... } block to do the heavy lifting.

    Here is a contrived example that isn't terribly useful, but that works, and demonstrates the issue:

    use strict; use warnings; no warnings 'experimental::signatures'; use feature qw/say signatures/; use List::Util qw(all); BEGIN { ( *array_numeq,*array_streq ) = map { my $compare = $_; sub :prototype(\@\@) ($l,$r) { @$l == @$r && all { $compare->($l->[$_],$r->[$_]) } 0 .. $#$l } } sub { shift == shift }, sub { shift eq shift } } my @left = ( 1, 2, 3 ); my @right = ( 1, 2, 3 ); { local $" = ','; say "(@left) ", ( array_numeq @left, @right ) ? "matches" : "doesn't match", " (@right)"; }

    Do you see what the problem is? The compiler doesn't care for this at all, and will throw a pretty useless compiletime error:

    Array found where operator expected at line 14, at end of l +ine (Missing operator before ?) syntax error at line 14, near "@\@) " Global symbol "$l" requires explicit package name at line 1 +4. Global symbol "$r" requires explicit package name at line 1 +4. Global symbol "$l" requires explicit package name at line 1 +5. Global symbol "$r" requires explicit package name at line 1 +5. Global symbol "$l" requires explicit package name at line 1 +6. Global symbol "$r" requires explicit package name at line 1 +6. Global symbol "$l" requires explicit package name at line 1 +7. BEGIN not safe after errors--compilation aborted at line 17 +.

    Q: So what changed between the first example, that works, and the second example, that doesn't?

    A: Lacking other cues, the compiler parses  sub : as a label named sub, and thinks that I'm trying to call a subroutine named prototype... and from that point on things are totally out of whack.

    Solution: +. Anything that can remind the parser that it's not looking at a label will do the trick. Parenthesis around the sub : ... construct works, but + is easier, and probably more familiar to programmers who use + to get {....} to be treated as an anonymous hash ref constructor rather than as a lexical block.

    With that in mind, here's code that works:

    use strict; use warnings; no warnings 'experimental::signatures'; use feature qw/say signatures/; use List::Util qw(all); BEGIN { ( *array_numeq,*array_streq ) = map { my $compare = $_; + sub :prototype(\@\@) ($l,$r) { @$l == @$r && all { $compare->($l->[$_],$r->[$_]) } 0 .. $#$l } } sub { shift == shift }, sub { shift eq shift } } my @left = ( 1, 2, 3 ); my @right = ( 1, 2, 3 ); { local $" = ','; say "(@left) ", ( array_numeq @left, @right ) ? "matches" : "doesn't match", " (@right)"; }

    ...or how a single keystroke de-vexed the parse.

    A really simple example that breaks is this:

    my $subref = do{ sub : prototype($) ($s) { return $s; }; # Perl thinks sub: is a lab +el here. };

    I don't really see any way around the parsing confusion in the original version that doesn't work. That perl considers sub : to be a label in the absence of other cues is probably not something that can be fixed without making sub an illegal label. But if I were to file a bug report (which I haven't done yet), it would probably be related to the useless error message.

    This example is fairly contrived, but it's not impossible to think that subs with signatures and prototypes might be generated in some similar way as to fall prey to this mis-parse.

    Credit to mst and mauke on for deciphering why the compiler fails to DWIW.


The First Ten Perl Monks
6 direct replies — Read more / Contribute
by eyepopslikeamosquito
on Nov 16, 2014 at 08:31

Add your Meditation
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • 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 lurking in the Monastery: (12)
    As of 2015-05-28 18:51 GMT
    Find Nodes?
      Voting Booth?

      In my home, the TV remote control is ...

      Results (566 votes), past polls