perl

How can I launch Java tests using Perl?

How can I launch a Java test suite using Perl? ...

How can I unbless an object in Perl?

From perldoc -f bless: bless REF,CLASSNAME This function tells the thingy referenced by REF that it is now an object in the CLASSNAME package. Is there any way of obtaining an unblessed structure without unnecessary copying? ...

How I can I convert timezones in Perl?

I am trying to convert a date/time GMT 0 to GMT -6 in Perl. For example, a DHCP Server lease time is in the following format: 2010/02/18 23:48:37 I am trying to convert that time to the Localtime zone (GMT -6) but need it to honor Daylight savings time. The script below may be overkill, but I am not sure how to proceed from here...

Can you salvage my negative lookbehind example for commifying numbers?

In the "Advanced Regular Expresssion" chapter in Mastering Perl, I have a broken example for which I can't figure out a nice fix. The example is perhaps trying to be too clever for its own good, but maybe someone can fix it for me. There could be a free copy of the book in it for working fixes. :) In the section talking about lookaround...

Is checking Perl function arguments worth it?

There's a lot of buzz about MooseX::Method::Signatures and even before that, modules such as Params::Validate that are designed to type check every argument to methods or functions. I'm considering using the former for all my future Perl code, both personal and at my place of work. But I'm not sure if it's worth the effort. I'm thinking...

Why does my Perl max() function always return the first element of the array?

I am relatively new to Perl and I do not want to use the List::Util max function to find the maximum value of a given array. When I test the code below, it just returns the first value of the array, not the maximum. sub max { my @array = shift; my $cur = $array[0]; foreach $i (@array) { if($i > $cur) { ...

In Perl, how can I use Tie::IxHash with a dictionary while 'use strict' is on?

I'm trying to create a hash that preserves the order that the keys are added. Under section "Create a hash and preserve the add-order" of this page, it gives a snippet that modifies a hash so when you do keys it returns the keys in the order that you inserted them into the hash. When I do the following snippet: use strict; our %foo; u...

Perl+Image::Magick usage: how to assemble several areas in one image into a new image?

Hi Everybody, I'm new to ImageMagick and haven't figured out how to assemble several areas into a new image. E.g., I know the "geometry" of words "hello" and "world" respectively in an image, what I need to do is to retrieve the word images and put then into one line image while keep their relative positions. Question1: Suppose I use ...

How do I get the text-form verification code when doing auto site access in Perl?

I'm playing around with Win32::IE:Mechanize to try to access some authentication-required sites automatically. So far I've achieved moderate success, for example, I can automatically log in to my yahoo mailbox. But I find many sites are using some kind of image verification mechanism, which is possibly called CAPTCHA. I can do nothing to...

Why does Perl treat a hash element as list context at declaration?

Given this code: #!/usr/bin/perl -w use strict; use warnings; sub foo { return wantarray ? () : "value1"; } my $hash = { key1 => foo(), key2 => 'value2' }; use Data::Dumper; print Dumper($hash); I get the following output: $VAR1 = { 'key1' => 'key2', 'value2' => undef }; When I would expect: $VAR1 = { 'key1' ...

Why does Perl evaluate code in ${...} during string interpolation?

Why does the following snippet work at all? And what evil might be possible using this? But seriously, is there any reason, the code in ${} gets evaluated at all and then used as scalar reference? use strict; no strict 'refs'; our $message = "Hello world!"; print "${ lc 'MESSAGE' }\n"; ...

Why is using a POSIX character class in my regex pattern giving unexpected results?

I have encountered some strange Perl behavior: using a Posix character class in a regexp completely alters the sort order for the resulting strings. Here is my test program: sub namecmp($a,$b) { $a=~/([:alpha:]*)/; # $a=~/([a-z]*)/; $aword= $1; $b=~/([:alpha:]*)/; # $b=~/([a-z]*)/; $bword= $1; return $aword cmp $bword; ...

Python equivalents of the common Perl modules?

I need to rewrite some Perl code in python. So I'm looking for the closest modules to what I'm using now in Perl (i.e. with similar functionality and stability): DBI + DBD::mysql LWP::UserAgent WWW::Mechanize XML::LibXML HTML::TreeBuilder CGI::FormBuilder Template::Toolkit What are the Python equivalents to these? ...

How can I get an unreserved ClearCase check using Perl?

I need help on below requirement. I have a extracted report where I used to get "revision number", element details, version path, changeset. I need to: Create a temporary directory using a Perl script for each revision. Do an unreserved check out for the each element map with each revision and put into the created temporary folders. ...

How can I POST a multipart HTTP request from Perl to Java and get a response?

I'm trying to post from one of my subroutines in Perl a request to a Java based controller. But I'm not getting any kind of response back. I know the Java code works file because I can get a response if I post to it from a HTML form. This is my Perl code: use HTTP::Request::Common; my $ua = LWP::UserAgent->new; my $response = $u...

How can I add barcode support to html2ps?

We are using the html2ps Perl script to convert HTML to PostScript. I know it's not the best solution but this is what the developers here did (it was before my time). Now we need to implement support for barcode fonts that is showing each HTML and needs to be shown in each converted PostScript file. How do you do this? ...

How can I use Perl's Net::SFTP::Foreign on Windows?

I installed Net::SFTP::Foreign in my perl 5.8.8 and I'm trying to log in to a Secure FTP server using the below code: use Net::SFTP::Foreign; my $host = $tt->get_ftp_server_address(); my $sftp = Net::SFTP::Foreign->new("$host", {user=>$tt->get_location_user_name(), ...

How can my Linux daemon know when a Windows program has stopped writing a file that I access through SAMBA?

I'm developing a system that interfaces with a USPS shipping package called Dazzle. Part of this system includes a monitoring daemon whose purpose is to take tab-separated value files, turn them into XML that Dazzle recognizes, and pass them to Dazzle for label generation. And this part works just fine. What I also want to do, however...

How can I fix "unknown terminal type" when connecting with Perl's Net::Telnet?

I got a problem connecting to a SUSE linux machine by Perl's Net::Telnet module. The code looks like below: my $t = new Net::Telnet (Timeout => 20); $t->open($server); $t->input_log("telnet.log"); $t->login($user, $pass); my @lines=$t->cmd($command); print @lines; The log file looks like below: Welcome to SUSE Linux Enterprise Se...

Is there a Python equivalent for the Perl module Term::VT102?

In Perl there is a very handy module, Term::VT102, which allows you to create a screen in memory. This is very handy for scraping purposes since you can keep track of all the changes to portions of the screen and then export the screen as plain-text for processing. Is there an equivalent module in Python? Followup Question: There are mo...