perl

What are the best-practices for implementing a CLI tool in Perl?

I am implementing a CLI tool using Perl. What are the best-practices we can follow here? ...

Parsing a Gmail-style advanced search syntax?

I want to parse a search string similar to that provided by Gmail using Perl. An example input would be "tag:thing by:{user1 user2} {-tag:a by:user3}". I want to put it into a tree structure, such as {and => [ "tag:thing", {or => [ "by:user1", "by:user2", ]}, {or => [ {not => "tag:a"}, "by:use...

How do I create or test for NaN or infinity in Perl?

How do I create or test for NaN or infinite values in Perl? ...

How do I preserve localtime() as an int when printing?

I'm trying to append the integral return value of localtime (in Perl) but I can't seem to avoid it converting the return val to something that looks like this: Sun Jul 26 16:34:49 2009 When I say print localtime I see what I want, but when I say $foo = localtime,""; print $foo; I get the string. I want those digits. I tried $foo = local...

Is there a way to use Acrobat Reader in Perl to save multiple PDF files as HTML files?

Hello everybody, I am using Xpdf for extracting text from PDF files which works well with -raw option, but now we want to convert the PDF files to HTML files for extracting the HTML formating tags like bold <b>, italics <i> etc with the text. Xpdf with the -html option does work, I have also tried using pdf2html for this but did not fin...

How can I sort a dd/mm/yyyy formatted date by month using Perl?

I have a list of dd/mm/yyyy dates stored in a hash that I need to sequentially print out in order of date by month. Here is the relevant excerpt. use feature 'say'; for my $date (sort {$a cmp $b} keys %data) { say $date; } This outputs: 16/07/2008 16/08/2008 16/09/2008 17/07/2008 17/08/2008 17/09/2008, etc. when what I need is...

How do I factor integers using Perl?

I want split integers into their factors. For example, if the total number of records is: 169 - ( 13 x 13 times) 146 - ( 73 x 2 times) 150 - ( 50 x 3 times) 175 - ( 25 x 7 times) 168 - ( 84 x 2 ) 160 - ( 80 x 2 times) When it's more than 10k - I want everything on 1000 When it's more than 100k - I want everything on 10k In this w...

How do I check if a key exists in a hash in Perl?

I want to check if parameter $PGkey is equal to a key with the same name inside a hash table. Further, I want to do it in a format as close to this as possible: while(<PARAdef>) { my($PGkey, $PGval) = split /\s+=\s+/; if($PGkey == $hash{$PGkey}) { print PARAnew "$PGkey = $hash{$PGkey}->[$id]\n"; } else { pri...

How can I automate an existing instance of Internet Explorer using Perl?

I am struggling to get control of an IE preview control which is 'Internet Explorer_Server' class on an external windows application with perl. Internet Explorer_Server is the class name of the window, I've found it with Spy++. and here’s my assertion code of it $className = Win32::GUI::GetClassName($window); if ($className eq "Inter...

Is there a way to package my unit tests with PAR or PerlApp?

I have an app that I pack into "binary" form using PerlApp for distribution. Since my clients want a simple install for their Win32 systems, this works very nicely. Now a client has decided that they need to run all unit tests, like in a standard install. However, they still will not install a normal Perl. So, I find myself in need...

Why am I not able to query a database from a forked child in Perl?

I have tried with Perl fork manager and DBI . But i got the error DBD::mysql::st execute failed: Lost connection to MySQL server during query . Here the sample code: I want make query between low to high value (i have spitted int 10k records) use Parallel::ForkManager; my $pm = new Parallel::ForkManager(50); my $db = krish::DB->new or...

Which Perl session management library works well with TemplateToolkit?

I've considered CGI::Application and CGI::Session. Of the two, CGI::Session seems more promising. CGI::Application model, however, doesn't look like it would work well with Template Toolkit. (Am I wrong to think so?) I would like to evaluate more session management libraries, before comitting to one. Any recommendations? I'm looking for...

Mapping values with Column header and row header

Hi, I have some files with below data. sample File 1: sitename1,2009-07-19,"A1",11975,17.23 sitename1,2009-07-19,"A2",11,0.02 sitename1,2009-07-20,"A1",2000,17.23 sitename1,2009-07-20,"A2",538,0.02 I want to map the values in column 4 with column 2 and 3 as shown below. Output required. Site,Type,2009-07-19,2009-07-20 sitename1,"A...

What is the simple way to keep the output stream exactly as it shown out on the screen (while interactive data used) ?

Hello friends, Let's say I have the following simple script: print "ID : "; $ID = <>; system (`comp program $ID`); exec "task --shell"; When I use: perl foo.pl | tee log.txt The showing up problem is getting on screen a blink sign echo (waiting for the ID enter) before I even see the "ID : " (print instruction). I need to keep on ...

Should I avoid nested if statements in Perl?

Hi, I'm doing some Perl and seeing my nested "if" statements is driving me mad. I managed to reduce some of them with guard blocks in another section, but I'm stuck here. Do you think I may leave the code as is, or is there a "proper" way to refactor the following ? (I also admit being relatively new to Perl) This is actually a subro...

What's the difference between ignoring a signal and telling it to do nothing in Perl?

If I tell Perl to explicitly ignore a signal, SIGINT has no effect: $SIG{INT} = 'IGNORE'; my $count = 0; say $count++ and sleep 1 while 1; Then pressing Control-C, rather obviously, has no effect. If, on the other hand, I tell it to do nothing: $SIG{INT} = sub { }; my $count = 0; say $count++ and sleep 1 while 1; Then pressing Cont...

Using Perl, how can I replace all whitespace in a file with newlines?

For example text file: Speak friend and enter using a Perl script to remove whitespace and replace with carriage-return Speak friend and enter ...

How can a Perl script detect if it is running within the Komodo IDE?

One way I found is to check if the Perl Debugger is "loaded" by checking for defined($DB::single) and assuming Komodo is active, if $DB::single is defined.. But this might also mean the script is legitimately running as perl -d under the "standalone" debugger. #!/usr/local/ActivePerl-5.10/bin/perl use strict; use warnings; use feature...

Perl compared to Java

For programming tasks that need to be developed quick how does Perl compare to Java? How about as far as speed, would Perl be much slower than Java? Whenever I need to program something quick I use Java. All the available libraries and built in goodness make Java pretty nice in my eyes. But there's a lot of people that swear by perl. In...

PerlEmbed - C# - Mono - Linux

Has anyone attempted using perlembed in Mono on Linux? Here is the link: perlembed Here is my first attempt at the DllImport signatures: private const string PERL_LIB = "/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE/libperl.so"; [DllImport(PERL_LIB, EntryPoint = "perl_alloc", SetLastError = true)] public static extern IntPtr Allo...