perl

How do I conditionally compile C code snippets to my Perl module?

I have a module that will target several different operating systems and configurations. Sometimes, some C code can make this module's task a little easier, so I have some C functions that I would like to bind the code. I don't have to bind the C functions -- I can't guarantee that the end-user even has a C compiler, for instance, and it...

How can I check if a value is numeric, alphabetical or alphanumeric in Perl?

I have array which values are user input like: aa df rrr5 4323 54 hjy 10 gj @fgf %d Now I want to check each value in array to see whether it's numeric, alphabetic (a-zA-Z), or alphanumeric and save them in other respective arrays. I have done: my @num; my @char; my @alphanum; my $str =<>; my @temp = split(" ",$str); fore...

How can I compare arrays in Perl?

I have two arrays, @a and @b. I want to do a compare among the elements of the two arrays. my @a = qw"abc def efg ghy klm ghn"; my @b = qw"def ghy jgk lom com klm"; If any element matches then set a flag. Is there any simple way to do this? ...

How do I use Perl's localtime with print to get the timestamp?

I have used the following statements to get the current time. print "$query executed successfully at ",localtime; print "$query executed successfully at ",(localtime); print "$query executed successfully at ".(localtime); Output executed successfully at 355516731103960 executed successfully at 355516731103960 executed succes...

How can I use Math::Business::EMA with DBI to calculate exponential moving averages in Perl?

Script pulls data from mysql: $DBI::result = $db->prepare(qq{ SELECT close FROM $table WHERE day <= '$DATE' ORDER BY day DESC LIMIT $EMA }); $DBI::result->execute(); while($row = $DBI::result->fetchrow) { print "$row\n"; }; with the following example results: 1.560 1.560 1.550... But I need to work out ...

What's the proper way to fork() in FastCGI ?

I have an app running under Catalyst+FastCGI. And I want it to fork() to do some work in background. I used this code for plain CGI long ago (and it worked): defined(my $pid = fork) or die "Can't fork: $!"; if ($pid) { # produce some response exit 0; } die "Can't start a new session: $!" if setsid == -1; close STDIN o...

How can get a filehandle for a Perl program's output?

I have an encrypted file X1, I have a Perl program P1 that decrypts the X1. I am parsing the decrypted file using a Perl program p2. X1--P1(decrypter) --> X2(plain text file) --p2(parser) --> parse output My parser is based on XML::Parser. It can work with a filehandle to the decrypted file. Now I am getting the X2 and storing it in t...

What are the disadvantages of the Perl Tk module?

What are the disadvantages of the Tk module compared to other solutions to create a GUI in Perl? ...

How does Perl's lib pragma work?

I use use lib "./DIR" to grab a library from a folder elsewhere. However, it doesn't seem to work on my server, but it works fine on my local desktop. Any particular reasons? And one more question, does use lib get propagated within several modules? Two situations: Say I make a base class that requires a few libraries, but I know that...

Running Java, Python, Ruby and Perl programs in .NET

I've .NET framework 3.5 installed in my laptop. Just .NET alone, no Visual Studio. How can I run Java, Python, Ruby and Perl programs from the console? Do I need to install something else also, for running these language files? In case there is a need for something extra to be installed and after i have all of them, what are the comma...

Is it good practice to export variables in Perl?

I'm finding it very convenient to pass configuration and other data that is read or calculated once but then used many times throughout a program by using Perl's use mechanism. I'm doing this by exporting a hash into the caller's namespace. For example: package Myconfiguration; my %config; sub import { my $callpkg = caller(0); ...

Is there any way to read MATLAB's .mat files in Perl?

I have some data generated in MATLAB that I want to process using Perl. I saved the data from MATLAB in a .mat file. Is there any way to read it in Perl? ...

Which POSIX flavor of regex does Perl use?

Specifically, I'm using the Linux command: $ find . -regextype posix-extended -regex '<some regex>' ... I just want to make sure the POSIX type I'm using is the type Perl uses, since that is by far the one I am most familiar with. ...

Porting Perl to Python.

I am wondering if there are any tips or tricks to converting perl into python. It would be nice if there was a script like python's 2to3. Or perhaps some compatibility libraries. It doesn't have to be complete, anything to help speed up the process would be helpful. ...

How can I extract a value from comma separated values in Perl?

I have a log file containing statistics from different servers. I am separating the statistics from this log file using regex only. I am trying to capture the CPU usage from the running process. For SunOS, I have below output: process,10050,user1,218,59,0,1271M,1260M,sleep,58.9H,0.02%,java Here the CPU % is at 11th field if we separa...

No coverage for runtime with Devel::Cover and ModPerl::Registry

When I'm running Devel::Cover with ModPerl::Registry, I get no coverage info except for BEGIN blocks. When I'm running the same script with Devel::Cover from command line or as a CGI, everything works alright (obviously). How can I make Devel::Cover "see" my code being executed in the runtime? Here's Devel::Cover related stuff in my ht...

How can I validate a website URL in Perl?

I need a regular expression for validating the website URL using Perl. ...

How can I call a module in a Perl one-liner?

Say I have a data file that I want to process; I want to take the maximum value of each of the column and append it to the end of each line. INPUT: T1 T2 T3 35.82 34.67 31.68 32.20 34.52 33.59 37.41 38.64 37.56 OUTPUT: T1 T2 T3 35.82 34.67 31.68 35.82 32.20 34.52 33.59 34.52 37.41 38.64 37.56 38.64 I'm trying to implement this as ...

Perl : get substring which matches regex error

I am very new to Perl, so please bear with my simple question: Here is the sample output: Most successful agents in the Emarket climate are (in order of success): 1. agent10896761 ($-8008) 2. flightsandroomsonly ($-10102) 3. agent10479475hv ($-10663) Most successful agents in the Emarket climate are (in order of succes...

How can i check if a file exists in Perl?

I am a newbie to perl. My problem is... I have a relative path $base_path = input/myMock.TGZ myMock.TGZ is the file name located in input folder. The filename can change. But the path is always stored in $base_path. I need to check if the file exists in $base_path. Any suggestions are helpful to me ...