perl

Replace specific inline CSS with HTML counterpart in Perl

Hi there. This is my first time using Stack Overflow, so if I've done something wrong let me know. I am currently trying to write a "scraper", for lack of better term, that will extract html and replace certain inline CSS styles with the HTML counterparts. For example, I have this HTML: <p style="text-align:center"><span style="font-we...

Regular expression to match empty HTML tags that may contain embedded JSTL?

I'm trying to construct a regular expression to look for empty html tags that may have embedded JSTL. I'm using Perl for my matching. So far I can match any empty html tag that does not contain JSTL with the following? /<\w+\b(?!:)[^<]*?>\s*<\/\w+/si The \b(?!:) will avoid matching an opening JTSL tag but that doesn't address the wh...

How can I share object between threads in Perl?

I have searched for related topic, but still can't solve the problem... use threads; my $person = new Person( 'Name' => "yy"); my $udp_thread = threads->new(\&udp_func); while(1) { $person->working(); } sub udp_func { #Can't call method "setName" on an undefined value: $person->setName(); } How can I visit...

Why does Perl's Archive::Tar run out of memory?

I am using below Perl code to list the files in tar archive. The size of the tar archive is always about 15MB. my $file = shift; my $tar = Archive::Tar->new("$file"); my @lists = $tar->list_files; $tar->error unless @lists; Executing this code gives me an error "Out of Memory". I have about 512MB in my Linux system and I dont want to...

How can I install Perl's DBI module on Ubuntu?

cant open perl script "Makefile.PL":No such file or directory. While installing perl-DBI im getting this error. kindly suggest some solution. ...

How can I list files under a directory with a specific name pattern using Perl?

I have a directory /var/spool and inside that, directories named a b c d e f g h i j k l m n o p q r s t u v x y z And inside each "letter directory", a directory called "user" and inside this, many directories called auser1 auser2 auser3 auser4 auser5 ... Every user directory contains mail messages and the...

How can I use File::Find to print files with the relative path only?

I am using File::Find in the code below to find the files from /home/user/data path. use File::Find; my $path = "/home/user/data"; chdir($path); my @files; find(\&d, "$path"); foreach my $file (@files) { print "$file\n"; } sub d { -f and -r and push @files, $File::Find::name; } As I am changing the dir path to the path from where...

How do I install deps for CPAN module without installing it?

This is a follow-up to my previous question about developing Perl applications. Let’s say I develop an application as a CPAN module using Module::Install. Now I upload the code to the production server, say using a git push, and I would like to install the application dependencies listed in Makefile.PL. If I simply run cpan ., the thing ...

How can I extract EXIF data using PerlMagick?

I'm currently using Perl Magick http://www.imagemagick.org/script/perl-magick.php, the perl interface to Image Magick http://www.imagemagick.org, to process & convert photos that our site users upload. I'd like to be able to also capture some of the EXIF data attached to these images and I have been able to figure out how to do this usin...

Send file (image) through socket perl

Hi, I am aware on how to send files through a socket in perl (server, client)... but I was wondering if anyone could explain or give me a reference on how to send image files through a socket ...

How to distribute native perl scripts without custom module overhead?

How can someone distribute native (non-"compiled/perl2exe/...") Perl scripts without forcing users to be aware of the custom (non-CPAN) modules that the scripts needs in order to run? The problem is users will inevitably copy the script somewhere else on the system and take the script out of its native environment and then it can no lon...

Automating GUI with Win32::GuiTest /other module

I have a Win32 Gui Application is there any way with Win32::GuiTest/or any other cpan module to automate this action : intercepting the keyboad sent by the user and change it then send it to the application ,if yes could someone show some example ? ...

How do I implement lazy module loading in Perl?

How can I implement lazy module loading in Perl? I've seen similar things in python and implementation is somewhat simpler, but in Perl I think this would be a bit harder. ...

perl: getting value out of a hash using map

It seems like I should be able to do this with map, but the actual details elude me. I have a list of strings in an array, and either zero or one of them may have a hash value. So instead of doing: foreach $str ( @strings ) { $val = $hash{$str} if $hash{$str}; } Can this be replaced with a one-liner using map? ...

How can I initialize lexical variables in a Perl while condition?

What is the proper way to write something equivalent to the follow: while ( my $first = $iterator->next && my $second = $iterator->next ) { # do work } This does not run - I wanted $first and $second in proper scope inside the while loop. ...

How do I include functions from another file in my Perl script?

Hi, This seems like a really simple question but somehow my Google-Fu failed me. What's the syntax for including functions from other files in perl? I'm looking for something like C's #include "blah.h" I saw the option for using perl modules, but that seems like it'll require a not-insignificant rewrite of my current code. Thanks a ...

How do I run a Perl script on multiple input files with the same extension?

How do I run a Perl script on multiple input files with the same extension? perl scriptname.pl file.aspx I'm looking to have it run for all aspx files in the current directory Thanks! ...

How can I "use lib" the appropriate directory depending on installation location?

Hi Everyone, I have an object-oriented web-app that is installed in multiple locations on my server. Once for "live", once for "beta", etc. Being object-oriented, it consists of many perl modules. In the main module, I must "use lib" the appropriate directory for all of the custom perl modules for that instance of the app. This is n...

How can I separate different sorts of Perl tests so I don't have to run them all?

I noticed that in Perl the custom is to stick all tests into the t directory. How do you separate the unit test from the functional ones? Or, to make the question simpler and more obvious, how do you separate the tests that run quickly from the ones that do not? When all the tests run together the testing takes too long to be routinely u...

How can I delete all /* */ comments from a C source file?

I have a C file which I copied from somewhere else, but it has a lot of comments like below: int matrix[20]; /* generate data */ for (index = 0 ;index < 20; index++) matrix[index] = index + 1; /* print original data */ for (index = 0; index < 5 ;index++) How can I delete all the comments enclosed by /* and */. Sometimes, the comment...