perl

Is there a better way of doing data validation in Perl than regex?

Is there a better way of doing data validation in Perl than regex? I have Perl code that does string and numeric data validation using complex regex, and this makes code difficult to read and follow, for everyone. ...

How can I split a string along a user-provided string separator in Perl?

My code used to work fine, and now it's breaking. A reduction of the problem is the following: I want to split a source string (from a database, but that's not important) at a separator. The separator is not fixed, but user provided, in a string. I used to do that: @results = split($splitString, $sourceStr); But this breaks when the u...

SOAP::Lite takes filedescriptor but doesn't release it

Hi all, I'm calling a .net webservice from Linux using Perl (5.8.7). I'm using the SOAP::Lite library. The basic proof of concept worked fine and now I'm trying it in the real world where I have to call the webservice many times. Now it looks like the web service call opens a file but does not release the file descriptor. The default m...

How do I pass Perl arrays to/from SWIG?

In Perl, I'm accustomed to passing arrays to and from subs sub abc { foreach my $x (@_) { print $x; } return (0, 1, 2); } How can I achieve similar behavior with SWIG'ed functions? SWIG'ing this: std::vector<int> print_list(std::vector<int> l) { std::vector<int>::iterator iter; for(iter=l.begin(); iter!=l.end(); iter++) { ...

What does the special variable $@ mean in Perl?

I'm trying to understand the following piece of code: sub foo { ... if ( $@ ) { ... die $@; } } ...

C_ISAM file parsing with ruby or perl

Does anybody had success parsing *.idx and *.dat files with ruby or perl? I have an old application, without the source code and i want to parse files generated by this legacy code. Any direction? ...

How can I manage use of a shared resource used by several Perl programs?

I am looking for a good way to manage the access to an external FTP server from various programs on a single server. Currently I am working with a lock file, so that only one process can use the ftp server at a time. What would be a good way to allow 2-3 parallel processes to access the ftp server simultaneously. Unfortunately the provi...

Script to build HTML page from from extracted DIVs from other HTML pages

I have a set of HTML reports that each contain two DIV elements with specific IDs that I need to strip out and compile into an overall summary report (again, an HTML file). My initial thoughts are that this is an ideal job for a Perl script, however we have no up-to-date in-house Perl skills (we're a .NET C# shop). Thoughts and suggest...

How do you reposition the main window under Perl Tkx?

Having more or less converted a lot of old Tk scripts over to Tkx I'm stuck for an port for the following function which repositions the window passed in as a parameter in the centre of the screen. I used to call this just before calling MainLoop, by which point Tk had obviously decided on the reqwidth and reqheight values. sub CenterWi...

How can I fix the "Couldn't create file parser context for file ..." bug with Perl libxml on Debian ?

When I try to read an XML file with XML::Simple, sometimes I get this error message: Couldn't create file parser context for file ... After some googling, it seems to be a problem with libxml-libxml-perl and is supposed to be fixed in the version I use (1.59-2). Any ideas? Edit: (code) sub Read { my ($file, $no_option) = @_; ...

What are some good Perl modules for flow-based programming on files?

What are some good Perl modules to process files based on configurations? Basically I am working on taking data files, split them into columns, remove some rows based on some columns, remove unnecessary columns, compare them to baseline (writes where changes have occured) and save a csv of the data and the comments as metadata. Sample...

How do I extract lines between two line delimiters in Perl?

I have an ASCII log file with some content I would like to extract. I've never taken time to learn Perl properly, but I figure this is a good tool for this task. The file is structured like this: ... ... some garbage ... ... garbage START what i want is on different lines END ... ... more garbage ... next one START more stuff I...

How can I manage Perl module dependencies?

I'm currently in a project which develops using a framework developed by another department as the base. We are currently introducing quality standards (at last, yay!) in our department, but it's currently impossible to introduce those to the other department. As a consequence, we are working against a constant moving target without eith...

Why does Module::Build's testcover gives me "use of uninitialized value" warnings?

I'm kinda new to Module::Build, so maybe I did something wrong. Am I the only one who gets warnings when I change my dispatch from "test" to "testcover"? Is there a bug in Devel::Cover? Is there a bug in Module::Build? I probably just did something wrong. I'm using ActiveState Perl v5.10.0 with Module::Build version 0.31012 and Dev...

How can I fake STDIN in Perl?

I am unit testing a component that requires user input. How do I tell Test::More to use some input that I predefined so that I don't need to enter it manually? This is what I have now: use strict; use warnings; use Test::More; use TestClass; *STDIN = "1\n"; foreach my $file (@files) { #this constructor asks for user input...

How do I create and append files with variable paths in Perl?

I'm working my way up towards creating a script that will create image galleries for me. When I run what I have it tells me No such file or directory at photographycreate line 16. ------------ (program exited with code: 2) Here is the code that I've gotten so far. #!/etc/perl -w #CHANGE THIS $filecategory = "cooking"; $filenumber...

Automating a Job at Work: Importing Powerpoint Bullet Text into an Excel Sheet

I have been asked to automate a particular task at work today which takes up a lot of our time! The following is what needs to be done and I would appreciate any help on how I can do this (Implementation Advice) within the realms of my knowledge, if possible. Problem I have a PowerPoint document (.ppt). I would like to extract text fro...

How can I create a nested hash as a constant in Perl?

I want to do, in Perl, the equivalent of the following Ruby code: class Foo MY_CONST = { 'foo' => 'bar', 'baz' => { 'innerbar' => 'bleh' }, } def some_method a = MY_CONST[ 'foo' ] end end # In some other file which uses Foo... b = Foo::MY_CONST[ 'baz' ][ 'innerbar' ] That is, I just want to declare a ...

How do I include a CSS file with HTML email that I send from a Perl CGI script?

I am using following code to create and send email through CGI perl. The images get attached properly, but the css files do not. my $msg = new MIME::Lite( From => $from, To => $to_list, Subject => "My subject", Type => 'text/html', # 'multipart/mixed' Data => $body ); $msg->attach(Typ...

When setting up Perl code to run as either a script or module, what is the reason for __PACKAGE__?

In this earlier Stackoverflow question and especially brian d foy's "How a Script Becomes a Module" I've read about how to set up code so that it can be run as either a script or a module, using this technique: package SomeModule; __PACKAGE__->run(@ARGV) unless caller(); sub run { # Do stuff here if you are running the file as ...