perl

How should I handle errors in Perl methods, and what should I return from the methods?

Hi I've wrapped Perl's Net::SSH::Expect with a small module to reduce the boilerplate code needed to write a new configuration script for use with our HP iLO cards. While on one hand I want this wrapper to be as lean as possible, so non-programmer colleagues can use it, I also want it to be as well-written as possible. It's used like s...

How can I extract images from a PDF file?

I need to extract all the images from a PDF file on my server. I don't want the PDF pages, only the images at their original size and resolution. How could I do this with Perl, PHP or any other UNIX based app (which I would invoke with the exec function from PHP)? ...

What's the best IPC mechanism for medium-sized data in Perl?

I'm working on designing a multi-tiered app in Perl and I'm wondering about the pros and cons of the various IPC mechnisms available to me. I'm looking at handling moderately-sized data, typically a few dozen kilobytes but up to a couple of megabytes, and the load is pretty light, at most a couple of hundred requests per minute. My pri...

Is there an advantage in choosing ASP.Net over PHP or Perl?

I found myself struggling with me every time I am asked, which language to prefer for a web-application. Most people dismiss the importance of a good architecture. That why a answer that architecture is more important than the language. Afterwards sometimes I sompare the advantadges. But that is always not about the language but im most ...

How can I select rows that are null using bound queries in Perl's DBI?

I want to be able to pass something into an SQL query to determine if I want to select only the ones where a certain column is null. If I was just building a query string instead of using bound variables, I'd do something like if ($search_undeleted_only) { $sqlString .= " AND deleted_on IS NULL"; } but I want to use bound que...

How can I determine if a Perl function exists at runtime?

I'm working on a test framework in Perl. As part of the tests, I may need to add precondition or postcondition checks for any given test, but not necessarily for all of them. What I've got so far is something like: eval "&verify_precondition_TEST$n"; print $@ if $@; Unfortunately, this outputs "Undefined subroutine &verify_preconditio...

How can I scan multiple log files to find which ones have a particular IP address in them?

Recently there have been a few attackers trying malicious things on my server so I've decided to somewhat "track" them even though I know they won't get very far. Now, I have an entire directory containing the server logs and I need a way to search through every file in the directory, and return a filename if a string is found. So I tho...

How do I use File::Find::Rule in taint mode?

I am trying to get a list of subdirectories in a given directory using something like the following: #!/usr/bin/perl -wT use strict; use warnings; use File::Find::Rule; use Data::Dumper; my @subdirs = File::Find::Rule->maxdepth(1)->directory->relative->in('mydir'); print Dumper(@subdirs); However, running this gives the result: ...

How can I send a JSON response from a Perl CGI program?

Hi, I am writing a JSON response from a perl/cgi program. The header's content type needs to be "application/json". But it doesn't seems to be recognized as response is thrown as a text file. I would be capturing response using JSON library of jQuery. Where am I missing in sending the JSON response. ...

How can I get started with Apache, MySQL, and (PHP, Perl, Python) on a Mac?

What do you recommend for setting the MAMP development stack? I've seen the quickstart thing at http://www.mamp.info, but I don't really like that approach. I'd rather have a full-fledged Apache that I can install any number of modules into. I remember seeing in the Leopard Server demo a really slick GUI that allows you to setup all this...

Flex/AIR + Catalyst: What's the best way to get them to talk to each other?

What is the best way to get Adobe Flex/AIR to communicate with perl Catalyst? We are currently using Catalyst::Plugin::XMLRPC on the Catalyst side and as3-rpclib on the Flex/AIR side. That works fine, but I'd rather take as3-rpclib out of the picture and use a method that is native to Flex. From what I can tell, it's native compnone...

Is there a test suite for PDF files?

Is there a test suite for PDFs, preferably in Perl? What I want is some function to test positioning and existence of some text (and if possible a name of a grapic) in a PDF file. Is this theoritically possible with PDF markup? Thank you for your help. ...

How can I read the files in a directory in sorted order?

When I read a directory in Perl with opendir, readdir, and closedir, the readdir function doesn't seem to read the files in any specific order (that I can tell). I am reading a directory that has subdirectories named by epoch timestamp: 1224161460 1228324260 1229698140 I want to read in these directories in numerical order, which wou...

Why can't Win32::OLE talk to Excel2003 under Win2003?

I have a Web-based Perl Win32::OLE script that uses Excel on the server side. It has been working happily for years on a Win2000 server running Excel2000. We recently upgraded to Win2003/Excel2003 and I now get the following error from the script: Win32::OLE(0.1709) error 0x80070005: "Access is denied" at create_worksheet_lib.plx line ...

Is there a way to "use" a single file that in turn uses multiple others in Perl?

I'd like to create several modules that will be used in nearly all scripts and modules in my project. These could be used in each of my scripts like so: #!/usr/bin/perl use Foo::Bar; use Foo::Baz; use Foo::Qux; use Foo::Quux; # Potentially many more. Is it possible to move all these use statements to a new module Foo::Corge and the...

How can download via FTP all files with a current date in their name?

I have a file format which is similar to "IDY03101.200901110500.axf". I have about 25 similar files residing in an ftp repository and want to download all those similar files only for the current date. I have used the following code, which is not working and believe the regular expression is incorrect. my @ymb_date = "IDY.*\.$year$mon$...

How do I use the Groups.pm in Request Tracker?

In lib\RT\CustomFieldValues\ there is the groups.pm file which is supposed to be an example of how to get data into a custom field, but how do I actually use that once I have written it? Does anyone have any documentation or a sample of this? ...

How do you do Design by Contract in Perl?

I'm investigating using DbC in our Perl projects, and I'm trying to find the best way to verify contracts in the source (e.g. checking pre/post conditions, invariants, etc.) Class::Contract was written by Damian Conway and is now maintained by C. Garret Goebel, but it looks like it hasn't been touched in over 8 years. It looks like wha...

How do I print unique elements in Perl array?

I'm pushing elements into an array during a while statement. Each element is a teacher's name. There ends up being duplicate teacher names in the array when the loop finishes. Sometimes they are not right next to each other in the array, sometimes they are. How can I print only the unique values in that array after its finished getting...

How does "map" interpret its first argument in Perl?

I have some questions about Perl's "map" function. Specifically: How does %hash = map {$_ => 1} @array create a hash mapping array's elements to 1? How does block return a list of two elements? I thought block returns its last value. Does => implicitly create a list, as opposed to "," that returns its right argument? Why does %hash...