perl

OO-Perl Aliasing Class Attributes

I have a module that I'm working on. I am setting up a few attributes like this: $self->{FOO}; $self->{BAR}; $self->{FOOBAR}; And, I want to use AUTOLOAD to help create methods for accessing these attributes. For example, $foo->Bar() returns the value of $self->{BAR}. No problem. Everything is standard. Now, I want to create alias M...

How can I extract URLs from JSON data?

I've a text document from which I want to extract URLs and place them in a new text file. How can I do that in Perl? A sample of the text file is here: {"type":"TabGroupsManager:GroupData","id":65,"name":"XML Schema Editor","image":"http://www.altova.com/favicon.ico","disableAutoRename":false,"titleList":"XML Schema Editor\u000...

How can I print "Done" or "Fail" at the end of line to stdout in Perl?

I just have begun with Perl and I want to write my own script to scan a document and convert the resulting TIFF file to a PDF file. If the conversion succeeds (using tiff2pdf), I want to print "Done" at the end of the line, but I can't seem to find a hint to do this on the Web. My guess is that I have to get the geometry of the terminal...

How can I modify HTML files in Perl?

I have a bunch of HTML files, and what I want to do is to look in each HTML file for the keyword 'From Argumbay' and change this with some href that I have. I thought its very simple at first, so what I did is I opended each HTML file and loaded its content into an array (list), then I looked for each keyword and replaced it with s///, a...

How can Perl's WWW::Mechanize expand HTML pages that add to themselves with JavaScript?

As mentioned in a previous question, I'm coding a crawler for the QuakeLive website. I've been using WWW::Mechanize to get the web content and this worked fine for all the pages except the one with matches. The problem is that I need to get all these kind of IDs: <div id="ffa_c14065c8-d433-11df-a920-001a6433f796_50498929" class="areaMap...

How can I get all local extrema in Perl without rolling my own?

It's not too difficult to implement, but I'd prefer code reuse if possible. my @arr = (2,3,4,5,5,5,4,4,3,1,1,2,3,0,2,4); my $ret = {MAXIMA=>[{INDEX=>3, VAL=>5},{INDEX=>4, VAL=>5},{INDEX=>5, VAL=>5}], MINIMA=>[{INDEX=>9, VAL=>1},{INDEX=>10, VAL=>1},{INDEX=>13, VAL=>0}]} So, do you know of any module that implements something...

What is the most elegant way in Perl to expand an iterator into a list?

I have an iterator with this interface: $hit->next_hsp The current implementation to listify it is: my @list; while ( my $hsp = $hit->next_hsp ) { push( @list, $hsp ); } Now I'm thinking that there might be better ways to do this in less code. What do you say, stackers? ...

Perl - Push into arrays using variable references versus using variable copies

Question: Why can't I push elements into a 2d array that's inside of a while loop that parses through a SQL result set? I need some help here as to why this happens. The way data is stored into a 2d array can be done several ways, but for my purposes, I need to use the push method. Here's some code that works: my @tt = (0,1,2,3); my...

How can I serialize and deserialize Perl data to/from database?

What is the best module or approach to serialize data into a database? Currently I am looking into Storable functions freeze and thaw, example: use Storable qw(freeze thaw); use strict; my %array_test = ('Year Average' => 0.1, 'Color Average' => 0.8, 'Humans' => 0, 'Units' => 1); my $serialized_data = freeze(\%array_test); my %deseria...

In Perl, what's the difference between "if defined $count" and "if $count"?

I have the following script: #!/usr/bin/perl use warnings; use strict; my $count = 0; my ( @first , @second , @third ); while ($count <= 7){ push ( @first , $count); push ( @second , $count) if defined $count; push ( @third , $count) if $count; $count++; } print "first: @first\n"; print "second: @second\n"; print "...

How do I call a Javascript Function from onclick event of submit button in Perl?

Hello everyone, I am trying to fire a javascript by onclick event of submit button but not able to, Details of my code are "i have a button named filter and two text boxes which take the Id and Name, All i want is "When i enter the value in Id textbox and click Filter then i want the values to be displayed on URL using QueryString". here...

Is there a Perl equivalent of which?

Possible Duplicate: Is there a Perl module that works similarly to the Unix which command? I'm looking for an equivalent of which in Perl that would give me the full path to a program according to the current $ENV{PATH}. Is there a CPAN module to do that? Or should I roll my own? ...

Does Statistics::Descriptive percentile method work as documented?

use strict; use warnings; use Statistics::Descriptive; use 5.012; my @data = ( -2, 7, 7, 4, 18, -5 ); my $stat = Statistics::Descriptive::Full->new(); $stat->add_data(@data); say ($stat->percentile(100) // "undef"); # return 18. OK. say ($stat->percentile(0) // "undef"); # return undef instead of "-inf". see doc below Statistics::Desc...

How can I compile my Perl script so to reduce startup time?

Is there a way to save a compiled version of my perl scripts? Or a way to do a JavaScript style compile where you just remove comments, whitespace, etc? ...

Can I use smart matching, ~~, in Test::More's cmp_ok?

[start EDIT] Yes, you can. See Michael Carman answer. The initial question title "Is it possible to use a test like Test::More::cmp_ok but that accepts '~~' (smart match operator) with not a scalar at the 'expected' argument?" was idiotic and with the help of Brian d Foy it has become the current one. You can skip the rest of the que...

How can I prevent Perl from using a module, for testing purposes?

I am developing a suite of Perl scripts and modules that then get deployed on different machines and systems round our company. Some facilities are dependent on a particular module which may or may not be installed on different machines. I have used 'eval' to detect whether or not this module is available. I've just had a fault report...

How can I round a date to nearest 15 minute interval in Perl?

I want to round current time to the nearest 15 minute interval.So if it is currently 6:07, it would read 6:15 as the start time. How can I do that? ...

How can I communicate across Perl CGI scripts?

I am searching for efficient ways of communication across two Perl scripts. I have two scripts; Script 1 generates some data. I want my Script 2 to be able to access that information. The easiest/dumbest way is to write the data generated by Script 1 as a file and read it later using Script 2. Is there any other way than this? Can I st...

How can I manipulate just part of a Perl string?

I'm trying to write some Perl to convert some HTML-based text over to MediaWiki format and hit the following problem: I want to search and replace within a delimited subsection of some text and wondered if anyone knew of a neat way to do it. My input stream is something like: Please mail <a href="mailto:[email protected]&amp;Subject=Please ...

How can I modify a Perl DateTime object?

In my script I need to make a cycle like this one: use DateTime; for $j(0..3){ my ($date) = DateTime->now->ymd; my ($k) = 0; while($k <= $j){ $date = ($date->subtract( days => 7)); $k++; } print "$date\n"; } which should get the current date, then one week ago, etc. Sadly, after getting the correct curr...