perl

How do I read the contents of a small text file into a scalar in Perl?

I have a small text file that I'd like to read into a scalar variable exactly as it is in the file (preserving line separators and other whitespace). The equivalent in Python would be something like buffer = "" try: file = open("fileName", 'rU') try: buffer += file.read() finally: file.close() except IOErro...

How do I convert a HTML table to a fixed font textual table?

I have an application in Perl that reads in HTML based mark up and converts it to a textual output. One of the things I have encountered is the need to easily convert a HTML table to a fixed font output. <table border="1"> <tr><td>Hello</td> <td>World</td> <tr> <td>foo</td> <td>bar</td> </tr></table> I am looking f...

How do I redirect stdout and stderr output from a Perl script to a file on WIndows?

I tried this: test1.pl >output.log 2>&1 but this is the result: Can't dup STDOUT: Permission denied at C:/Perl/lib/Test/Builder.pm line 1376. Compilation failed in require at C:/Perl/lib/Test/Builder/Module.pm line 3. BEGIN failed--compilation aborted at C:/Perl/lib/Test/Builder/Module.pm line 3. Compilation failed in require at C:/...

How can I extract images from a PDF file?

Hi! I am able to extract the images from a PDF file using many Perl modules, but none of them specifies the exact positions of the images being extracted (where the image actually belongs). Could anyone suggest to me how to extract the images along with their positions? Thanks in advance. ...

Should I use Perl or Python for network monitoring?

I want to have some work done on the Network front, pinging numerous computers on a LAN and retrieving data about the response time. Which would be the most useful and productive to work with: Perl or Python? ...

Why do my Perl tests fail with `use encoding 'utf8'`?

Hi, I'm puzzled with this test script: #!perl use strict; use warnings; use encoding 'utf8'; use Test::More 'no_plan'; ok('áá' =~ m/á/, 'ok direct match'); my $re = qr{á}; ok('áá' =~ m/$re/, 'ok qr-based match'); like('áá', $re, 'like qr-based match'); The three tests fail, but I was expecting that the use encoding 'utf8' would u...

How can I combine Catalyst and ngettext?

I'm trying to get my head around i18n with Catalyst. As far as I understood the matter, there are two ways to make translations with Perl: Maketext and Gettext. However, I have a requirement to support gettext's .po format so basically I'm going with gettext. Now, I've found Catalyst::Plugin::I18n and thus Locale::Maketext::Lexicon, whi...

How can I upload a document to SharePoint with Perl?

I have a Perl app that runs some perforce operations, in the end I would like it to upload the results to SharePoint website. What is the simplest Perl script that can accomplish a task of adding a document to SharePoint? The script would need to run on Solaris and use as few as possible external libraries as possible (definetely pur...

Why does MIcroQuill Smartheap throw "mem_bad_pointer" errors after I embed perl?

I am embedding perl in a C++ application that uses Smartheap. Regardless of whether I compile the perl to use its own malloc or the system's I get a bunch of error mem___bad_pointer dialogs. It seems to work fine when I just click "ok" and ignore the errors, but obviously I need to actually solve the problem. Do I maybe need to compil...

How do you calculate div and mod of floating point numbers?

In Perl, the % operator seems to assume integers. For instance: sub foo { my $n1 = shift; my $n2 = shift; print "perl's mod=" . $n1 % $n2, "\n"; my $res = $n1 / $n2; my $t = int($res); print "my div=$t", "\n"; $res = $res - $t; $res = $res * $n2; print "my mod=" . $res . "\n\n"; } foo( 3044.952963...

How do I use add_to in Class::DBI?

I'm trying to use Class::DBI with a simple one parent -> may chidren relationships: Data::Company->table('Companies'); Data::Company->columns(All => qw/CompanyId Name Url/); Data::Company->has_many(offers => 'Data::Offer'=>'CompanyId'); # =>'CompanyId' and Data::Offer->table('Offers'); Data::Offer->columns(All => qw/OfferId CompanyId...

Is there a Python equivalent of Perl's x operator?

In Perl, I can replicate strings with the 'x' operator: $str = "x" x 5; Can I do something similar in Python? ...

Is it possible to define anonymous subroutines in a hash constructor in Perl?

Is it possible to define anonymous subroutines in a hash constructor in Perl? I'm trying to do something like this: my %array = { one => sub { print "first $_[0]" }, two => sub { print "next $_[0]" }, three => sub { print "last $_[0]" }}; $array{$foo}->('thing'); But it isn't working. The code seem...

How do I override autogenerated accessors in Perl's Class::DBI?

Hello, I followed the example at http://wiki.class-dbi.com/wiki/Overriding_autogenerated_accessors I want to modify the URL before it is inserted to the database: package Hosting::Company; use base 'Class::DBI'; my $class = __PACKAGE__; $class->table('Companies'); $class->columns(Primary => 'CompanyId'); $class->columns(Others => qw...

Are there any free Windows Perl IDE with debugging?

Are there any free Perl IDEs out there for Windows that have debugging capabilities, syntax highlighting, and possibly even IntelliSense? ...

How do I determine the longest similar portion of several strings?

As per the title, I'm trying to find a way to programmatically determine the longest portion of similarity between several strings. Example: file:///home/gms8994/Music/t.A.T.u./ file:///home/gms8994/Music/nina%20sky/ file:///home/gms8994/Music/A%20Perfect%20Circle/ Ideally, I'd get back file:///home/gms8994/Music/, because that's th...

How can I implement server-side rate limiting for a Perl web service?

I have a Perl-based CGI/Fast CGI web service and want to rate-limit clients by IP address to stop aggressive clients causing too much work. I have looked around for some code and found Algorithm::TokenBucket in CPAN but that is for client requests; it has no persistence and has no per-user config so is not really useful for server-side ...

Can I define functions outside of a class using MooseX::Declare?

I recently started using the module MooseX::Declare. I love it for its syntax. It's elegant and neat. Has anyone come across cases where you would want to write many functions (some of them big) inside a class and the class definition running into pages? Is there any workaround to make the class definition to just have the functions decl...

How can I do unit testing in Perl?

I have been doing some OO Perl programming and I was wondering: which is the best way to perform unit tests? So far I have been using the Test::Simple module to perform tests, but it feels insufficient for what I want. Can you point me to some nice modules for that? ...

Is there any good tool to refactor Perl web code?

hi guys, i'm currently working on a perl web app LAMP style and recently stumbled upon this death maze of code left by some previous developer. He left so many magic numbers and weird logic that it's gives me a headache everytime i had to go through it. I'm learning unit testing right now so i want to find some useful tool to refactor t...