Given a data structure (e.g. a hash of hashes), what's the clean/recommended way to make a deep copy for immediate use? Assume reasonable cases, where the data's not particularly large, no complicated cycles exist, and readability/maintainability/etc. are more important than speed at all costs.
I know I can use Storable, Clone, Clone::M...
I'm not sure if memory is the culprit here. I am trying to instantiate a GD image from data in memory (it previously came from a database). I try a call like this:
my $image = GD::Image->new($image_data);
$image comes back as undef. The POD for GD says that the constructor will return undef for cases of insufficient memory, so that...
I've often seen people use Perl data structures in lieu of configuration files; i.e. a lone file containing only:
%config = (
'color' => 'red',
'numbers' => [5, 8],
qr/^spam/ => 'eggs'
);
What's the best way to convert the contents of these files into Python-equivalent data structures, using pure Python? For the time being...
Whats the best way to separate the string, "Parisi, Kenneth" into "Kenneth" and "Parisi"?
I am still learning how to parse strings with these regular expressions, but not too familiar with how to set vars equal to the matched string & output of the matched (or mismatched) string.
...
Does anyone know of a free Perl program (command line preferable), module, or anyway to search and replace text in a PDF file without using it like an editor.
Basically I want to write a program (in Perl preferably) to automate replacing certain words (e.g. our old address) in a few hundred PDF files. I could use any program that suppor...
Can somebody advise me what this code does and how can I convert it to Ruby in most simple way?
#!perl
use Convert::ASN1;
my $asn1 = Convert::ASN1->new(encoding => 'DER');
$asn1->prepare(q<
Algorithm ::= SEQUENCE {
oid OBJECT IDENTIFIER,
opt ANY OPTIONAL
}
Signature ::= S...
Rails is a great platform, but it just doesn't have the history that Perl does, so I thought it might be an interesting idea to put them together. Anybody with lots of Rails experience see any problems with this?
...
I have a very common situation. I have a file, and I need to entirely overwrite that file with new contents. However, the original file is accessed on every page load (this is a web app), so it can't be missing for very long. A few ms is OK (though not ideal), a second is not OK.
Right now I do this by writing a temp file to the same di...
I understand one uses the "bless" keyword in Perl inside a class's "new" method:
sub new {
my $self = bless { };
return $self;
}
But what exactly is "bless" doing to that hash reference ?
...
I would like to do the following:
$find="start (.*) end";
$replace="foo \1 bar";
$var = "start middle end";
$var =~ s/$find/$replace/;
I would expect $var to contain "foo middle bar", but it does not work. Neither does:
$replace='foo \1 bar';
Somehow I am missing something regarding the escaping.
I fixed the missing 's'
...
I got into Perl years ago and always found it a fun and expressive language to work with.
I found that programming in Perl makes me quite productive thanks to its low overhead and the outstanding amount of ready-made solutions to common problems on CPAN.
If you're new to Perl, what got you into it?
...
The following snippet of code is used to find the PID of a user's terminal, by using ptree and grabbing the third PID from the results it returns. All terminal PID's are stored in a hash with the user's login as the key.
## If process is a TEMINAL.
## The command ptree is used to get the terminal's process ID.
## The user can ...
This might be a problem with my understanding with Curses more than with Perl, but please help me out. I'm using Curses.pm which works quite well except when I try to create a curses "window". Example code:
use Curses;
initscr;
$w=newwin(1,1,40,40);
$w->addstr(20,20,"Hello");
$w->refresh;
refresh;
endwin;
outputs nothing. Not using a ...
I need code in Perl for requesting and parsing ATOM and RSS feeds. Is there a CPAN module(s) for that?
...
I have some old perl code which recently stopped working on a FreeBSD box. The code which fails looks (in simplest form) like this:
#!/usr/local/bin/perl -w
use strict;
use DBI;
my $datasource = "DBI:mysql:dbname:hostname.domain.com";
my $user = "username";
my $pass = "password";
DBI->connect($datasource, $user, $pass);
This fails...
i want to compare the current time and file creation time in Perl but both are in different format. localtime is in this format:
22116291110813630
and file creation time is
Today, December 29, 2008, 2:38:37 PM
How do i compare which one is greater and their difference?
...
I upgraded to Ubuntu Intrepid Ibex yesterday and suddenly some of the Perl modules that I installed (on the Hardy Heron) have all gone missing!
I get the usual "Can't locate module in @INC" error. Has any of the CPAN repositories changed or something for Intrepid? Google doesn't help at all.
Thanks in advance.
...
A recent question here on SO got me thinking.
On most Linux distributions that I tried, some Perl modules would be available through the package manager. Others, of course, not. For quite a while I would use my package manager whenever I needed to install some CPAN module to find out whether a package was available or not and to install...
.NET has the Uri class.
Perl has its URI module.
The major difference is that URI.pm allows you to retrieve the query string components as a hash, and set a hash into the URI to construct a nice URI with query arguments. I don't see anything like that on the .NET side. Is there some hidden class I don't know about?
...
There are many debugging option available, but it says you need to compile Perl with
-DDEBUGGER option. How do we do that on Windows with ActivePerl.
Also, I had this problem of out of memory with Perl. I was reading a XML file with 5 lines but the second line was way way too big, (the file size was 4.3Mb) for 5 lines.
It does not pars...