perl

How to do a range query

I have a bunch of numbers timestamps that I want to check against a range to see if they match a particular range of dates. Basically like a BETWEEN .. AND .. match in SQL. The obvious data structure would be a B-tree, but while there are a number of B-tree implementations on CPAN, they only seem to implement exact matching. Berkeley ...

Perl array and hash manipulation using map

I have the following test code use Data::Dumper; my $hash = { foo => 'bar', os => 'linux' }; my @keys = qw (foo os); my $extra = 'test'; my @final_array = (map {$hash->{$_}} @keys,$extra); print Dumper \@final_array; The output is $VAR1 = [ 'bar', 'linux', undef ...

split function in perl

Hello, Please kindly help me in the following, I have $sub = C:\views\sght\gzad\text\hksdk\akldls\hool.java = C:\views\sght\bdsk\text\hksdfg\sdjks\same.java = C:\views\jdjk\jhah\fjd\afhlad\sitklds\hgls.jsp I need to replace every "\" with a "." I need to split the $sub such a way that if $sub contains the "text...

How to get registry Key name from an open Key Handle in Perl?

I have a perl function that takes an open registry key object. Now, I want to get the name of the key this object represents. How do I get the key Name? I am using Win32::Registry module. ...

A good Perl ORM framework for an already built (badly designed) database

Hello, I m looking to separate the database code from the rest of the code in our application and looking to use an ORM framework that will work well for that knowing that the database is not well designed. I looked in other topics and found that most people suggest DBIx:class, Rose:DB:Object... but did not know which one will work best ...

Device::Gsm: How to find out, if a group of sms is one message?

Hello! With the Device::Gsm I can read the sms received on my umts-modem. Sometimes one message is divided in two or more sms because of the limitation of length of one sms. Is there a way to find out if a group of sms is a part of one message? Wammu for example shoes me sms that belong together as one text. #!/usr/bin/perl use warnin...

How do I reduce number of redundant requests with mod_perl properly?

In a fairly big legacy project, I've refactored several hairy modules into Moose classes. Each of these modules requires database access to (lazy) fetch its attributes. Since those objects are used pretty heavily, I want to reduce the number of redundant requests, for example for unchanged data. Now, how do I do that properly? I've got ...

Processing a log to fix a malformed IP address ?.?.?.x

I would like to replace the first character 'x' with the number '7' on every line of a log file using a shell script. Example of the log file: 216.129.119.x [01/Mar/2010:00:25:20 +0100] "GET /etc/.... 74.131.77.x [01/Mar/2010:00:25:37 +0100] "GET /etc/.... 222.168.17.x [01/Mar/2010:00:27:10 +0100] "GET /etc/.... My humble beginnings.....

In Perl, how do I get the directory or path of the current executing code?

If I am in some library code, how do I determine the path to the file of the code that is currently executing? I know how to get the path of the top perl file by looking at ARGV, but if I load a library, how can that library know which path it is at? ...

inspect the parameters to "use", and pass on the rest?

I have a Perl module and I'd like to be able to pick out the parameters that my my module's user passed in the "use" call. Whichever ones I don't recognize I'd like to pass on. I tried to do this by overriding the "import" method but I'm not having much luck. EDIT: To clarify, as it is, I can use my module like this: use MyModule qw...

Perl XML::Simple XMLout function

I pass in the following XML to XMLin: <root foo="bar" foo2="bar2"> <pizzas> <pizza>Pepperoni</pizza> </pizzas> </root> I then edit part of the root element via hash array. I don't care about the pizza, but I do need that XML to come back out exactly as it was. However, I get the following from XMLout: <root foo="bar" foo2="bar2"> <...

Perl directory change from Windows cmd.exe

According to the manual, chdir, Changes the working directory to EXPR, if possible. This script, when executed from cmd.exe: my $path = 'C:\\some\\path\\'; print "$path\n"; chdir("$path") or die "fail $!"; results in this output: C:\some\path\ but when I am returned to the command prompt - I'm still at the original directory. Am I...

Does anyone here use the make-cdf & stats.pl program?

I came across this page: Plotting Tools where I found a set of tools with the name stats.pl and make-cdf. I can write my own but don't want to spend too much time when someone else has already done that. Does anyone have these tools or at least point me to a similar set of tools somewhere? ...

make my file readable as either Perl or HTML

In the spirit of the "Perl Preamble" where a script works properly whether executed by a shell script interpreter or the Perl interpreter... I have a Perl script which contains an embedded HTML document (as a "heredoc"), i.e.: #!/usr/bin/perl ... some Perl code ... my $html = <<'END' ; <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Tran...

Why doesn't Perl's "sort" put these hash keys in numeric order?

#!/usr/bin/perl use strict; use warnings; my %hash; foreach ( 1 .. 10 ) { $hash{$_} = $_; } foreach ( sort(keys %hash) ) { print $_ . ": " . "$hash{$_}" . "\n" ; } When I execute the above code, the result is as below: 1: 1 10: 10 2: 2 3: 3 4: 4 5: 5 6: 6 7: 7 8: 8 9: 9 I expect "10: 10" to be the last one that...

How to get Best Practical RT configuration.

How to get Best Practical's RT configuration (list of users, queues, possible values for status field, possible values for custom field) via its REST interface? Or may be there is some web page where this information can be easily parsed from? I found sources for REST interface in rt-3.8.7.tar.gz/rt-3.8.7/share/html/REST/1.0 but I know l...

Auto Generate Objects in DBIx::Class ORM in Perl

Hello, I started learning DBIx::class and I reach the point where you have to create the Objects that represents tables. Should this classes be created manually ( hard coding all the fields and relationships.....) or there is a way to generate them automatically using the database schema. I read something about loaders, but i did not kn...

TCP, HTTP and the Multi-Threading Sweet Spot

I'm trying to understand the performance numbers I'm getting and how to determine the optimal number of threads. See the bottom of this post for my results I wrote an experimental multi-threaded web client in perl which downloads a page, grabs the source for each image tag and downloads the image - discarding the data. It uses a non...

validating radiogroup with perl/cgi

Is it possible to validate a radio group (so something is checked off, or chosen) using server-side validation with Perl? If so, how? I already have it for JavaScript, but I want this form to be able to be submitted even without JavaScript enabled. Thus I will need the validation on the server-side. There is no fixed name for the radi...

Why can't I run a Perl program from TextMate?

I'm following a bioinformatics text, and this represents one of my first Perl scripts. While in TextMate, this does not produce any result. Is it functioning? I added "hello world" at the bottom and I don't see that when I run the script in TextMate. What have I done wrong? #!/usr/local/bin/perl -w use lib "/Users/fogonthedowns/myperlli...