perl

How do I get a list of installed CPAN modules?

Aside from trying perldoc <module name> individually for any CPAN module that takes my fancy or going through the file system and looking at the directories I have no idea what modules we have installed. What's the easiest way to just get a big list of every CPAN module installed? From the command line or otherwise. ...

When is the right time (and the wrong time) to use backticks?

Many beginning programmers write code like this: sub copy_file ($$) { my $from = shift; my $to = shift; `cp $from $to`; } Is this bad, and why? Should backticks ever be used? If so, how? ...

How can I update Perl on Windows without losing modules?

At work I'm using Perl 5.8.0 on Windows. When I first put Perl on, I went to CPAN, downloaded all the sources, made a few changes (in the .MAK file? to support threads, or things like that), and did nmake / nmake test / nmake install. Then, bit by bit, I've downloaded individual modules from CPAN and done the nmake dance. So, I'd like ...

What exactly is Parrot?

I understand that Parrot is a virtual machine, but I feel like I'm not completely grasping the idea behind it. As I understand, it's a virtual machine that's being made to handle multiple languages. Is this correct? What are the advantages of using a virtual machine instead of just an interpreter? What specifically is Parrot doin...

How do I parse a string with GetOpt::Long::GetOptions?

I have a string with possible command line arguments (using an Read-Eval-Print-Loop program) and I want it to be parsed similar to the command line arguments when passed to Getopt::Long. To elaborate: I have a string $str = '--infile /tmp/infile_location --outfile /tmp/outfile' I want it to be parsed by GetOptions so that it is easi...

How can I find the first occurrence of a pattern in a string from some starting position?

I have a string of arbitrary length, and starting at position p0, I need to find the first occurrence of one of three 3-letter patterns. Assume the string contain only letters. I need to find the count of triplets starting at position p0 and jumping forward in triplets until the first occurrence of either 'aaa' or 'bbb' or 'ccc'. Is th...

How do you translate this regular-expression idiom from Perl into Python?

I switched from Perl to Python about a year ago and haven't looked back. There is only one idiom that I've ever found I can do more easily in Perl than in Python: if ($var =~ /foo(.+)/) { # do something with $1 } elsif ($var =~ /bar(.+)/) { # do something with $1 } elsif ($var =~ /baz(.+)/) { # do something with $1 } The corres...

Comparison of Python and Perl solutions to Wide Finder challenge

I'd be very grateful if you could compare the winning O’Rourke's Perl solution to Lundh's Python solution, as I don't know Perl good enough to understand what's going on there. More specifically I'd like to know what gave Perl version 3x advantage: algorithmic superiority, quality of C extensions, other factors? Wide Finder: Results ...

Intra-process coordination in mod_perl under the worker MPM

I need to do some simple timezone calculation in mod_perl. DateTime isn't an option. What I need to do is easily accomplished by setting $ENV{TZ} and using localtime and POSIX::mktime, but under a threaded MPM, I'd need to make sure only one thread at a time was mucking with the environment. (I'm not concerned about other uses of loca...

I know Perl 5. What are the advantages of learning Perl 6, rather than moving to Python?

Coming from a Perl 5 background, what are the advantages of moving to Perl 6 or Python? Edit: If you downvoted this because you think it's just flamebait, read the answers below. They're not raving arguments; they're well-written discussions of the pros and cons of each language. Give the Stack Overflow community some credit. ...

Should I learn/play with Perl 6?

Perl 6 has been under development for over 8 years now, and (as ever) there seems to be no end in sight. However, it has had a reasonable implementation for some time, Pugs, and even has multiple implementations now. When I last took a look at Perl 6 a few years ago, it seemed to me that there were lots of interesting ideas, but that e...

Passing a regex substitution as a variable in Perl?

I need to pass a regex substitution as a variable: sub proc { my $pattern = shift; my $txt = "foo baz"; $txt =~ $pattern; } my $pattern = 's/foo/bar/'; proc($pattern); This, of course, doesn't work. I tried eval'ing the substitution: eval("$txt =~ $pattern;"); but that didn't work either. What horribly obvious thing a...

How does Perl 6 evaluate truthiness?

In reading about Perl 6, I see a feature being trumpeted about, where you no longer have to do: return "0 but true"; ...but can instead do: return 0 but True; If that's the case, how does truth work in Perl 6? In Perl 5, it was pretty simple: 0, "", and undef are false, everything else is true. What are the rules in Perl 6 when it...

Decode an UTF8 email header

Hi, I have an email subject of the form: =?utf-8?B?T3.....?= The body of the email is utf-8 base64 encoded - and has decoded fine. I am current using Perl's Email::MIME module to decode the email. What is the meaning of the =?utf-8 delimiter and how do I extract information from this string? ...

Why can't I install DBD::mysql so I can use it with Maatkit?

I'm trying to install Maatkit following the maatkit instructions. I can't get past having to install DBD::mysql. "Warning: prerequisite DBD::mysql 1 not found." When I try to install DBD::mysql from cpan, I get very helpful "make had returned bad status, install seems impossible". Perl is "v5.8.8 built for darwin-thread-multi-2level", ...

Perl or Python script to remove user from group

I am putting together a Samba-based server as a Primary Domain Controller, and ran into a cute little problem that should have been solved many times over. But a number of searches did not yield a result. I need to be able to remove an existing user from an existing group with a command line script. It appears that the usermod easily ...

What is the difference between my and local in Perl?

I am seeing both of them used in this script I am trying to debug and the literature is just not clear. Can someone demystify this for me? ...

Any good collection module in perl?

Can someone suggest a good module in perl which can be used to store collection of objects? Or is ARRAY a good enough substitute for most of the needs? Update: I am looking for a collections class because I want to be able to do an operation like compute collection level property from each element. Since I need to perform many such op...

What does "0 but true" mean in Perl?

Can someone explain what exactly the string "0 but true" means in Perl? As far as I understand, it equals zero in an integer comparison, but evaluates to true when used as a boolean. Is this correct? Is this a normal behavior of the language or is this a special string treated as a special case in the interpreter? ...

Does a hash shrink in Perl as you delete elements?

Does a hash shrink in Perl as you delete elements. More specifically I had a perl program that I inherited that would parse a huge file ( 1 GB ) and load up a hash of hashes. it would do that same for another file and then do a comparison of different elements. The memory consumption was huge during this process and even though I added...