perl

Why are Perl 5's function prototypes bad?

In another question a member asserted "I would advice you not to use prototypes. They have their uses, but not for most cases and definitely not in this one." Can anyone elaborate on why this might be true (or otherwise)? I almost always supply prototypes for my Perl functions, and I've never before seen anyone else say anything bad ab...

How can I validate dates in Perl?

How can I validate date strings in Perl? I'd like to account for leap years and also time zones. Someone may enter dates in the following formats: 11/17/2008 11/17/2008 3pm 11/17/2008 12:01am 11/17/2008 12:01am EST 11/17/2008 12:01am CST ...

When should I use OO Perl?

Hi, All. I'm just learning Perl. When is it advisable to use OO Perl instead of non-OO Perl? My tendency would be to always prefer OO unless the project is just a code snippet of < 10 lines. TIA ...

How can I use a database server from a Perl CGI script?

My program works already, I have Perl (GUI Window) where I can input data, data passed to the webpage (using to Tomcat server, JSP) and then saved it to oracle database. What I want is to make search parameter (webapp) that retrieve/extract data from the Oracle database using Perl CGI. Is it possible? Or any suggestions to solve my progr...

How can I read stderr when a command execution fails in Perl?

Hi, I am executing a diff command in perl. my @lines = `/usr/local/bin/diff -udr \"$expected_file\" \"$gen_file\"`; if ($? != 0) { print ERRFILE "Diff between $expected_file and $gen_file failed\n"; return $diff_err; } Here the diff might have failed because of some reason. For example: the stderr showed that /usr/local/bin/...

How can I modify Windows NTFS permissions in Perl?

Hi there, I'm using ActiveState Perl on Windows Server 2003. I want to create a directory on a Windows NTFS partition and then grant a Windows NT security group read access to the folder. Is this possible in Perl? Would I have to use Windows NT commands or is there a Perl module to do it? A small example would be much appreciated! ...

How can I read lines from the end of file in Perl?

Hi Guys, I am working on a Perl script to read CSV file and do some calculations. CSV file has only two columns, something like below. One Two 1.00 44.000 3.00 55.000 Now this CSV file is very big ,can be from 10 MB to 2GB. Currently I am taking CSV file of size 700 MB. I tried to open this file in notepad, excel but it looks like ...

How do I break out of a loop in Perl?

Hi, I'm trying to use a break statement in a for loop, but since I'm also using strict subs in my Perl code I'm getting an error saying: Bareword "break" not allowed while "strict subs" in use at ./final.pl line 154. Does anyone know of a workaround for this (besides disabling strict subs)? My code is formatted as follows: f...

How can I prevent XML::XPath from fetching a DTD while processing an XML file?

My XML starts like this $ cat a.xhtml <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; ... My code starts like this use XML::XPath; use XML::XPath::XMLParser; my $xp = XML::XPath->new(filename => "a.xhtml"); my $nodeset = $xp->find('/html/body//table');...

Why does my script report 'uninitialized value in eval "string"?

I am getting this warning: Use of uninitialized value in eval \"string\" at myscript.pl line 57. When I run this code: eval; { `$client -f $confFile -i $inputFile -o $outputFile`; }; if( $@ ) { # error handling here ... } What is causing the error? How can I fix the underlying cause? (Or otherwise suppress the war...

How can I open other people's Outlook calendars from Perl?

I can access my calendar entries as: $folder = $namespace->Folders("Joe Cool")->Folders("Calendar"); How do I open "Jane Cool" Calendar? Outlook shows that calendar as: People's Calendar Jane Cool ...

How can I prevent database being written to again when the browser does a reload/back?

Hi there, I'm putting together a small web app that writes to a database (Perl CGI & MySQL). The CGI script takes some info from a form and writes it to a database. I notice, however, that if I hit 'Reload' or 'Back' on the web browser, it'll write the data to the database again. I don't want this. What is the best way to protect ag...

How can I kill a whole process tree with Perl?

What's the best way to kill a process and all its child processes from a Perl script? It should run at least under Linux and Solaris, and not require installation of any additional packages. My guess would be to get a list of all processes and their parents by parsing files in /proc or by parsing the output of ps (neither of which seems...

How can I get the database name from a Perl MySQL DBI handle?

I've connected to a MySQL database using Perl DBI. I would like to find out which database I'm connected to. I don't think I can use: $dbh->{Name} because I call USE new_database and $dbh->{Name} only reports the database that I initially connected to. Is there any trick or do I need to keep track of the database name? ...

Why do I need to explicitly output the HTTP header for IIS but not Apache?

I am trying to set up apache instead of IIS because IIS needlessly crashes all the time, and it would be nice to be able to have my own checkout of the source instead of all of us editing a common checkout. In IIS we must do something like this at the beginning of each file: use CGI; my $input = new CGI(); print "HTTP/1.0 200 OK"; prin...

Why does my Perl script remove characters from the file?

Hi, I have some issue with a Perl script. It modifies the content of a file, then reopen it to write it, and in the process some characters are lost. All words starting with '%' are deleted from the file. That's pretty annoying because the the % expressions are variable placeholders for dialog boxes. Do you have any idea why? Source fi...

How can I append the name of a file to end of each line in that file?

I need to do the following for hundreds of files: Append the name of the file (which may contain spaces) to the end of each line in the file. It seems to me there should be some way to do this: sed -e 's/$/FILENAME/' * where FILENAME represents the name of the current file. Is there a sed variable representing the current filename? ...

How can I make hash key lookup case-insensitive?

Evidently hash keys are compared in a case-sensitive manner. $ perl -e '%hash = ( FOO => 1 ); printf "%s\n", ( exists $hash{foo} ) ? "Yes" : "No";' No $ perl -e '%hash = ( FOO => 1 ); printf "%s\n", ( exists $hash{FOO} ) ? "Yes" : "No";' Yes Is there a setting to change that for the current script? Thanks. ...

How important is it to indicate if a class implements an interface in Perl?

I've been discussing a code style issue with a friend. We have a series of packages that implement an interface by returning a specific type of value via a named subroutine. For example: package Foo::Type::Bar; sub generate_foo { # about 5-100 lines of code return stuff here; } So you can go: my $bar_foo = Foo::Type::Bar->gen...

How can I change the case of a hash key?

I am writing a script which is likely to be modified by users. Currently I am storing the configuration settings inside the script. It exists in the form of a hash-of-hashes. I would like to guard against people accidentally using lowercase characters in the hash keys, because that will break my script. It would be simple to inspect th...