perl

When would it be a good idea to supply an anonymous sub as a command-line argument?

I'm toying with the idea of modifying my home-made test suite to supply it anonymous subroutines as command-line arguments. The reason why I want to do this is to enhance the script's flexibility. It doesn't seem worth it to hard-code a subroutine that I am only going to use once or twice to assimilate the data in a particular manner. ...

Simplifying regex OR patterns

I was asked today if there was a library to take a list of strings and to compute the most efficient regex to match only those strings. I think it's an NP Complete problem by itself, but I think we can refine the scope a bit. How would I generate and simplify a regex to match a subset of hosts from a larger set of all hosts on my networ...

How does my Perl program get standard input on Linux?

I am fairly new to Perl programming but I have a fair amount of experience with linux. Lets say I have the following code:. while(1) { my $text = <STDIN>; my $text1 = <STDIN>; my $text2 = <STDIN>; } Now, the main question is: Does STDIN in Perl read directly from /dev/stdin on a linux machine or do I have to ...

Perl application move causing my head to explode...please help.

I'm attempting to move a web app we have (written in Perl) from an IIS6 server to an IIS7.5 server. Everything seems to be parsing correctly, I'm just having some issues getting the app to actually work. The app is basically a couple forms. You fill the first one out, click submit, it presents you with another form based on what checkb...

How can I test that "something" is a hash in Perl?

I am receiving a hash of hashes from another function, and some elements of the hash of hashes can be another hash. How can I test to see if something is a hash? ...

How can I find low regions in a graph using Perl/R?

I'm examining some biological data which is basically a long list (a few million values) of integers, each saying how well this position in the genome is covered. Here is a graphical example for a data set: I would like to look for "valleys" in this data, that is, regions which are significantly lower than their surrounding environmen...

Why does this Perl function return a value?

$hi = do_this('asdf'); sub do_this { $blob{'f'} = { 'k' => 'j' }; } print $hi->{'k'}; # prints j since do_this doesn't return anything, how does it still print j? ...

How can I efficiently count ranges that cover a given range in Perl?

I have a database of some 30k ranges, each is given as a pair of start and end points: [12,80],[34,60],[34,9000],[76,743],... I would like to write a Perl subroutine that a range (not from the database), and returns the number of ranges in the database which fully 'include' the given range. For example, if we had only those 4 ranges ...

Do you have a good Perl template script?

I do a lot of programming in Perl and was wondering if people had a "default" template Perl script that they use and willing to share. I started copying one of my older scripts which has Getopt functions. I am thinking people would have done something similar? ...

How can I check if `File::Path::remove_tree` failed?

I'm used to `... or die ".. failed... $!";. I was surprised to find that in order to know if File::Path::remove_tree failed or not I must do something like this: remove_tree( 'foo/bar', 'bar/rat', {error => \my $err} ); if (@$err) { die "error..." } Am I missing something? Is this really the way to go? A lot of unneeded code for me...

How do I define a Windows file path as a variable?

I am screwing around with a tiny script I am making and one thing I am trying to figure out is how to make a perl variable reflect an executable, for example. $putty = C:\putty.exe; When ever I run it like this it tells me "C:\ is not recognizable command, what am I doing wrong? I have also tried surrounding it in quotes and no help b...

How can I run dynamic code in Perl?

I have a question relating to Perl dynamic code. Is there a construct in Perl where I could use to execute code. For instance, $command = " some command"; $perl -> execute($command); $command changes in run time . Sorry for my terminology. I do not know how to explain it otherwise. I am trying to accomplish this: I have a function w...

How can I delete empty arrays/refs from a Perl hash?

Lets say I have the following Perl hash: %hash = ( 'A' => { 'B' => ['C', 'D', 'E'], 'F' => { 'G' => [], 'H' => [] }, 'I' => [] } ); and I'd like to get rid of the []'s to get the hash result below: %hash = ( 'A' => [ 'B' => ['C', 'D', 'E'], 'F' => [ 'G', 'H', 'I' ] ...

How can I find out if two strings are mostly equal (in perl)?

I have a string that I want to compare against an array of strings, and return the array element that most closely matches. I can write a sliding correlator that counts the number of matching characters at each step and returns the max correlation. But is there a better way? For example: control_string = drv_probability_1_max List:...

How do I extract links from HTML with a Perl regex?

I have a HUGE html which has many things I don't need, but inside it has URLs that are provided in the following format: <a href="http://www.retailmenot.com/" class=l I'm trying to extract the URLs... I tried, to no avail: open(FILE,"<","HTML.htm") or die "$!"; my @str = <FILE>; my @matches = grep { m/a href="(.+?") class=l/ } @str ...

How can I run command prompts with VBA and restart if they fail?

I'm a Perl programmer with some nice scripts that go fetch HTTP pages (from a text file-list of URLs) with cURL and save them to a folder. However, the number of pages to get is in the tens of millions. Sometimes the script fails on number 170,000 and I have to start the script again manually. It automatically reads the URL and sees if...

How can I lazily load a Perl variable?

I have a variable that I need to pass to a subroutine. It is very possible that the subroutine will not need this variable, and providing the value for the variable is expensive. Is it possible to create a "lazy-loading" object that will only be evaluated if it is actually being used? I cannot change the subroutine itself, so it must sti...

Mapping Languages to Paradigms

I recently read Eric Steven Raymond's article "How To Become A Hacker" and I like his suggestion of learning 5 key languages (he suggests Python, C/C++, Lisp, Java, and Perl) as a way of covering the main programming paradigms in use today. His advice is that it's not so important which specific languages a programmer knows. It's more ...

How do I read args passed to the constructor and args passed by `use Module` in Perl?

Currently I am making a new module and I was wondering how could I implement in my module 2 things. We often see the use like: use My::Module qw(something); for example: use CGI::Carp qw(fatalsToBrowser); So the first question is, how do i retrieve this, i mean wether the user has specified anything and what he specified ? Second...

How can I fetch more than 1000 Google results with the Perl Google API?

HUsing the regular search engine, as a human, can get you not more than 1000 results, which is far more than a regular person needs. But what If I do want to get 2000? is it possible? I read that it is possible using the App Engine or something like that (over here...), but, is it possible, somehow, to do it through Perl? ...