perl

Why is object destructor not called when script terminates ?

I have a test script like this: package Test; sub new { bless {} } sub DESTROY { print "in DESTROY\n" } package main; my $t = new Test; sleep 10; The destructor is called after sleep returns (and before the program terminates). But it's not called if the script is terminated with Ctrl-C. Is it possible to have the destructor called ...

Perl/Tk : Getting the selected value of option menu

Hi all, I am developing one interface in Perl/Tk. In that I am using one optionmenu to list the names of the users. And while selecting the user from optionmenu it should display corresponding date of birth of the employee. And I should be able to update the date of birth of the selected user. I have written the following code. $dob...

How can I send the output of external programs to a Perl socket?

I have just started to learn socket programming using Perl. Is there a method to send the output (STDOUT) data/images from already running scripts/tools using Perl socket programming? ...

Override variables while testing a standalone Perl script

There is a Perl script in our environment that I now need to maintain. It is full of bad practices, including using (and re-using) global variables throughout the script. Before I start making changes to the script, I was going to try to write some test scripts so I can have a good regression base. To do this, I was going to use a met...

Why is the Switch module deprecated in Perl?

Why was Switch deprecated in Perl? I know that a switch/case be made with elsif, but I don't like that very much. ...

Why doesn't CPAN install dependencies for the modules in my bundle?

I'm creating a bundle to make it easy to install my app. I started here: http://search.cpan.org/dist/CPAN/lib/CPAN.pm#Bundles I have a package Bundle::MyApp which looks like this: package Bundle::MyApp; $VERSION = '0.01'; 1; __END__ =head1 NAME Bundle::MyApp - modules needed by my app =head1 SYNOPSIS cpan install Bundle::MyApp ...

What are the most interesting/useful new things in Perl 5.12?

I remember quickly adopting given .. when, say, //, and the smart matching operator when Perl 5.10 came around. What do you consider the most useful fixes and features introduced with Perl 5.12.0? ...

What would I use to remove escaped html from large sets of data.

Our database is filled with articles retrieved from RSS feeds. I was unsure of what data I would be getting, and how much filtering was already setup (WP-O-Matic Wordpress plugin using the SimplePie library). This plugin does some basic encoding before insertion using Wordpress's built in post insert function which also does some filte...

How do I elegantly print the %z (timezone) format in Perl on Windows?

An offshoot of http://stackoverflow.com/questions/172110/how-do-i-elegantly-print-the-date-in-rfc822-format-in-perl, but Windows specific. On windows: C:\> perl -MPOSIX print strftime('%z', localtime()),"\n"; Yields: Central Daylight Time I was expecting: -0500 As anyone would on a Linux system. How can I get th...

Why doesn't Perl file glob() work outside of a loop in scalar context?

According to the Perl documentation on file globbing, the <*> operator or glob() function, when used in a scalar context, should iterate through the list of files matching the specified pattern, returning the next file name each time it is called or undef when there are no more files. But, the iterating process only seems to work from ...

How can I use the match variable $1 following a substitution in Perl?

What is the cleanest way of picking up a match variable from a substitution in Perl I sometimes find myself writing s/(something)// ; my $x = $1 ; then I realise that if the s/ / / fails $1 might be carrying over a value from a previous match. So I try my $x = 'defaultvalue' ; if ( s/(something)// ) { $x...

how to include .pl (PERL) file in PHP

i have two pages one in php(index.php) and another one in Perl(dbcon.pl). basically i want my php file to show only the UI and all the data operations would be done in Perl file. i have tried in index.pl <?php include("dbcon.pl");?> <html> <br/>PHP</br> </html> and dbcon.pl has #!/usr/bin/perl use strict; use warnings; use DBI; ...

Importing Conditionally Compiled Functions From a Perl Module

I have a set of logging and debugging functions which I want to use across multiple modules / objects. I'd like to be able to turn them on / off globally using a command line switch. The following code does this, however, I would like to be able to omit the package name and keep everything in a single file. More specifically, I would ...

How can I ignore C comments when I process a C source file with Perl?

I'm running a code that read files, do some parsing, but need to ignore all comments. There are good explanations how to conduct it, like the answer to How can I strip multiline C comments from a file using Perl? $/ = undef; $_ = <>; s#/\*[^*]*\*+([^/*][^*]*\*+)*/|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#defined $2 ? $2 : ""#gse; pr...

How can I extract paragaphs and selected lines with Perl?

I have a text where I need to: to extract the whole paragraph under the section "Aceview summary" until the line that starts with "Please quote" (not to be included). to extract the line that starts with "The closest human gene". to store them into array with two elements. The text looks like this (also on pastebin): AceView: ge...

Perl regex extract parts of string with multiple condition

What's the single regex that enables me to capture all the text that goes after are genes and is gene from this text The closest human genes of best are genes A B C The closest human gene of best is gene A Hence I hope to extract $1 that contain A B C A Tried this but fail: $line =~ /The closest .* gene[s] (.*)$/; ...

Perl like regex in Python

In Perl I would do something like this for taking different fields in a regexp, separating different fields by () and getting them using $ foreach $line (@lines) { $line =~ m/(.*?):([^-]*)-(.*)/; $field_1 = $1 $field_2 = $2 $field_3 = $3 } How could I do something like this in Python? ...

How do I sort a multidimensional hash array by a key maybe three levels in, in PHP?

I am moving from Perl to PHP and am struggling to get my head around PHP sorting. Here's what I have in Perl: $log{'11111'}{'1'}{'20100102'}{'name'}='blah'; $log{'11111'}{'1'}{'20100101'}{'name'}='blah'; $log{'11111'}{'1'}{'20100103'}{'name'}='blah'; $cook='11111'; foreach $entry (sort {$log{$cook}{$a}{time} cmp $log{$cook}{$b}{time}...

Why do I get extra, unexpected results with my ack regex?

I'm finally learning regexps and training with ack. I believe this uses Perl regexp. I want to match all lines where the first non-blank characters are if (<word> !, with any number of spaces in between the elements. This is what I came up with: ^[ \t]*if *\(\w+ *! It only nearly worked. ^[ \t]* is wrong, since it matches one or non...

How can an SVN::Error callback identify the context from which it was called?

I've written some fairly extensive Perl modules and scripts using the Perl bindings SVN::Client etc. Since the calls to SVN::Client are all deep in a module, I have overridden the default error handling. So far I have done so by setting $SVN::Error::handler = undef; as described in the docs, but this makes the individual calls a bi...