perl

How can I beta test web Perl modules under Apache/mod_perl on production web server?

We have a setup where most code, before being promoted to full production, is deployed in BETA mode - meaning, it runs in full production environment (using production database - usually production data; and production web server). We call that stage BETA testing. One of the main requirements is that BETA code promotion to production mu...

Nested dereferencing arrows in Perl: to omit or not to omit?

In Perl, when you have a nested data structure, it is permissible to omit de-referencing arrows to 2d and more level of nesting. In other words, the following two syntaxes are identical: my $hash_ref = { 1 => [ 11, 12, 13 ], 3 => [31, 32] }; my $elem1 = $hash_ref->{1}->[1]; my $elem2 = $hash_ref->{1}[1]; # exactly the same as above ...

Perl Script in PHP

I have a perl script, which takes a query string parameter, connects to a database and displays data. I'd like to include that script in a PHP file like so: include('perlscript.pl?item=302'); Such that the perl script's response is displayed on the PHP/HTML page. How can I do this? ...

How can I use Perl to send and HTTP request with a cookie?

I am new to Perl and I want to write a Perl program that: creates an HTTP request sends it to any URL (e.g. http://www.google.com ) includes a cookie in the request logs the http response codes in a file I have tried this: #!/usr/bin/perl require HTTP::Request; require LWP::UserAgent; $request = HTTP::Request->new(GET => 'http:...

How can I recursively read out directories in Perl?

Hi, I want to read out a directory recursively to print the data-structure in an HTML-Page with Template::Toolkit. But I'm hanging in how to save the Paths and Files in a form that can be read our easy. My idea started like this sub list_dirs{ my ($rootPath) = @_; my (@paths); $rootPath .= '/' if($rootPath !~ /\/$/); ...

How can I generate HTML tables in Perl?

I need to create a 2 tables in HTML format. Each has 5 rows: 1st Table 1st row has FRUITS in it, occupying all columns 2nd row has January(month), occupying all columns 3rd row has names of some 6 fruits (apple, orange, grapes,...)These names do not change. so this row has 6 columns 4th row has rates for each fruit ( 10,20,30..) so th...

What does Perl's -p command-line switch do?

perl -p -i.bak -e 's/search_str/replace_str/g' filename here what is -p -i.bak /s and /g ...

What is the right way to stop an infinite while-loop with a Term::Readline-readline?

What is the right way to stop an endless while-loop with a Term::Readline::readline? This way I can not read in a single 0 #!/usr/bin/env perl use warnings; use strict; use 5.010; use Term::ReadLine; my $term = Term::ReadLine->new( 'Text' ); my $content; while ( 1 ) { my $con = $term->readline( 'input: ' ); last if not $con;...

How do I write Perl object with plugins?

How do I write Perl objects with extensible code? Im thinking drivers, or some configuation, where the user can pass in a string "Classname::Class" or something. Thanks. For example, for a graph class: my $spg = Graph::ShortestPathGraph->new; $spg->Algorithm( "Graph::DFS" ); $spg->solve; $spg->Algorithm( "Graph::BFS" ); $spg->solve;...

How can I print only certain fields in a space separated file?

I have a file containing the following content 1000 line in the following format: abc def ghi gkl How can I write a Perl script to print only the first and the third fields? abc ghi ...

How can I read piped input in Perl on Windows?

I am trying to create something in Perl that is basically like the Unix tee command. I'm trying to read each line of STDIN, run a substitution on it, and print it. (And eventually, also print it to a file.) This works if I'm using console input, but if I try to pipe input to the command it doesn't do anything. Here's a simple example: ...

Do perl threads have the same advantage as kernel threads?

Kernel threads do context switch at kernel level instead of process level. I am planning to set up an httpserver in perl. I want to know if perl threads have same advantage as kernel threads from the perspective of context switch. ...

In Perl, is a while loop generally faster than a for loop?

I've done a small experiment as will be shown below and it looks like that a while loop is faster than a for loop in Perl. But since the experiment was rather crude, and the subject might be a lot more complicated than it seems, I'd like to hear what you have to say about this. Thanks as always for any comments/suggestions :) In the fo...

How can I create columnar output in Perl?

Hello! #!/usr/bin/env perl use warnings; use strict; my $text = 'hello ' x 30; printf "%-20s : %s\n", 'very important text', $text; the output of this script looks more ore less like this: very important text : hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hello hel...

How can I store an inventory using Perl hashes?

For an assignment in college, we have to make a script in Perl that allows us to manage an inventory for an e-store. (The example given was Amazon). Users can make orders in a fully text-based environment and the inventory must be updated when an order is completed. Every item in the inventory has 3 to 4 attributes: a product code, a ti...

How does Perl's grep function work with a regex?

Hi, How does the following grep function works (what does !/0o1Iil]/ do? ) @chars = grep !/0o1Iil]/, 0..9, "A".."Z", "a".."z"; use Data::Dumper; print Dumper @chars; to produce the following in @chars? $VAR1 = 0; $VAR2 = 1; $VAR3 = 2; $VAR4 = 3; $VAR5 = 4; $VAR6 = 5; $VAR7 = 6; $VAR8 = 7; $VAR9 = 8; $VAR10 = 9; $VAR11 = 'A'; $VAR1...

Which dynamic language can easily use libraries from other languages?

Tell why you think Python, Perl, Ruby, etc is easiest for plugging in modules from other languages with minimal thought. To clarify, an example: I want to write business logic in Python, but use functionality that conveniently exists as a Perl module. In other words, which language "just works" with the most modules? ...

How can I build something like Amazon S3 in Perl?

I am looking to code a file storage application in perl similar to amazon s3. I already have a amazon s3 clone that I found online called parkplace but its in ruby and is old also isn't built for high loads. I am not really sure what modules and programs I should use so id like some help picking them out. My requirements are listed below...

Is there a regular expression to remove a trailing slash in Perl?

I would like to remove a trailing slash from a string. For example if i have a string called $test = "test/". How would I remove the slash at the end? ...

How can I get approximate time passed since some timestamp?

Is there any useful module on CPAN that returns number of biggest fractions of date interval, i.e. return integer number of years/months/days/hours/minutes/seconds between two dates, to use in sentence like "N days ago" or "M months ago" ...