perl

How can I change the case of filenames in Perl?

I'm trying to create a process that renames all my filenames to Camel/Capital Case. The closest I have to getting there is this: perl -i.bak -ple 's/\b([a-z])/\u$1/g;' *.txt # or similar .extension. Which seems to create a backup file (which I'll remove when it's verified this does what I want); but instead of renaming the file, it re...

Why do you not use CPAN modules?

ETA: When I ask "Why do you not use CPAN modules?", I am referring to the people who refuse to use any CPAN modules (including high quality ones like DBI). Not all CPAN code is of high quality, and it is fine to stay away from modules that are trivial or are based on experimental code (I got annoyed at a developer the other day for want...

How can I detect if the file for an open filehandle has been deleted on Windows using Perl?

Hello, I have a process with an open filehandle to a file. I need to detect if this file has been deleted by another process (there may be a file with the same name in its place). On UNIX I was comparing the inodes of my filehandle and the file-path via stat, but this doesn't work on Win32. How can I do this in Perl? Thanks, -Peter ...

Why does my Perl script complain about 'Global symbol "$connection" requires explicit package name'?

my $now = &GetDate; my $myHeader = &ReadMessage; my $mySoftwareVersions = param('mySoftwareVersions'); my $q = new CGI;print $q->header(); use CGI::Carp(fatalsToBrowser); getAllSoftwareVersions(); sub getAllSoftwareVersions { my $user = "zxxx"; my $passwd = "xxxx"; # my $tableName = "config_table"; # my $con...

Why can I only open 2045 files with Tie::File on Windows?

I have the following code that tries to tie arrays to files. Except, when I run this code, it only creates 2045 files. What is the issue here? #!/usr/bin/perl use Tie::File; for (my $i = 0; $i < 10000; $i++) { @files{$i} = (); tie @{$files{$i}}, 'Tie::File', "files//tiefile$i"; } Edit: I am on windows ...

How do I handle both caught and uncaught errors in a Perl subroutine?

This is a followup to "How can I get around a ‘die’ call in a Perl library I can’t modify?". I have a subroutine that calls a Library-Which-Crashes-Sometimes many times. Rather than couch each call within this subroutine with an eval{}, I just allow it to die, and use an eval{} on the level that calls my subroutine: my $status=eval{fun...

How can I catch changes to %ENV?

I have a bunch of scripts that run tool flows. Like a Makefile does but in Perl. As part of those flows, the Perl scripts set environment vars and it's not always easy to know when they happen and hence it can be hard to reproduce individual stages of the flow. Is there a way to hook into %ENV such that I can register a callback when t...

Is there a CPAN module that digests a short string into a short number?

I need to create unique numerical ids for some short strings. some.domain.com -> 32423421 another.domain.com -> 23332423 yet.another.com -> 12131232 Is there a Perl CPAN module that will do something like this? I've tried using Digest::MD5 but the resulting numbers are too long: some.domain.com -> 29680057245717615035661393...

Why doesn't File::Find handle my dangling symlink?

I'm using Perl's File::Find module to scan for files, directories, and links. Among other things, I want the utility I'm writing to report dangling links. In theory, this is supported by creating a subroutine to be called whenever an dangling link has been found, and calling the find method with a hash reference of appropriate values, ...

How can I force IIS 7 to flush output?

In IIS 6, using Perl, I was able to send a stream of output to the client rather than buffering the entire thing and dumping it out at all once. This allowed such things as progress bars and such to be used. How can I accomplish the same thing in IIS 7? ...

Why am I getting a panic with Perl 5.10, Mason, and Apache?

I'm developing an application using Perl 5.10, HTML::Mason, and apache 2.2. This is the first time I've used Perl 5.10 for a big project. I get a strange behavior every once in a while. The application dies with a very strange error: panic: attempt to copy value to a freed scalar b87acf34 at ... I guess my question is it Perl 5.10 be...

I need a portable, consistent pseudorandom number generator

I am writing a kid sister encryption function and I need a PRNG that produces consistent results across OSes (so no floating point math, taking advantage of hardware, or system level software). It would be nice, but not necessary, for the PRNG had a period longer than 230. I am currently using a 32 bit Xorshift: #!/usr/bin/perl use s...

Why do I need to know how many tests I will be running with Test::More?

Am I a bad person if I use use Test::More qw(no_plan)? The Test::More POD says Before anything else, you need a testing plan. This basically declares how many tests your script is going to run to protect against premature failure... use Test::More tests => 23; There are rare cases when you will not know beforehand h...

How can I reduce Perl CGI script start-up time?

I'm developing some CGI scripts and I'm trying to find a solution to decrease the "starting time" produced when I import a lot of modules with "use". ...

perl GD draw a shape

I am using GD library to draw an image. Image I am drawing is this http://i39.tinypic.com/apd1f7.png I am able to manage most of the image however, I do not know how to draw the red portion of the image. The red portion has a sideways triangle on both sides...how can I manage that using the GD lib? ...

What are good interactive GUI builder packages for Perl?

I'd like to write some interactive GUIs in Perl. I've used TclTk but it looks dated. I've written QT code for C++, but the PerlTk module hasn't had a release in several years. Googling around I see other possible options. What are good packages for this, including basic windowing, menus, drawing canvas, scrollbars, and so on. ...

How can I determine which SSL client certificate a connection is using in mod_perl?

I am writing a web service in Perl that will run under SSL (HTTPS) with client certificates. How can I determine which certificate is being used by the client in the current connection so I can filter out unwanted ones? Note: the web service is being run as a mod_perl script. ...

How do you do beautiful reports when testing with Selenium under Perl?

Selenium has some nice additional libraries, as long you are using Java to write your tests, e.g. LoggingSelenium. However, these are not usable if you are writing in Perl. How do you normally do proper reporting, possibly with screenshots after every significant step etc.? ...

How can I limit file types in CGI file uploads in Perl?

I am using CGI to allow the user to upload some files. I just want the just to be able to upload .txt or .csv files. If the user uploads file with any other format then I want to be able to put out an error message. I saw that this can be done by javascript: http://www.codestore.net/store.nsf/unid/DOMM-4Q8H9E But is there a better way...

How do I know if a file is tab or space delimited in Perl?

I am uploading a file to a Perl program from from an HTML page. After the file has been uploaded I want to determine whether the file is either space or tab delimited and all the values are integers. If this is not the case then I want to output some message. I was thinking of reading every character of the file and checking if it's...