perl

How do I remove the <opt> tag in XML::Simple output?

I'm creating an XML file using Perl and XML::Simple module. I successfully create the XML file, but the problem is I am having <opt> </opt> tag for each my tags. I am looking for any option which we can aviod the <opt> </opt> tag. I can't do the post-processing to remove the tag. because the file size is huge. Example : <opt> <per...

Best data structure for searching record

I am having a lot of IDs and I want to store them for a temporary purpose and need to search that record for some operation. Which data structure is good for this operation in Perl? Should I use a hash or an array, or is there any other module I could use to do this efficiently? The records are 4343, 34343, 34343, 2323, 232, .... ...

Why does Blowfish::PP's encrypt only print five characters?

Good day! I have a code here that uses the blowfish_PP algorithm from Crypt::Blowfish_PP to encrypt a password. I've provided a sample "key" variable for a start (though I will make a function later that will increment key every time I use it), but for now this is what I've got: use Crypt::Blowfish_PP; $key = "12345678"; $$plaintextB...

What is the difference between \1 and $1 in a Perl regex?

What is the difference of doing \1 as opposed to $1 if any, or are they interchangeable in all situations. Example: s/([a-z]+),afklol/$1,bck/; #against s/([a-z]+),afklol/\1,bck/; They both give the same result but is there any difference? ...

How can I retrieve a Perl hash value only if its key exists?

Code: %a = ( 1 => "ONE" , 2 => "TWO" , 3 => " Three", ); $test_value = 1 ; foreach $key (sort(keys %a)) { if ($key == $test_value ) { print $a{$key}; } } I just want to achieve the same operation in very short way. Is there any shortcut for this? ...

Is there a way to override a Perl "use constant" in your unit testing?

I have a Perl module that I have declared some constants: use constant BASE_PATH => "/data/monitor/"; In live operation the constant will never change but I wish to be able to modify it in my unit tests, e.g. to set it to ~/project/testdata/. Is there a way do do this without having to use "non-constants"? Could I possibly use Test:...

What global variables affect the -e, -d file test operators in Perl?

I am having issues getting the -e and -d file test operators to work reliably. Listings 1 and 2 are in the same directory, on an NTFS Windows XP SP 3 system. However, Listing 2 insists that a directory exists(it doesn't), and Listing 1 gets it right. Listing 2 is part of the main program. Also, interesting, my logger routine is refusin...

How do I send a TAB using Perl's Net::Telnet?

I am using Perl's Net::Telnet module to access an application available over telnet. I am using $telnet->waitfor() and $telnet->print() methods to determine the form received and submit appropriate data. One of the forms has two options - "Find" and "Cancel". In a terminal, I can just hit TAB to choose "Cancel" and ENTER. But within ...

Retrying an operation after an exception: Please criticize my code.

My Perl application uses resources that become temporarily unavailable at times, causing exceptions using die. Most notably, it accesses SQLite databases that are shared by multiple threads and with other applications using through DBIx::Class. Whenever such an exception occurs, the operation should be retried until a timeout has been re...

What's a good way to handle development/production libs paths with Perl?

With Perl, what is an easy way to handle different development versus production libs paths? I want to use my local box path for testing, but when I launch I want it to automatically point to the production lib path. ...

Can I create Java-like interfaces in Perl?

I understand that Perl's OO model is rather primitive; it is, in most respects, essentially a namespace hack. Nevertheless, I wonder if it is possible to create something like an "interface?" My goal is to have a base class from which others are extended whose principal purpose is to make mandatory the implementation of certain method...

Automate open and save OpenOffice Impress format as html/jpeg using C# reflection, or perl

I want to convert an OpenOffice Impress Presentation file and convert it to HTML or JPEG. I have found a few examples, but they appear to be broken. I would like to do it, in a way that it does not matter what version of OpenOffice is installed, and I do not want to bundle any interop dlls with my application. Therefore, I am looking fo...

How can I create a complex data structure in Perl?

%a = ( "KEY" => { "p1" => 1 , [1223], "p1" => 2 , [2323], "p1" => 3 , [2353], } ); I want to generate a structure like this. I have tried with this code: @array = ( 1223 , 2323 ,2353 ); $count = 0; foreach my $i (@array) { $a{"KEY"} => { "p1" ...

How can I combine two XML files with Perl?

I want to merge the multiple XML files into single XML file in Perl. File 1 : <r1> <searchpath> <dir>/usr/bin</dir> <dir>/usr/local/bin</dir> <dir>/usr/X11/bin</dir> </searchpath> </r1> FILE 2 : <r2> <user login="grep" fullname="Gary R Epstein" /> <user login="stty" fullname="Simon T Tyson" /> </r2> Mer...

Are nonblocking I/O operations in Perl limited to one thread? Good design?

I am attempting to develop a service that contains numerous client and server sockets (a server service as well as clients that connect out to managed components and persist) that are synchronously polled through IO::Select. The idea was to handle the I/O and/or request processing needs that arise through pools of worker threads. The sh...

What flavour of regular expression is grep?

I'm guessing it's not a Perl compatible regular expression, since there's a special kind of grep which is specifically PCRE. What's grep most similar to? Are there any special quirks of grep that I need to know about? (I'm used to Perl and the preg functions in PHP) ...

How do I create and use a byte array in perl?

$var = pack "C2", 0x20, 0x30; seems to work well enough, but now how do I address the elements of the array? Make changes to elements? In-place if possible. The pack/unpack semantics are not very friendly. Currently I'm using substr($var, $index, 1, substr($var, $index, 1) + 10) to add 10 to elements in-place. And for intializers, i...

Grab info between tags

I have a text file that has data wrapped between tags. The tags are: <title> <url> <pubDate> So, the entries look like this: <title>title 1</title> <url>url 1</url> <pubDate>pubDate 1</pubDate> <title>title 2</title> <url>url 2</url> <pubDate>pubDate 2</pubDate> <title>title 3</title> <url>url 3</url> <pubDate>pubDate 3</pubDa...

Perl - why won't this simple file open request work?

OK, so this is so simple but for the life of me I can't figure out why the code below doesn't work. I'm trying to simply write a CGI script that creates sequentially numbered files. I'm using a counter (stored in a separate file) to keep track of the last ordinal used, and then generating a unique filename using sprintf. The uniquel...

Protecting against SQL tablename injection - how far is too far?

I'm developing a relatively small application to talk to PostgreSQL, and wanted to get some feedback on how far is too far to go with regards to protecting against SQL injection. The application is in Perl and does not use any ORM modules (just DBI). The SQL statements are constructed in the typical fashion with placeholders: my $sql ...