perl

How can I install several CPAN distributions at once?

I have recently started some Perl development and use CPAN to install all my packages. I was wondering if there are some "best practices" to manage required packages for a script or application. So far, I'm doing it the inelegant and cumbersome way. I have a script which looks like this : install Foo::Bar install Zulu::Car ... and the...

How can I inheriting from a concrete class in Perl?

Our software represents each device as a concrete class. So let's say I have a class named Cpu-Version-1, which is derived from a abstract baseclass called Device. Now, the CPU vendor wants to release the economic version of this CPU ( Cpu-Version-2 ), which is a feature reduced version of Cpu-Version-1 (obviously for a lower price ). 90...

How can I automate a series of tests in Perl?

i, I have to run about a 100 tests on my program and doing it one-by-one is killing my time bad so I am looking to write a script. I write an individual test like so ./program test_1 > out_1 and then compare it to the output that I am looking for like so diff -urpb expected_out_1 out_1 > diff_1 Can somebodyhelp me to write a short P...

How can I write a Perl script that generates a new log file each time it's run?

I am trying to modify a Perl script to create a different/new log file each time I run the script. I was trying to create each log file by date, but I am having trouble incorporating this concept... This is what I have so far: #!perl -w use WWW::Mechanize; # What URL shall we retrieve? $url = "http://www.mediabase.com/whatsong/whats...

Accessing Array Elements of Referenced Array

I am new to Perl. I wrote a snippet to access array elements and print it to the console: use strict; use warnings; my @array1 = ('20020701 00000', 'Sending Mail in Perl', 'Philip Yuson'); my @array2 = ('20020601', 'Manipulating Dates in Perl', 'Philip Yuson'); my @array3 = ('20020501', 'GUI Application for CVS', 'Philip Yuson'); my @...

How can I use JSON and Perl (HTML::Mason) to create dynamic web page with AJAX?

Hi everyone, I'm some kind of lost with the way i have to deal with Javascript, JSON and Perl and most of the examples are in PHP which is not helpfull for me. I have a page (called main.html) where i have a with data from MySQL and i have an option to delete a row by id. Then i have the Javascript sending the id to page apagar.html ...

How can I print the SQL query executed after Perl's DBI fills in the placeholders?

I'm using Perl's DBI module. I prepare a statement using placeholders, then execute the query. Is it possible to print out the final query that was executed without manually escaping the parameters and dropping them into the placeholders? Thanks ...

What does SIGPIPE in this situation mean?

I have the following script structure: script A opens PIPE on B, and B opens PIPE on C. So the dataflow is A->B->C. B catches SIGPIPE. Though descriptors IN and OUT are opened: $SIG{'PIPE'} = sub { $logger->info('caught PIPE signal.'); $logger->info("STDIN status: ".STDIN->opened()); $logger->info("STDOUT status: ".OUT->opened()); die; ...

How can I access the commited file from a Subversion pre-commit hook in Perl?

I need to do the following: Write pre-commit hook in Perl Hook should check all files being committed for presence of some text, and fail if that text is not found Basically, I need an example of Perl hook that reads files being committed. I am really looking for some elegant solution with the least amount of code. Notes: Hook sho...

Code documentation style guidelines for Perl?

Does anyone know of a perlstyle-like guideline for how to document Perl code? Like this bit from javadoc guidelines: "Gets the label of this button.       (preferred)" vs. "This method gets the label of this button.       (avoid) " (from http://java.sun.com/j2se/javadoc/writingdoccomments/). I haven't found anything at perlstyle...

How do I find the current value of a processes STDOUT in Perl?

I have a POE Perl program forking children. The children it is forking do logging and interactive telnets into remote devices. POE uses STDOUT to return output back up to the parent process but for some reason it's getting lost (not going to screen or to any files). I'm theorising that this is because STDOUT is being redirected somewhe...

Perl equivalent of (Postgre)SQL BETWEEN operator?

Is there such a thing? The equivalent of a <= expr <= b, or in SQL parlance expr BETWEEN a AND b, where expr is evaluated only once? Or is asking for this just getting silly? ...

How can I tell CPAN::Shell to install all dependencies for a module?

I currently have this on a script: CPAN::Shell->rematein("notest", "install", "$m"); Where $m is a module name the script installs. However, I want the module to install without prompting the user whether additional dependencies should be installed (optional deps or not), how can I do that? ...

Why is a threaded version of this particular Perl script 200 times slower than its non-threaded counterpart?

A presentation by Mikhael Goikhman from a 2003 Perl conference includes a pair of examples of prime-number-finding scripts. One is threaded, and the other is not. Upon running the scripts (print lines commented out), I got an execution time of 0.011s on the non-threaded one, and 2.343 (!) seconds on the threaded version. What accounts fo...

Creating a Cocoa app using C or Perl (NOT Objective-C)

I'm having a hard time understanding how to use Cocoa with either C or Perl. Background: I've seen it mentioned in quite a few places that Mac's Cocoa API can be used with C, Perl etc. but I haven't found any information on how to go about doing this. I've also found a couple of articles saying that Cocoa can be used with Objective-C on...

How can I find the contents of a div using Perl's HTML modules, if I know a tag inside of it?

Ever since I asked how to parse html with regex and got bashed a bit (rightfully so), I've been studying HTML::TreeBuilder, HTML::Parser, HTML::TokeParser, and HTML::Elements Perl modules. I have HTML like this: <div id="listSubtitlesFilm"> <dt id="a1"> <a href="/45/subtitles-67624.aspx"> .45 (2006) </a> </dt> </div> ...

Getting names of directories under given path

I am trying to get the names of all first level directories under given path. I tried to use File::Find but had problems. Can someone help me with that? ...

Atomic file save on Linux without losing metadata

I'm working on a Perl-based file synchronization tool. It downloads files into a temporary directory (which is guaranteed to be on the same filesystem as the real file) and then moves the temporary files into place over the old ones, preserving metadata like permissions, ownership, and ACLs. I'm wondering how to achieve that last step ...

How do I make Perl scripts recognize parameters in the Win32 cmd console?

When I invoke my Perl scripts in the Windows environment without invoking perl first, the parameters are not passed to my script. For example, C:\> C:\my-perl-scripts\foo.pl bar invokes foo.pl but doesn't recognize bar as a parameter (@ARGV is empty). However, C:\> perl C:\my-perl-scripts\foo.pl bar works as expected. Is this a ...

How can I do a conditional substitution in Perl?

I am trying to convert as following: bool foo(int a, unsigned short b) { return pImpl->foo(int a, unsigned short b); } to: bool foo(int a, unsigned short b) { return pImpl->foo(a, b); } In other words, I need to remove the type definition on the lines which are not the function definition. I am using Linux. The following ...