perl

Is it possible to increase then QUEUESIZE for Perl's socket listen?

The typical socket code for Perl goes like this: bind(Server, sockaddr_in($port, INADDR_ANY)) || die "bind: $!"; listen(Server,SOMAXCONN) || die "listen: $!"; As described in this page the actual maximum allowed is somewhere around 5. That's way too low! I'm using a unix domain file socket and expecting very high throughput. ...

How can I load an image file into a blob in SQLite using Perl?

Could someone please give me a Perl example on how to load an image file into a blob in SQLite? ...

How can I replace all the text before the match in a Perl substitution?

Hi I am reading each line of an input file (IN) and printing the line read to an output file (OUT) if the line begins with one of the patterns, say "ab", "cd","ef","gh","ij" etc. The line printed is of form "pattern: 100" or form "pattern: 100:200". I need to replace "pattern" with "myPattern", i.e. print the current line to FILE but re...

Do you incur a data-copying performance hit when passing arguments to Perl subroutines?

I have been working on several Perl scripts that process large fixed-width data files, extracting small substrings out of each data record. I had imagined that delegating the extracting of substrings to method calls would be costly because of the overhead of copying the data record into the @_ array. So I ran the following to compare (a)...

Is there an easy way to chunk a text file into brace-balanced sections?

I'm trying to parse some data out of a file using Perl & Parse::RecDescent. I can't throw the full data file at the perl script because RecDescent will take days poring over it. So I split up the huge datafile into RD-sized chunks to reduce the runtime. However, I need to extract sections within balanced brackets and the routine I hav...

Is there a Perl or Python library for ID3 metadata?

Basically, I've got a bunch of music files yoinked from my brother's iPod that retain their metadata but have those absolutely horrendous four character names the iPod seems to like storing them under. I figured I'd write a nice, quick script to just rename them as I wished, but I'm curious about any good libraries for reading ID3 metada...

How can I create an object whose derived class is specified implicitly by the creation properties?

I'm looking for a pattern for the following. (I'm working in Perl, but I don't think the language matters particularly). With a parent class Foo, and children Bar, Baz, Bazza. One of the methods for constructing a Foo is by parsing a string, and part of that string will implicitly specify which class is to be created. So for example i...

Is there a good library in CPAN for filtering out cross-site scripting (XSS)?

Is there a good library in CPAN for filtering out an textfield for all the bad things, like xss? ...

How can I capture output from the Windows cmd shell?

Is there any way with, say Perl or PHP, that I can grab output from another process that outputs to the Windows cmd shell? I have a game server that outputs certain information, for example say 'player finished track in 43s' and I want to grab that line and use Perl or PHP to send a request to a webserver to update ranks on a web page. I...

Why is my Perl source code being displayed in the browser?

What does it mean when I access my Perl script via URL, but when I do, the source code is printed on the screen? Does this mean that Perl isn't properly set up? I'm using Apache on Fedora. ...

How can I see if a Perl hash already has a certain key?

Hey simple question probably. I have a Perl script that is counting the number of occurrences of various strings in a text file. I want to be able to check if a certain string is not yet a key in the hash. Is there a better way of doing this altogether? Here is what I am doing: foreach $line (@lines){ if(($line =~ m|my regex|) ) ...

Cleanest Perl parser for Makefile-like continuation lines

A perl script I'm writing needs to parse a file that has continuation lines like a Makefile. i.e. lines that begin with whitespace are part of the previous line. I wrote the code below but don't feel like it is very clean or perl-ish (heck, it doesn't even use "redo"!) There are many edge cases: EOF at odd places, single-line files, f...

How do I convert Data::Dumper output back into a Perl data structure?

Hi all! I was wondering if you could shed some lights regarding the code I've been doing for a couple of days. I've been trying to convert a Perl-parsed hash back to XML using the XMLout() and XMLin() method and it has been quite successful with this format. #!/usr/bin/perl -w use strict; # use module use IO::File; use XML::Simple; u...

Why does @my_array = undef have an element?

@my_array = undef; if (@my_array ) { print 'TRUE'; } else { print 'FALSE'; } This will print TRUE Why does the array have an element ? ...

Using Perl, Python, or Ruby, how to write a program to "click" on the screen at scheduled time?

Using Perl, Python, or Ruby, can I write a program, probably calling Win32 API, to "click" on the screen at scheduled time, like every 1 hour? Details: This is for experimentation -- and can the clicking be effective on Flash content as well as any element on screen? It can be nice if the program can record where on screen the click...

sort with lexicographic order

I see the results from the following code, but I don't understand exactly how the or knows what to do in the following sort example: use Data::Dumper; $animals{'man'}{'name'} = 'paul'; $animals{'man'}{'legs'} = 2; $animals{'cheeta'}{'name'} = 'mike'; $animals{'cheeta'}{'legs'} = 3; $animals{'zebra'}{'name'} = 'steve'; $animals{'zebra...

Is the select() wrapper in IO::Select thread-safe? How to work around?

Let's say I have a thread: sub new { my $class = shift; my $self = ref $class || $class; bless { 'read_set' => IO::Select->new, 'write_set' => IO::Select->new, 'error_set' => IO::Select->new }, $self; } sub start { my $self = shift; $self...

How can I accurately program an automated "click" on Windows?

I wrote a program to click on an application automatically at scheduled time using Win32, using MOUSE_DOWN and MOUSE_UP. It usually works well, except I found that I need to put in a sleep 0.1 between the MOUSE_DOWN and MOUSE_UP. (using Ruby, which allows sleeping a fraction of a second). Without the sleep, sometimes the click doe...

foreach my $var (@list) -- $var is a reference?

So, I never knew this and I want to get some clarifcation on it. I know if you do foreach (@list){ if you change $_ in that loop it will affect the actual data. But, I did not know that if you did foreach my $var1 (@list){ If you changed $var1 in the loop it would change the actual data. :-/ So, is there a way to loop over @list ...

How do I integrate NTLM authentication with Perl's SOAP::Lite module?

This Perl code works with Anonymous access to an ASP.NET web service, but when integrated security is turned on, the service returns 401 errors. I think I need to use the NTLM module in conjunction with SOAP::Lite, but it's not clear how to do so. How can these components be integrated? use SOAP::Lite; use strict; my $proxy = "http://l...