perl

What do I do after printing HTML in my Perl CGI script?

What should you call after printing HTML from a Perl CGI script? I have seen empty return statements, exit statements, and in some cases nothing at all. Does it matter? #!perl print "Content-type: text/html\n\n"; print <<'END_HTML'; <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1...

perl script to searches text file for a specific string and copies the whole line to a new file?

Hello, The main problem I'm having is that my script runs, opens the text file, finds the string, and copies it to a new file, but sometimes it doesn't copy the whole line. It gets cut off at different points in the line. I believe is a problem with my regex. A line of txt may look like this: E03020039: Unable to load C:\Documents...

How can I have DBIC persistent database connection in mod_perl?

I am using mod_perl for my web application. Currently, I plan to use a mysql database across the network. In every CGI request to display_customer_transaction.cgi, my script will Open up database connection across network Perform query on the database using SQL statement Analysis the data retrieved from database Print out the data in H...

Why would PDF::FromHTML behave differently when called from my web app?

I'm using PDF::FromHTML to generate a PDF from HTML(as the name of the module would imply) :) I'm able to run it from the command line fine and receive my expected output - however when I use the exact same code in my web app, the output doesn't look correct at all - text is appearing in the wrong places and not all of it is appearing. ...

Perl's diamond operator: can it be done in bash?

Is there an idiomatic way to simulate Perl's diamond operator in bash? With the diamond operator, script.sh | ... reads stdin for its input and script.sh file1 file2 | ... reads file1 and file2 for its input. One other constraint is that I want to use the stdin in script.sh for something else other than input to my own script. Th...

What’s the best way to discover all variables a Perl application has currently defined?

I am looking for best, easiest way to do something like: $var1="value"; bunch of code..... **print allVariablesAndTheirValuesCurrentlyDefined;** ...

How can I speed up Perl's readdir for a directory with 250,000 files?

I am using Perl readdir to get file listing, however, the directory contains more than 250,000 files and this results long time (longer than 4 minutes) to perform readdir and uses over 80MB of RAM. As this was intended to be a recurring job every 5 minutes, this lag time will not be acceptable. More info: Another job will fill the di...

How do I export Readonly variables with mod_perl?

I'm trying to make it easier to follow some Perl Best Practices by creating a Constants module that exports several of the scalars used throughout the book. One in particular, $EMPTY_STRING, I can use in just about every Perl script I write. What I'd like is to automatically export these scalars so I can use them without defining them ...

How can I get a character at a given index in Perl?

If I have a Perl string: $str = "Hello"; how can I get a character at a given index similar to charAt(index)? ...

How do I merge two FASTA files (one file with line break) in Perl?

I have two following Fasta file: file1.fasta >0 GAATAGATGTTTCAAATGTACCAATTTCTTTCGATT >1 GTTAAGTTATATCAAACTAAATATACATACTATAAA >2 GGGGCTGTGGATAAAGATAATTCCGGGTTCGAATAC file2.qual >0 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 15 40 40 >1 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40...

How can I delete characters between < and > in Perl?

I need to write a Perl script to read in a file, and delete anything inside < >, even if they're on different lines. That is, if the input is: Hello, world. I <enjoy eating bagels. They are quite tasty. I prefer when I ate a bagel to when I >ate a sandwich. <I also like >bananas. I want the output to be: Hello, world. I ate a sandwic...

How can I convert a function return value from reference to array?

I have this code in Perl: sub f { return [1,2,3] } print f; The function f returns reference to array, how can I convert returned value to array without additional variable, like here? sub f { return [1,2,3] } $a = f; print @$a; ...

How do I force a stack backtrace for all fatal errors in Perl?

In Perl, is there a way to force all fatal errors to display a stack backtrace like Carp::confess produces? I know you can do use warnings FATAL => 'all'; to make warnings fatal over the current lexical scope. Further it is possible to use $SIG{__WARN__} = sub { CORE::die(@_) }; to make all warnings fatal everywhere (that hasn't locali...

How can I detect recursing package calls in Perl?

I have a Perl project were I just had a problem by making a circular package call. The code below demonstrates the problem. When this is executed, each package will call the other until all of the memory of the computer is consumed and it locks up. I agree that this is a bad design and that circular calls like this should not be mad...

How can I write Perl that doesn't look like C?

My co-workers complain that my Perl looks too much like C, which is natural since I program in C most of the time, and Perl just a bit. Here's my latest effort. I'm interest in Perl that is easy to understand. I'm a bit of a Perl critic, and have little tolerance for cryptic Perl. But with readability in mind, how could the following co...

How do I output each Perl array element surrounded in quotes?

I want to output the elements of an array in a specific format in Perl. @myArray = ("A", "B", "C"); $text = something; Something should be the string '"A" "B" "C"' (each element enclosed in double quotes). However, if @myArray is empty, then $text should be too. I thought of using join(), such as $text = "\"" . join("\" \"", @myArra...

How do I replace a token with increasing numbers in Perl?

I want to replace a token in a text file with a number. The token is "<count>" and I want it to be replaced with the number of counts so far. For example: This <count> is a <count> count. The <count> count increases <count><count><count>. <count><count><count><count><count><count> becomes: This 1 is a 2 count. The 3 count increases 4...

Why won't my Perl function work?

I am having trouble with a function I wrote... sub TemplateReplace { my($regex, $replacement, $text) = @_; $text =~ s/($regex)/($replacement)/gs; } my $text = "This is a test."; TemplateReplace("test", "banana", $text); But it doesn't work. I thought arguments were sent by reference in Perl. Does the line my($regex, $replacem...

What are some good resources for learning the Perl port of Lucene?

For learning about the Perl port of Lucene, what are some good documents, resources, or books? As people note on CPAN, the documentation is a little lacking. On Amazon all I find is Lucene and Java, but I understand the port is fairly good. Is buying a Java or Lucene book the best approach? ...

Does a Perl module know where it is installed?

Hi Perl programmers, I have started creating a Perl package that contains a default email template. The MANIFEST looks something like: SendMyEmail.pm SendMyEmail/defualt_email.tt Currently I know where the module (and the template) are - but does the module itself know where on disk it is? So could the module find the default temp...