perl

Is PHP or vanilla Perl CGI faster?

I'm developing a web app for an Apache shared hosting server. I have already written some code in Perl but I recently found out, to my surprise, the shared hosting provider does not provided mod_perl or a way to install it. I have been a bit worried that running a Perl web app through CGI without mod_perl would make it very slow? Shou...

Is there a cron-like service written in Perl?

I am mulling over a web-app in Perl that will allow users to create bug monitors. So essentially each "bug watch" will be a bug ID that will be passed to a sub routine along with the "sleep" time, and once the the "sleep time" is over it must recur without blocking the parent process or the peer processes. I tried Schedule::Cron. It s...

What's the best way to write a Perl CGI application?

Every example I've seen of CGI/Perl basically a bunch of print statements containing HTML, and this doesn't seem like the best way to write a CGI app. Is there a better way to do this? Thanks. EDIT: I've decided to use CGI::Application and HTML::Template, and use the following tutorial: http://docs.google.com/View?docid=dd363fg9_77gb4...

How can I use Template Toolkit on a string instead of a file?

I have some strings that I am pulling out of a database and I would like to use Template Toolkit on them, but I can't seem to figure out how to use strings as TT input. Any tips? Thanks! -fREW ...

How can I read from an IO::Socket::INET filehandle only if there is a complete line?

When reading from a IO::Socket::INET filehandle it can not be assumed that there will always be data available on the stream. What techniques are available to either peek at the stream to check if data is available or when doing the read take no data without a valid line termination and immediately pass through the read? ...

How can I create multidimensional arrays in Perl?

Hello, I am a bit new to Perl, but here is what I want to do: my @array2d; while(<FILE>){ push(@array2d[$i], $_); } It doesn't compile since @array2d[$i] is not an array but a scalar value. How sould I declare @array2d as an array of array? Of course, I have no idea of how many rows I have. ...

How do I reference a scalar in a hash reference in Perl?

Simple question: How do I do this on one line: my $foo = $bar->{baz}; fizz(\$foo); I've tried \$bar->{baz}, \${$bar->{baz}}, and numerous others. Is this even possible? -fREW Update: Ok, the hashref is coming from DBI and I am passing the scalar ref into template toolkit. I guess now that I look more closely the issue is somethin...

What's the best way to open and read a file in Perl?

Edit on 11/26 - Please note - I am not looking for the "right" way to open/read a file, or the way I should open/read a file every single time. I was just interested to find out what way most people use, and maybe learn a few new methods at the same time :) A very common block of code in my perl programs is opening a file and reading o...

What do these Perl/Tk errors from Tk::After mean?

Here are the errors: $ perl ftper.pl Use of uninitialized value $id in hash element at /usr/lib/perl5/vendor_perl/5.1 /i686-cygwin/Tk/After.pm line 39. se of uninitialized value $id in hash element at /usr/lib/perl5/vendor_perl/5.1 /i686-cygwin/Tk/After.pm line 39. se of uninitialized value $id in hash element at /usr/lib/perl5/vendor_...

How do I determine the character set of a string?

I have several files that are in several different languages. I thought they were all encoded UTF-8, but now I'm not so sure. Some characters look fine, some do not. Is there a way that I can break out the strings and try to identify the character sets? Perhaps split on white space then identify each word? Finally, is there an easy ...

What should I teach a beginning Perl programmer?

I am going to spend 30 minutes teaching Perl to an experienced programmer. The best way to learn Perl is by writing code. In addition to CPAN, what would you show a programmer so they would understand the expressiveness of Perl, the amount of functionality provided by CPAN, while keeping everything clean and tidy so they walk away comf...

Is Lua, Perl, Python, or Ruby better suited for Unix system automation?

I am starting a new project to provide monitoring and control services for a number of unix (Linux and FreeBSD) servers (think munin, monit, mrtg, etc). The reason I'm not considering using an already existing monitoring solution is that I need to do checks for custom APIs (like post a specific HTTP request and parse the answer body for ...

How can I make log4perl output easier to read?

When using log4perl, the debug log layout that I'm using is : log4perl.appender.D10.layout=PatternLayout log4perl.appender.D10.layout.ConversionPattern=%d [pid=%P] %p %F{1} (%L) %M %m%n log4perl.appender.D10.Filter = DebugAndUp This produces very verbose debug logs, for example: 2008/11/26 11:57:28 [pid=25485] DEBUG SomeModule.pm (33...

Found unexpected <Submission> inside <<<<ROOT>>>>. This is not a valid child element

I am trying to validate xml file against schema using XML::Validator::Schema. But it gives me this error: Found unexpected <Submission> inside <<<<ROOT>>>>. This is not a valid child element. [Ln: 2, Col:119] Note: <Submission> is the very first element I have after <xml version="1.0" encoding="UTF-8"?> I can't figure out what it ...

Is there a Perl module that validates an XML against a schema?

I need to validate an XML agaist a schema. I tried XML::SAX::ParserFactory; XML::Validator::Schema and related modules but looks like they are limited. Limited in the sense that it didn't recognize schema elements such as xsd:unique, xsd:group, xsd:keyref, xsd:union and xsd:key. Are these xsd:unique, etc. new additions? Appreciate...

Why does this Perl BEGIN block act differently in the debugger?

I have some Perl code that runs fine outside the debugger: % perl somefile.pl but when I run it inside the debugger: % perl -d somefile.pl it behaves differently. The files in question (there are several) are part of the test suite for a large Perl module (~20K lines of code). The tests do a lot of setup work at compile time and ...

How do I add elements from one Perl array that aren't already in the other array?

Given: my @mylist1; push(@mylist1,"A"); push(@mylist1,"B"); push(@mylist1,"C"); my @mylist2; push(@mylist2,"A"); push(@mylist2,"D"); push(@mylist2,"E"); What's the quickest way in Perl to insert in mylist2 all elements that are in mylist1 and not already in mylist2 (ABCDE). ...

Scripting language choice for initial performance

I have a small lightweight application that is used as part of a larger solution. Currently it is written in C but I am looking to rewrite it using a cross-platform scripting language. The solution needs to run on Windows, Linux, Solaris, AIX and HP-UX. The existing C application works fine but I want to have a single script I can maint...

How can I make this Perl one-liner to toggle character in line in a file?

I am attempting to write a one-line Perl script that will toggle a line in a configuration file from "commented" to not and back. I have the following so far: perl -pi -e 's/^(#?)(\tDefaultServerLayout)/ ... /e' xorg.conf I am trying to figure out what code to put in the replacement (...) section. I would like the replacement to inser...

How can I find the newest created file in a directory?

Is there an elegant way in Perl to find the newest file in a directory (newest by modification date)? What I have so far is searching for the files I need, and for each one get it's modification time, push into an array containing the filename, modification time, then sort it. There must be a better way. ...