perl

How do I schedule one-time tasks from a Perl CGI application?

I am writing an application to allow users to schedule one-time long-running tasks from a web application (Linux/Apache/CGI::Application). To do this I use the the Schedule::At module which is the Perl interface to the "at" command. Since the scheduled tasks are not repeating, I am not considering "cron". I have two issues with "at" thou...

Why doesn't my Perl/Tk Scrolled actually scroll?

Hi All, The following code produces pretty much what I want, but the scrollable pane on the left doesn't scroll. I am using ActivePerl 5.8.9 Build 825: The code is: use Tk; use Tk::Pane; use Tk::LabFrame; # create the application window my $MW = MainWindow->new ( -background => "GREY" ); # set the x/y size for the window $MW->geomet...

What's the difference between single and double quotes in Perl?

In Perl, what is the difference between ' and " ? For example, I have 2 variables like below: $var1 = '\('; $var2 = "\("; $res1 = ($matchStr =~ m/$var1/); $res2 = ($matchStr =~ m/$var2/); The $res2 statement complains that "Unmatched ( before HERE mark in regex m". ...

How can I work around a round-off error that causes an infinite loop in Perl's Statistics::Descriptive?

I'm using the Statistics::Descriptive library in Perl to calculate frequency distributions and coming up against a floating point rounding error problem. I pass in two values, 0.205 and 0.205, (taken from other numbers and sprintf'd to those) to the stats module and ask it to calculate the frequency distribution but it's getting stuck i...

How can I use hashes as arguments to subroutines in Perl?

Hello, I have a function that is doing some calculations and then passes some properties into another subroutine like so: sub get_result { my $id = 1; my %diet = ( result => 28, verdict => 'EAT MORE FRUIT DUDE...' ); my %iq = ( result => 193, verdict => 'Profess...

How can I append characters to a line in a file?

I have a CSV file that was extracted from a ticketing system (I have no direct DB access to) and need to append a couple of columns to this from another database before creating reports off of it in Excel. I'm using Perl to pull data out of the other database and would like to just append the additional columns to the end of each line a...

Is it possible to execute multiple statements in a single query using DBD::Oracle?

I'd like to know if it's possible to execute more than one SQL statement within a single execute() or do() call using DBD::Oracle via Perl DBI. Example: # Multiple SQL statements in a single query, separated by a ";" $sql = 'UPDATE foo SET bar = 123; DELETE FROM foo WHERE baz = 456'; $sth = $dbh->prepare($sql); $sth->execute; # ...or...

Should I migrate from CGI.pm to CGI::Simple?

I just noticed CGI::Simple while looking something up for the CGI.pm module. Should I be using CGI::Simple instead? What will it offer me over CGI.pm, which I've used for eight years? I see that CGI::Simple doesn't do HTML generation; what should I be using for that? And will it integrate with CGI::Simple by allowing me to make form ...

How can I determine if the script is being executed within a system or qx call in Perl?

In Perl, is it possible to determine if a script is being executed within another script (presumably via system or qx)? $ cat foo.pl print "foo"; print "\n" if not $in_qx; # or the like. I realize this is not applicable if the script was being run via exec. I know for certain that system runs the process as a fork and I know fork c...

How can I do a global regular expression match in Perl?

I am trying to come up with a regular expression in Perl matching multiple patterns and returning all of them like preg_match_all in PHP does. Here's what I have: $str = 'testdatastring'; if($str =~ /(test|data|string)/) { print "its found index location: $0 $-[0]-$+[0]\n"; print "its found index location: $1 $-[1]-$+[1...

How do I refactor Perl code that uses Template Toolkit with DBI to take advantage of FastCGI?

Background Below is a typical piece of Perl code (sample.pl for the sake of discussion) that grabs submitted form data using CGI, passes the form data to DBI which will then retrieve the required rows from MySQL and then hands the results over to Template Toolkit to render into a HTML document for display. Code listing for sample.pl : ...

Parse::RecDescent - getting information from it.

Hi, I'm working with the Parse::RecDescent parser in Perl, and I seem to have the most terrible time getting information from it. The information readily available online does not seem to have non-trivial examples. Here is the code: event_function: object_list ':' event_list ';' <defer: { #item is a special character w...

sudoku obfuscated python -> perl translation

Anybody care to translate this into obfuscated perl? It's written in Python taken from: here def r(a):i=a.find('0');~i or exit(a);[m in[(i-j)%9*(i/9^j/9)*(i/27^j/27|i%9/3^j%9/3)or a[j]for j in range(81)]or r(a[:i]+m+a[i+1:])for m in'%d'%5**18] from sys import*;r(argv[1]) I realize it's just for fun :) ...

How can I fork a Perl CGI program to hive off long-running tasks?

I am writing a Bulk Mail scheduler controlled from a Perl/CGI Application and would like to learn abut "good" ways to fork a CGI program to run a separate task? Should one do it at all? Or is it better to suffer the overhead of running a separate job-queue engine like Gearman or TheSchwartz as has been suggested recently. Does the answer...

How can I search CSS with Perl?

Hi there, Longtime user/browswer, first time question-asker. I'm writing a Perl script that will go through a number of HTML files, search them line-by-line for instances of "color:" or "background-color:" (the CSS tags) and print the entire line when it comes across one of these instances. This is fairly straightforward. Now I'll ad...

How do I detect combination argument errors using Getopt::Euclid?

I'm being forced (by engineering policy) to use Getopt::Euclid to parse arguments to my Perl program. I have three arguments, foo, bar and blah. It is legitimate to have none of these and use other arguments instead. If foo is present than exactly one of bar or blah should be present, and if either bar or blah are present, than foo mu...

Is there a way to precompile a regex in Perl?

Is there a way to precompile a regex in Perl? I have one that I use many times in a program and it does not change between uses. ...

How can I use Perl to get a list of CSS elements with a color or background color attribute?

Hello, I asked a question earlier today regarding using Perl to search in a CSS document. I have since refined my requirements a little bit, and have a better idea of what I am trying to do. The document I am searching through is actually an .html doc with CSS as a style in the <head>, if that makes sense. Basically, what I need to d...

How can I strip block comments with Perl?

I am working on a preprocessor that is analyzing a DSL. My goal is to remove the comments. The block comment facility is demarcated by %% before and after. I do not have to worry about %% being in strings, by the definition of the language. I am using this s/// regex. Unfortunately, it seems to match everything and wipe it out: #Remove...

In Perl, how can I read an entire file into a string?

So I'm working on a server where I can't install any modules whatsoever. Yes this makes my job difficult. To complete the rest of my script I need to do something that I had thought would be fairly straightforward but it seems to be anything but. I'm trying to open an .html file as one big long string. This is what I've got: ope...