perl

How can I compare a number against a range in bash or Perl?

How to script a comparison of a number against a range? 1 is not within 2-5 or 3 is within 2-5 ...

How can I host a mod_perl application on a shared RHEL server?

I want to host a mod_perl application on a shared RHEL server where I do not have access to a root account. mod_perl is available on the server as are all Perl modules required (my app runs fine with CGI). Here are two problems I anticipate: Apache restarts would be required whenever I update my code the first time and subsequently on ...

What is the limitation of PerlNet?

Hi everyone, I've used PerlNet for a data extraction project. Perl is a powerful language for extracting data and text manipulation with a huge CPAN module. However, my program need some kind of UI, thread... which I decided to use .NET C#. With Perl Dev Kit, we have an option to wrap an Perl module to a .NET DLL and use this DLL direct...

How do I fix a multi-line runaway string error in Perl?

There are some errors in my Perl script, I looked though the source code but couldn't find the problem. #Tool: decoding shell codes/making shell codes use strict; use Getopt::Std; my %opts=(); getopts("f:xa", \%opts); my($infile, $hex); my($gen_hex, $gen_ascii); sub usage() { print "$0 -f <file> [-x | -a] \n\t"; print '-p <path to ...

Generating Synthetic DNA Sequence with Subtitution Rate

Given these inputs: my $init_seq = "AAAAAAAAAA" #length 10 bp my $sub_rate = 0.003; my $nof_tags = 1000; my @dna = qw( A C G T ); I want to generate: One thousand length-10 tags Substitution rate for each position in a tag is 0.003 Yielding output like: AAAAAAAAAA AATAACAAAA ..... AAGGAAAAGA # 1000th tags Is there a compact ...

What does it mean to pre-increment $#array?

I've come across the following line of code. It has issues: it is intended to do the same as push it ought to have used push it's hard to read, understand I've since changed it to use push it does something I thought was illegal, but clearly isn't here it is: $array [++$#array] = 'data'; My question is: what does it mean to pre-i...

Is Perl a good option for heavy text-processing?

I have this web application which needs to do several heavy text processing tasks: removing certain characters, parsing XML files, among others. Some of them involve regular expressions. The web application has some implementations in Java and others in PHP. Is it worth using Perl or other specific text processing language for such task...

What do you keep in your Perl toolbox?

I am a Perl developer and have gravitated towards a specific suite of modules that I use for almost everything. I primarily build GIS and database oriented web applications for reporting and data entry and the like. I'm curious what groups of modules other Perl devs have settled on using regularly. Mine: CGI DBI Spreadsheet::WriteE...

How should I call a Perl Script in Java?

I read Runtime.getRuntime().exec("perl script.pl") is an option, but is this the best way to do it? I'll need an answer from that script, so I'll have to read the script's return in some cases, although I might read it from a text file on other cases. Anyway, is exec() a good way of calling a Perl Script from Java? I should note, I'm w...

What's the opposite of the localtime function in Perl?

In Perl, localtime takes a Unix timestamp and gives back year/month/day/hour/min/sec etc. I'm looking for the opposite of localtime: I have the parts, and I'd like to build a unix timestamp from them. ...

How do I parse the JSON Date Format in Perl?

How can I parse this date format that my web service is receiving in JSON format in Perl? I'd like to convert it to a DateTime object: Date(1216647000000-0400) I assumed it was milliseconds since the epoch along with a time zone offset but the dates are way off. ...

Does Python have something like Perl 5.10's "state" variables?

In Perl 5.10, I can say: sub foo () { state $x = 1; say $x++; } foo(); foo(); foo(); ...and it will print out: 1 2 3 Does Python have something like this? ...

How can I encrypt or hide passwords in a Perl script?

I am working on Perl script that uses Expect to login via telnet to remote machines (don't ask, gotta use telnet). I also do perforce p4 login operations as necessary and use expect to pipe in the correct passwords. For now I just read passwords from clear text environment variable, i.e. export PASSWORD=password, which I know is no good ...

How would you translate this from Perl to Python?

I've got a Perl function which takes a timestamp and returns either the unchanged timestamp (if it's never seen it before) or otherwise, it appends some letters to make it unique: sub uniqify($) { my $timestamp = shift; state $last_ts = -1; state $next_letter = 'A'; if ($timestamp == $last_ts) { $timestamp .= $next_letter+...

Is there autoexpect for Perl's Expect?

I would like to generate Perl Expect code automatically, does something like autoexpect exist for Perl's Expect?? ...

How do I use Class::ArrayObjects?

Hi, I wrote a simple program that using Class::ArrayObjects but It did not work as I expected. The program is: TestArrayObject.pm: package TestArrayObject; use Class::ArrayObjects define => { fields => [qw(name id address)], }; sub new { my ($class) = @_; my $self = []; bless $...

What's the best way to discover all subroutines a Perl module has?

What's the best way to programatically discover all of the subroutines a perl module has? This could be a module, a class (no @EXPORT), or anything in-between. Edit: All of the methods below look like they will work. I'd probably use the Class::Sniff or Class::Inspector in production. However, Leon's answer is marked as 'accepted' ...

How can I use MooseX::ClassAttribute within a role?

I would like to use MooseX::ClassAttribute in a role. I.e., do something like package Cachable; use Moose::Role; use MooseX::ClassAttribute; class_has Cache => ( is => 'rw' ); 1; Unfortunately, the code above doesn't work as the deep magic of MooseX::ClassAttribute expects to be called from within a Moose object, and not a Moos...

Why am I having trouble comparing lines from input in Perl?

I don't know what I could be doing wrong with this simple transaction, but it's not working: print "OK? (y or n)\n"; $ans = <>; print "\n"; if($ans eq "y"){print $ans;} I basically want to know how to test the user input. This little bit of code won't work for me. I'm just trying to print $ans if y is entered by the user. Any sugge...

Matrices of Matrices within Perl

In a Perl script I'm working on, I need to build a matrix out of several other matrices. I've looked at a couple of modules in CPAN (Math::Matrix, PDL::Matrix, Math::Cephes::Matrix), but none of these seem to support this. In Octave, this is very easy. Here's an example of something similar to what I'm trying to do: octave:1> A = [ 1, ...