perl

Is there a working example of simple Net::OpenID::Consumer::Lite CGI script?

I have seen the examples of Net::OpenID::Consumer::Lite on CPAN but I was hoping to get a single script that uses POST method. If nobody has this than I will post my solution back here once I get it working. ...

Perl: When called in a method, can ref($self) ever return anything other than __PACKAGE__ or undef?

Hi, I have method in a class that I need to make sure is only called on an object instance, and not as a class method. I will probably do something like this: # Edit: this is terrible, don't do this, it breaks inheritance. sub foo { my ($self) = @_; if (ref($self) ne __PACKAGE__) { return; } ...do stuff } But I'm thinking it...

What are best practices for deploying a Catalyst application to a production server?

What is a good way to deploy Catalyst applications to a production server? Currently I simply have a FastCGI dispatch script in the root of the repository and when I want to update the server code, I push the branch to the server. This is quite simple, but not perfect. If the code fails the tests on the server machine (for example becaus...

How can I extract data from HTML tables in Perl?

Possible duplicate: Can you provide an example of parsing HTML with your favorite parser? How can I extract content from HTML files using Perl? I'm trying to use regular expressions in Perl to parse a table with the following structure. The first line is as follows: <tr class="Highlight"><td>Time Played</a></td><td></td><td>Artist</...

How do I connect to an MS Access database using Perl?

I have a .accdb file on my local machine and I am trying to connect to it and read some data from 3 tables within the DB. How do I establish the connection using Perl? So far I have scraped together this much for MS Access, but I am getting errors saying that I am not using the correct driver. Any ideas? my $msaccess_dbh = DBI->connect...

Why does Perl's sprintf not round floating point numbers correctly?

I was out looking for the rounding convention used by Perl's built-in function sprintf. I was thinking that it does a normal rounding (e.g. ROUND_HALF_UP as in Java's rounding mode convention), but digging further proved this to be wrong: > /usr/local/bin/perl5.10.1 -e 'print(sprintf("%.2f", shift @ARGV)."\n");' 0.335 0.34 > /usr/local...

How can I check if a file is open by another program in Perl?

In Perl, how do I test if a file of open by another Perl program? I need the first program to be done before the second program can start. ...

SQL query generator for Perl with stored procedures support

Current code base I'm working on is full of ad-hoc conditional string concatenations producing less than clear SQL queries. I want to make them maintainable, but since using DBIx::Class is too complex to move to for now (giant legacy base), I'm looking to at least make them more robust by using some sort of SQL generator, which would onl...

Why does my Perl tr/// remove newlines?

I'm trying to clean up form input using the following Perl transliteration: sub ValidateInput { my $input = shift; $input =~ tr/a-zA-Z0-9_@.:;',#$%&()\/\\{}[]?! -//cd; return $input; } The problem is that this transliteration is removing embedded newline characters that users may enter into a textarea field which I want to keep as ...

FreeBSD, MySQL, Perl, bash: intermittent blocking on named pipes?

This is weird and I'm not sure who the culprit really is. I'm doing some scripting, on FreeBSD (6.2)? which makes extensive use of the following bashism: do_something <(mysql --skip-column-names -B -e 'select ... from ... where ...;') ... where "do_something is a somewhat crufty utility (in Perl) that won't read from a pipeline. If ...

How can I delete a newline if it is the last character in a file?

I have some files that I'd like to delete the last newline if it is the last character in a file. 'od -c' shows me that the command I run does write the file with a trailing new line: 0013600 n t > \n I've tried a few tricks with sed but the best I could think of isn't doing the trick: sed -e '$s/\(.*\)\n$/\1/' abc Any ideas...

Has anyone implemented Peter Norvig's spellchecker in Perl?

I saw Michael Sparks's very interesting dissection of Peter Norvig's Spell Checker at the SO DevDays in London and it got me wondering if anyone has attempted to implement this piece of code in another language, say Perl or maybe C++? ...

Perl -Database-Connection Count/error handling

Using a perl script (Perl 5.8.6), I'm connecting to Sybase dataserver. Looking for the following: How many connections are currently opened by the script. Generic (non-dataserver specific) Error handling modules/mechanism When executing a stored proc, it returned the following error message. DBD::Sybase::st execute failed: Serve...

Problem with mixins in a MooseX::NonMoose class

Consider the following: package MyApp::CGI; use Moose; use MooseX::NonMoose; use Data::Dumper; extends 'CGI::Application'; BEGIN { print "begin isa = " . Dumper \@MyApp::CGI::ISA; }; print "runtime isa = " . Dumper \@MyApp::CGI::ISA; ... The output when this compiles is: begin isa = $VAR1 = [ 'Moose::Object' ...

How can I fetch a single count value from a database with DBI?

The following code seems to be just too much, for getting a single count value. Is there a better, recommended way to fetch a single COUNT value using plain DBI? sub get_count { my $sth = $dbh->prepare("SELECT COUNT(*) FROM table WHERE..."); $sth->execute( @params ); my $($count) = $sth->fetchrow_array; $sth->finish; ret...

How can I copy a file in Perl and maintain its timestamp?

I am using the File::Copy module to copy a file in Perl: #! /usr/bin/perl -w use File::Copy; copy("somefile.log", "copiedfile.log"); I would like to preserve timestamps (particularly the modification time), but this doesn't appear to be an option. Is there a straightforward way to achieve this without resorting to making a system ...

How can I debug my Net::SMTP Perl program?

Hello, I'm building a application that sends a test message to another email, the program executes without errors, but when I check my email there isn't any new email, take a look at my code: my $smtpserver = 'smtp.vix.terra.com.br'; my $smtpuser = 'nathanpc'; my $fromemail = '[email protected]'; my $smtp = Net::SMTP-> new($sm...

How to cancel output if $^I=".bak" already exists?

In Perl, I'm looping over files using the common pattern: $^I=".bak"; while(<>) { s/pattern/replacement/g; print; } where $^I will create backups. However, I want to test if the backup file exists and cancel the script if it does, so the back up isn't overwritten. It has to be explicitly removed. The problem is that outside the...

Why doesn't my Perl match operator match anything?

I'm new to Perl and playing around screen scraping and regex. I'm trying to extract the "title" name of the following HTML block: ... title="The Valley Downs Chicago"><img class="vimg120" ... My simple Perl code to do so is: @htmlBlocks = split ("margin-bottom:20px",$content); foreach $item (@htmlBlocks) { if (/\stitle="([^"]*)"/six)...

What is the future of Class::DBI?

Does anyone know what is the status of Class::DBI? I see that it was last updated on 4 October 2007, is anyone still working on this project or is it just left to die? Thank you. ...