perl

How do I structure my Perl CGI program?

We just got our first major Perl CGI assignment in my CS class. Our task is to create an mp3 sharing site that allows users to create accounts, log in, share mp3's. Statistics must be shown of current users, mp3's available, etc. All actions must be written to a log file. Our code must be secure. So far, I have implemented each of th...

Why can't I use more than 20 files with my Perl script and Windows's SendTo?

I'm trying to emulate RapidCRC's ability to check crc32 values within filenames on Windows Vista Ultimate 64-bit. However, I seem to be running into some kind of argument limitation. I wrote a quick Perl script, created a batch file to call it, then placed a shortcut to the batch file in %APPDATA%\Microsoft\Windows\SendTo This works g...

To File::Find is this an array or just a scalar?

In this snippet: find( sub { print "found " . $File::Find::name . "\n"; }, (".")); What type will the (".") be? Array or scalar? ...

When writing a Perl module, do I have to specifically check for an object instance in all my methods?

I'm writing a module that has several methods. Let's consider this : package MyPackage; sub new { ... } sub do_your_job { ... } 1; What is to stop someone calling do_your_job like MyPackage->do_your_job instead of $obj->do_your_job ? Do I need to check in every method that I'm receiving a reference as the first argument? ...

How do I delete a random value from an array in Perl?

I'm learning Perl and building an application that gets a random line from a file using this code: open(my $random_name, "<", "out.txt"); my @array = shuffle(<$random_name>); chomp @array; close($random_name) or die "Error when trying to close $random_name: $!"; print shift @array; But now I want to delete this random name from the fi...

Perl's TieRegistry and Windows Server 2008 R2

Hi, We have a Perl program that ran well on all Windows platforms so far. When we tried it on the newly released Windows Server 2008 R2, it stopped working. Investigation revealed that the problem is that calls to read registry values using TieRegistry returned undefined values. Is this a known problem? Did anyone run into a problem a...

How do I match a text which can contain - or an underscore using regular expression?

I want the username to be any characters with _ or - in it but this in Perl is not working, why is it? if ("kunjaaN-" =~ /^[a-zA-Z-_]{1,7}$/) { print "equal" ; } ...

Why isn't there a CPAN for .NET?

CPAN is a really helpful resource for Perl. Why isn't there a CPAN for .NET? Should there be one? Are there other programming or platform technologies that have a CPAN-like infrastructure? EDIT No one mentioned this: isn't the Comprehensive base-class library included in .NET one of the key reasons you would NOT expect to see a CP...

What's the benefit of calling new on an object instance?

I'm reading Programming Perl, and I found this code snippet: sub new { my $invocant = shift; my $class = ref($invocant) || $invocant; my $self = { color => "bay", legs => 4, owner => undef, @_, # Override previous attributes }; return bless $self, $class; } With...

How do I properly invoke a subroutine that takes 2 subroutine references?

Imagine this subroutine: sub test(&&) { my $cr1 = shift; my $cr2 = shift; $cr1->(); $cr2->(); } I know I can call it like: test(\&sub1,\&sub2), but how can I call it like: test { print 1 },{ print 2 }; If I say that the subroutine takes only one &, than sending a block will work. I don't know how to make it work wit...

How should I best structure my web application using job queues [and Perl/Catalyst]?

Hi, I'm writing a web application using the Catalyst framework. I'm also using a Job Queue called TheSchwartz. I'm wanting to use a job queue because I'm wanting as much of the application specific code decoupled from the web application interface code. Essentially the whole system consists of three main components: GUI (Catalyst ...

How to I get perldoc to find my modules in perl/site/lib?

Update: My problem seems to have solved itself. Not sure what's going on. Sorry for the false alarm. My understanding is that perl/lib is reserved for the core Perl distribution and that I should be putting my own modules in perl/site/lib. However, when I do that, perldoc does not find my modules. It does find modules that I put in perl...

How do I write a Perl script to filter out digital pictures that have been doctored?

Last night before going to bed, I browsed through the Scalar Data section of Learning Perl again and came across the following sentence: the ability to have any character in a string means you can create, scan, and manipulate raw binary data as strings. An idea immediately hit me that I could actually let Perl scan the pictures tha...

Selectively counting delimited field values and creating a hash using map

I have a pipe delimited text file containing, among other things, a date and a number indicating the lines sequence elsewhere in the program. What I'm hoping to do is from that file create a hash using the year as the key and the value being the maximum sequence for that year (I essentially need to implement an auto-incremented key per y...

Restrict access to images on my website except through my own htmls

Hi, On my website I store user pictures in a simple manner such as: "image/user_1.jpg". I don't want visitors to be able to view images on my server just by trying user_ids. (Ex: www.mydomain.com/images/user_2.jpg, www.mydomain.com/images/user_3.jpg, so on...) So far I have three solutions in mind: I tried using .htaccess to passwor...

OS specific tests for Perl test scripts

Is there a more elegant way to write the portion of the test script which is O/S dependant? Please refer to the code below the comment line. Background: Module Perl::Tags creates a tags file for VIM. On Win32 the directory separator is "\" but on other OS's it is "/". Vim's Perl-support module seems to read the tags file quite happily,...

Should I use common::sense or just stick with `use strict` and `use warnings`?

I recently installed a module from CPAN and noticed one of its dependencies was common::sense, a module that offers to enable all the warnings you want, and none that you don't. From the module's synopsis: use common::sense; # supposed to be the same, with much lower memory usage, as: # # use strict qw(vars subs); # use feature qw(say...

Mysterious line in perl

Hello, I am reviewing some perl code and ran across this line $> = $<; It's older code and I wish I could have been more descriptive in the title above (sorry folks). What does this line do? ...

Should I use Perl or PHP for parsing a large XML file?

I want to parse a large XML file and I have two options: Perl or PHP. Being new to both languages what would be your suggestion about language of choice for parsing a large XML file? And what modules are more appropriate for the task at hand? ...

How to install GD library with Stawberry Perl

I am attempting to install the GD library using Strawberry perl and GnuWin32. However, when I enter "install GD" in the CPAN shell, the following message appears: 'gdlib-config' is not recognized as an internal or external command, operable program or batch file. **UNRECOVERABLE ERROR** Could not find gdlib-config in the search path. Pl...