perl

How do I mock Perl's built-in backticks operator?

I'd like to unit test a Perl program of mine that is using backticks. Is there a way to mock the backticks so that they would do something different from executing the external command? Another question shows what I need, but in Ruby. Unfortunately, I cannot choose to use Ruby for this project, nor do I want to avoid the backticks. ...

Using OLE to get text out of Powerpoint

I am trying to use Win32::OLE to get a list of slides and their titles from the current presentation. So far I can get my $powerpoint = Win32::OLE->GetActiveObject('Powerpoint.Application') my $ap = $$powerpoint { ActivePresentation } ; my $slides = $$ap { slides } ; But $slides only has properties Application Count Pare...

Which Perl built-ins cannot be overridden in CORE::GLOBAL?

The Overriding Built-in Functions section of the perlsub documentation provides There is a second method that is sometimes applicable when you wish to override a built-in everywhere, without regard to namespace boundaries. This is achieved by importing a sub into the special namespace CORE::GLOBAL::. and then gives a few examples. ...

How complex is Perl? Is it easy to learn?

At first, I was doing C (2 years). Now, I am doing PHP (1.5 years). My boss wants me to learn Perl now. He says the company is going to have many Perl projects now and he need me to do it. How complex is Perl to learn in my case? Should I clearly say no to him OR should I give it a try. Edit: You all asked why I would say no to ...

open source license scanner (heuristic, regular expression matches in subdirs)

Assume you have a small collection of WebCMS assembled, subdirs in ~/www/test/ or so. And now you want to quickly/crude scan and detect the license in each project. Is there a simple grep/perl/regex scanner which can guess the used licenses? Doesn't need to be exact or reliable, just for getting a rough overview, and just needs to inspe...

Set up MIME::Lite on Windows 7 without Outlook

Hi, I run ActiveState's ActivePerl on my Windows 7 box. I just installed the MIME::Lite module using the PPM (Perl Package Manager). The installation went fine. However, as I try to run a very simple script use strict; use MIME::Lite; my $msg = MIME::Lite->new( From => '[email protected]', To => '[email protected]...

How to read and extract information from a file that is being continuously updated?

This is how I am planning to build my utilities for a project : logdump dumps log results to file log. The results are appended to the existing results if the file is already there (like if a new file is created every month, the results are appended to the same file for that month). extract reads the log result file to extract relevant...

Perl & Image::Magick, getting color values by pixel

I'm using Perl and the Image::Magick module to process some JPEGs. I'm using the GetPixels sub to get the RGB components of each pixel. e.g. my @pixels = $img->GetPixels( width => 1, height => 1, x => 0, y => 0, map => 'RGB', #normalize => 1 ) print Dumper \@pixels; $img->Resize( ...

Socket message hangs until thread completes in Perl

I am trying to write Perl code that does two-way communication over a Unix socket. It needs to do the following things: Client code sends a request over the socket Server code reads the request Server performs any actions that should happen immediately Server creates a new thread to do additional actions that may take a long time Serv...

Is there an equivalent of `tail -f` in Perl?

I'm writing a script that listens for changes to a log file and acts appropriately. At the moment I'm using open my $fh, "tail -f $logfile |"; but ideally I don't want to use system calls. I've tried File::Tail but it has a minimum interval of 1 second (I've tried passing less but it defaults to 1 second, even if I pass 0). I've check...

How do I use SWIG in Perl?

I am totally new to SWIG interfaces and how to use this with C and Perl. It will a great help to me, if someone explains about using Perl and C with SWIG. ...

Visit Half Million Pages with Perl

Currently I'm using Mechanize and the get() method to get each site, and check with content() method each mainpage for something. I have a very fast computer + 10Mbit connection, and still, it took 9 hours to check 11K sites, which is not acceptable, the problem is, the speed of the get() function, which , obviously, needs to get the pag...

How do I use Perl's Inline::C?

I have a piece of code like this (Perl file): print "9 + 16 = ", add(9, 16), "\n"; print "9 - 16 = ", subtract(9, 16), "\n"; C code also, #include<stdio.h> main () { int x = 9; int y = 16; printf(" add() is %d\n", add(x,y)); printf(" sub() is %d\n", subtract(x,y)); // return 0; } int add(int x, int y) { return x + y; } int ...

What is wrong with this if-elsif-else block in my Perl script?

I'm trying to write a condition for a nested if statement, but haven't found a good example of using or in if statements. The following elsif condition fails and allows the code nested beneath it to fire if $status == 6: if ($dt1 > $dt2 ) {do one thing} elsif(($status != 3) || ($status != 6)) { do something else} else {do something com...

In Perl, how can I check from which module a given function was imported?

I have a code which calls the function. But I don't know the module this function belongs to. I need it to modify this function. How can I check it? ...

How can I send email to multiple email addresses using Email::Simple in Perl?

I want to be able to send email to multiple email addresses in: my $email = Email::Simple->create( header => [ To => '"My Name" <[email protected]>', From => '"Someone1" <[email protected]>', Subject => $subject, ], body => $body ); sendmail($email, {transport => $transport}); Is it poss...

perl dbi rollback not working

Hello, i am using this approach. If there is an error in the sql, rollback only happens for the first id of the asset_group. Rest of the ids are ignored. Am i doing it the right way? my $sql = "sql batch that update and insert depending on the condition"; $dbh->{RaiseError} = 1; $dbh->{PrintError} = 0; $dbh->{AutoCommit} = 0; m...

perl and huge databases, how to search and store?

I have a task and would like to develop in my mind how i should go around programming this. I will probably be given a csv format database which would have minimum 36 million lines of data. In the future, users would need to search this "database" through CGI/perl interface based on some conditions depending on multiple column values an...

Why is `$@` untrustworthy?

I seem to recall that it is not safe to trust the value of $@ after an eval. Something about a signal handler having a chance to set $@ before you see it or something. I am also too tired and lazy right now to track down the real reason. So, why is it not safe to trust $@? ...

What are the implications of not closing a directory handle in Perl?

I recently inherited some code that someone else had written. I discovered that everywhere in the code that a directory was opened for reading, it was never closed because the original developer had a syntax problem - he was using the close function to try to close a directory handle instead of the closedir function. The code was som...