perl

How can I use DBI to execute a "\copy from remote table" command in Postgres?

I need to copy from a remote postgres server to a local one. I cannot use any ETL tools; it must be done using Perl with DBI. This data will be large so I don't want to use "select from source" and "insert into local". I was looking to use COPY to create a file but this file will be created on the remote server. I can't do that either. I...

How can I get the width and height of a text string with CAM::PDF?

I use the following to read a PDF file and get text strings of a page: my $pdf = CAM::PDF->new($pdf_file); my $pagetree = $pdf->getPageContentTree($page_no); # Get all text strings of the page # MyRenderer is a separate package which implements getTextBlocks and # renderText methods my @text = $pagetree->traverse('MyRenderer')->getTex...

How come MooseX::Storage doesn't seem to follow attribute traits for some objects?

Hi, I have put together a little test case to demonstrate my problem: package P1; use Moose; use MooseX::Storage; with Storage; has 'blah' => ( is => 'rw', ); package P2; use Moose; use MooseX::Storage; with Storage; has 'lol' => ( is => 'rw', traits => ['DoNotSerialize'] ); package P3; use Moose; extends 'P2'; has 'ma...

What's the most straightforward way to delete emails marked as spam by SpamAssassin?

I'm on Ubuntu Intrepid, using Postfix and SpamAssassin. I've seen approaches using procmail (like the one suggested @ Apache), but I'm looking for a solution that does not use procmail. This is a programming question because the correct answer will be some form of code that accomplishes the task at hand (my response to the negative vote...

Detecting Overridden Methods in Perl

Last week I was bitten twice by accidentally overriding methods in a subclass. While I am not a fan of inheritance, we (ab)use this in our application at work. What I would like to do is provide some declarative syntax for stating that a method is overriding a parent method. Something like this: use Attribute::Override; use parent '...

How can I modify received socket messages in Perl?

I am writing a Perl program that sends and receives messages from two sockets and acta as a switch. I have to modify the received messages received from one socket, prepend 3 bytes to the data, and finally send the modified messages to another socket. I adopt select()...sysread()...syswrite() mechanism to poll for messages between socket...

How do I invoke a Perl script on Windows?

Hello, I tried compile apache 2.2, my Visual Studio 2008 returned error on RC. After some googling, I found this explanation: What appears to have happened is that you've opened it up unsuccessfully in Visual Studio; before you convert to an .sln file + .vcproj files, it's important to invoke the perl script perl srclib\...

What regex will capitalize any letters following whitespace?

I'm looking for a Perl regex that will capitalize any character which is preceded by whitespace (or the first char in the string). I'm pretty sure there is a simple way to do this, but I don't have my Perl book handy and I don't do this often enough that I've memorized it... ...

How can I output UTF-8 from Perl?

I am trying to write a Perl script using the "utf8" pragma, and I'm getting unexpected results. I'm using Mac OS X 10.5 (Leopard), and I'm editing with TextMate. All of my settings for both my editor and operating system are defaulted to writing files in utf-8 format. However, when I enter the following into a text file, save it as a ...

Next step after PHP: Perl or Python?

It might seem it has been asked numerous times, but in fact it hasn't. I did my research, and now I'm eager to hear others' opinions. I have experience with PHP 5, both with functional and object oriented programming methods. I created a few feature-minimalistic websites. Professionals may agree about PHP not being a programming langua...

How can a Perl script know its own memory footprint?

I have a long running Perl script and I'd like to let it know (and report) how much memory it is using. I'd like to have this information both on Linux and Windows and if possible on Mac OS X as well. ...

Where is the documentation for CGI.pm?

A google search reveals nothing useful. Does Perl have a javadoc equivalent for its modules? (Update -- I'm aware of perdoc, but that is more like a man page, which is hard to scan to find functionality... I'm looking for a function/operation list (w/ descriptions) similar to javadoc's presentation or php's documentation) ...

How do you comment a Perl regular expression?

How do you put comments inside a Perl regular expression? ...

How can I parse quoted CSV in Perl with a regex?

I'm having some issues with parsing CSV data with quotes. My main problem is with quotes within a field. In the following example lines 1 - 4 work correctly but 5,6 and 7 don't. COLLOQ_TYPE,COLLOQ_NAME,COLLOQ_CODE,XDATA S,"BELT,FAN",003541547, S,"BELT V,FAN",000324244, S,SHROUD SPRING SCREW,000868265, S,"D" REL VALVE ASSY,000771881, S,"...

How can I send Perl output to a both STDOUT and a variable?

I would like to send the output from a command to both STDOUT and to a variable. I want to combine: my $var = `some command` ; system( 'some command' ) ; [Tee][1] is a step in the right direction but this sends it to a file rather than to a variable. I guess I could then read the file but it would be simpler to get it straight the...

How can I redefine Perl class methods?

The question "How can I monkey-patch an instance method in Perl?" got me thinking. Can I dynamically redefine Perl methods? Say I have a class like this one: package MyClass; sub new { my $class = shift; my $val = shift; my $self = { val=> $val}; bless($self, $class); return $self; }; sub get_val { my $self = shift; retu...

How to detemine the file type in Linux?

If someone sends me a document (.pdf,.doc,.xls, ppt, .ogg, mp3, png, etc) without the extension, how can I determine the file type? The /usr/bin/file command doesn't always guess right or it simply says that I have a Microsoft Office document. I would like to know exactly so I can add the extension to the file name. ...

How can I generate all permutations of an array in Perl?

What's the best (elegant, simple, efficient) way to generate all n! permutations of an array in perl? For example, if I have an array @arr = (0, 1, 2), I want to output all permutations: 0 1 2 0 2 1 1 0 2 1 2 0 2 0 1 2 1 0 It should probably be a function that returns an iterator (lazy/delayed evaluation because n! can become so impo...

What is a good way to determine dates in a date range?

What is a good Perl module (or good approach) that returns all the valid calendar dates between a start date and an end date? For example, if I have 1/29/2009 as a start date and 2/3/2009 as an end date then I would like it to return an array of 1/30/2009, 1/31/2009, 2/1/2009, and 2/2/2009. There must be a good Perl module that already...

Why doesn't Perl print the last text before it exits?

My code won't run the last line right before " exit; " and I have no clue why. I tried to put an additional printf $fh line before exit, but that didn't work either; it would not print either line. Everything else prints fine except the last print statements before the exit. Any clue why this happens? Or better yet, how to fix or wor...