perl

How do I know how many rows a Perl DBI query returns?

I'm trying to basically do a search through the database with Perl to tell if there is an item with a certain ID,. This search can return no rows, but it can also return one. I have the following code: my $th = $dbh->prepare(qq{SELECT bi_exim_id FROM bounce_info WHERE bi_exim_id = '$exid'}); $th->execute(); if ($th->fetch()->[0] != $ex...

How do I implement 'tail -f' with timeout-on-read in Perl?

My question is the antithesis of How do I process input immediately instead of waiting for newline. I want to continue reading a growing log file, but stop after the file has not grown for a specified number of seconds. I found Sys::AlarmCall at CPAN, and tried as shown below, but it doesn't time-out when I run: perl progress.tracker....

Can I have regular parameters along with CGI::Application::Dispatch?

I appreciate the ability to be able to do: http://server/controller/runmode or even http://server/controller/runmode/id. But if I have a lot of optional parameters I'd like to be able to do the regular: http://server/controller/runmode?foo=bar&baz=frew, especially since I have a lot of JS that will do the latter for me. Does anyone...

How do I have a persistent DBIx::Class in CGI::Application with mod_perl?

I am using CGI::Application on mod_perl with DBIx::Class and I'd like to have something like new define a new dbic schema on instantiation. So far I haven't been able to get it to work. The closest thing I have come to is a superclass that has a connect() method that returns a new object, but I would rather it be already be connected...

How do I have mod_perl reload source files on change?

I am developing an application with mod_perl and restarting the server every time I change code is a huge drag. I'd like to still use mod_perl for development because it's what I plan on using for the live server. I didn't see anything in the documentation about how to do this. Thoughts? ...

How can I extract external referrers from an Apache access log with Perl?

I need some help getting a regex working to parse all referrers from an apache access log file which come from real links offsite and which are valid referrals from real people rather than bots or spiders. I'm working in Perl. This bit of code almost works already [the access log is opened with the filehandle $fh]: my $totalreferals = ...

How can I download a list of users from an LDAP server using Perl?

I want to upload a list of users from my work's LDAP server to upload into our wiki as a company directory. How can I download a list of users from an LDAP server using Perl? Thanks. ...

How do I use a Perl package known only in runtime?

Hi, I have a Perl program, that needs to use packages (that I also write). Some of those packages are only chosen in Runtime (based on some environment variable). I don't want to put in my code a "use" line for all of those packages, of course, but only one "use" line, based on this variable, something like: use $ENV{a}; Unfortunatel...

What can make Class::Loader fail where "use" and "new" do not?

I'm working on a very large CGI application that uses Crypt::RSA, which is properly installed. I get a "attempted to call a null reference as a function" type of error (I can't go back to get the exact error right now because we had to rollback for a release date) when I try to run any the embedded library. I trace the null reference t...

How can I rotate log files monthly using Perl?

In Unix, I need to be able to archive log files into monthly folders, labelled accordingly. How do I do this in Perl? ...

How can I pass command-line arguments via file association in Vista 64?

How can one pass command line arguments via file association in Vista 64? I recently built a PC running Vista Ultimate 64-bit. I noticed several of the Perl scripts I transferred failed due to command-line arguments not being passed. As a simple test, I wrote the following (foo.pl): #!/usr/bin/perl -w use strict; my $num_args = $#ARG...

What would cause Perl to dump core?

What are the most common reasons that I would be getting this error from running a Perl script: Memory fault(coredump) I am running two SQL commands beforehand that only store ~1500 rows each with 6 fields. The SQL works fine out of the script, so I don't think I'm getting the error from that. And half of my code runs before it takes ...

How do I cleanup at request end in Catalyst?

I'm trying to get some code called after each request completes using Catalyst. Basically, I want to run some code as part of finalize. Supposedly Catalyst::Plugin::Observe will do this, but it appears completely broken (just loading the plugin breaks Catalyst). I'm trying to fix the Observe plugin, but that's proving stubborn. So, is ...

How do I clear the read-only flag from a file in Perl?

Hi, I need to clear the read-only flag of a file in my Perl program that runs on Windows. I know system("attrib -r $filename") would work, but I was wondering if there is no built-in option in Perl to do it. chmod 777, $filename doesn't seem to work. Thanks, splintor ...

How can I deploy a Perl/Python/Ruby script without installing an interpreter?

I want to write a piece of software which is essentially a regex data scrubber. I am going to take a contact list in CSV and remove all non-word characters and such from the person's name. This project has Perl written all over it but my client base is largely non-technical and installing Perl on Windows would not be worth it for them. ...

What's the right way to display a DBIx::Class ResultSet in my Catalyst project that uses Template Toolkit?

Given a DBIx::Class resultset, for example: my $rs = $c->model("DB::Card")->search({family_name => "Smith"}); the tutorials I've read use the stash to pass an arrayref of rows: $c->stash->{cards} = [$rs->all]; This results in the query getting executed at this point, and the resulting objects stuffed into the stash, so they can be ...

How can I remove middle initial with a dot at the end?

I've got a bunch of first names in a field that carry a middle initial with a '.' at the end..I need a regex to convert this example:Kenneth R.intoKennethI was trying to build my own and found this useful site btw..http://www.gskinner.com/RegExr/but I'm new to Perl & regular expressions and could only get "...$" - which is useless when t...

How do I check the exit code in Test::More?

According to Test::More documentation, it will exit with certain exit codes depending on the out come of your tests. My question is, how do I check these exit codes? ps. I am trying to build a harness myself. Is there a simple harness I can use? ps2. Test::Harness did the trick for me. In particular execute_tests function. This functio...

How can I use awk or Perl to increment a number in a large XML file?

I have an XML file with the following line: <VALUE DECIMAL_VALUE="0.2725" UNIT_TYPE="percent"/> I would like to increment this value by .04 and keep the format of the XML in place. I know this is possible with a Perl or awk script, but I am having difficulty with the expressions to isolate the number. ...

What's the difference between an object and a class in Perl?

I'm having a little trouble getting my head around the conceptual difference between an object and a class. I don't really understand the distinction between the two in any programming language, but currently I'm working with Perl, and Moose, so I'd prefer an explanation using those things. Cheers ...