perl

In Strawberry Perl, what is the difference between perl\lib and perl\site\lib?

In the Strawberry Perl distribution for Win32, what is the difference between perl\lib and perl\site\lib? When CPAN modules are installed, are the files all stored in perl\site\lib by default? Is perl\lib reserved for modules that come with the standard Perl distribution? ...

Why am I getting a "Odd number of elements in anonymous hash" warning in Perl?

Help, I'm trying to create a new post in my wordpress blog with custom fields using the following perl script using metaweblogAPI over XMLRPC, but there seems to be an issue with the custom fields. Only the second custom field (width) ever seems to get posted. Can't get the "height" to publish properly. When I add another field, I get th...

How should I promote Perl warnings to fatal errors during development?

When running an applications test suite I want to promote all Perl compile and run-time warnings (eg the "Uninitialized variable" warning) to fatal errors so that I and the other developers investigate and fix the code generating the warning. But I only want to do this during development and CI testing. In production, the warnings should...

How do I match words of a specific length with a regex in Perl?

I want to find a word which is only three letter and starts with t and ends with e. Is there any other way, apart from what i have done: open (FH, "alice.txt"); @lines = <FH>; close(FH); foreach $words(@lines) { if($words =~ m/ t.e /g) { print $words," "; } } Also I wanted to find words which are more than 3 letters lon...

How can I use cURL or Wget inside of a Perl program?

I am trying to download and output to a file using cURL in a Perl script. 1) I have to pass username and password in the following below. What switch should I use? 2) When I execute Perl script, this is what I get: Can't locate WWW/Curl.pm in @INC (@INC contains: f:/Perl/site/lib f:/Perl/lib .) at onesec.pl line 9. BEGIN failed--comp...

Why don't I get the right package variable when using our()?

The below program prints "var = 13" and "var = 13". Shouldn't it print "var = 3" and "var = 13"? use warnings; use strict; package p1; our $var = 3; package p2; our $var = 13; sub temp { package p2; print "var = $var\n"; } package p1; print "var = $var\n"; #This prints var = 13. Why is it picking p2::var as the current packag...

Is « my » overwriting memory when called in a loop?

Hi, A simple but relevant question: Is « my » overwriting memory when called in a loop? For instance, is it "better" (in terms of memory leaks, performance, speed) to declare it outside of the loop: my $variable; for my $number ( @array ) { $variable = $number * 5; _sub($variable); } Or should I declare it inside the loo...

Why is ssh prompting me for a password after I give it to Perl's Net::SSH::Perl?

I am using Net::SSH::Perl to execute a command on a remote server as follows: use Net::SSH::Perl; my $ssh = Net::SSH::Perl->new($host); $ssh->login($user, $pass); my ($stdout, $stderr, $exit) = $ssh->cmd($cmd); But when I execute the above script, a password prompt comes again. Meaning the password I supplied in $pass is not taken to ...

Why can't I assign @b || @c to @a in Perl?

I'd like to perform some convoluted variation of the @a = @b || @c assignment, with the intent of taking @b if non-empty (hence true in a boolean sense), @c otherwise. The documentation explicitely tells me I can't. (And it's right about the fact, too!) The "||", "//" and "&&" operators return the last value evaluated (unlike C's...

How can I rearrange the order of items in this template, using Perl?

How can you convert the following matches to the given result? My files have the following matches -- cut -- Lorem ipsun Hello lorem ipsun { $hello } @param integer $question_id // example of the match Lorem ipsun Hello lorem ipsun { $hello } -- cut -- I would like to change them efficiently to @param $question_i...

How can I run a shell script on a remote machine with a local Perl program?

I'm writing a Perl script that is to be run on a PC networked with a computer running Linux. The script must give input to, and receive results from, a set of shell scripts on the Linux machine. I'm able to copy the input files from the PC and even invoke a Perl script on the Linux machine, but when that script attempts to run the .sh fi...

Perl memory usage profiling and leak detection?

I wrote a persistent network service in Perl that runs on Linux. Unfortunately, as it runs, its Resident Stack Size (RSS) just grows, and grows, and grows, slowly but surely. This is despite diligent efforts on my part to expunge all unneeded hash keys and delete all references to objects that would otherwise cause reference counts...

Representing a complex Perl data structure containing array references in Config::General

I have the following data structure in Perl code: my $config = { 'View::Mason' => { comp_root => [ [ 'teamsite' => 'root/teamsite' ], [ 'components' => 'root/components' ], ], }, }; I'm trying to represent this structure in a Config::General configuration file. So far I have: <Vi...

Why does Net::OpenID::Consumer fail when trying to grab Google's OpenID discovery endpoint?

I'm implementing OpenID support for a public website. Yahoo and Verisign openid authentication currently works fine. However, I cannot seem to connect to Google's endpoint. Below is the code: Usual initialization and stuff... my $csr = Net::OpenID::Consumer->new( ua => LWP::UserAgent->new(), consumer_sec...

Read CSV and create different arrays.

I am creating a script to read values from csv files and use the values for other taskes. I have written the below code to read values. sample file: site,type,2009-01-01,2009-01-02,.... X,A,12,10,... X,B,10,23,... Y,A,20,33,... Y,B,3,12,... and so on.... Code: my @value; while (<INFILE>) { next if $_ !~ /B/; my ($v1, $v...

Making Catalyst calls from the model?

I'm using Catalyst with Catalyst::Plugin::Authentication and Catalyst::Plugin::Authorization::Roles and am wondering if there is a better approach to adding an attribute to a model that I'm not seeing. Each user is permitted to access one or more companies, but there is always one primary (current) company at a time. The permitted list ...

Is this the equivalent function call to a Perl constructor call?

I can have a constructor like this : sub create { my $class = shift; my $self = {}; return bless $self,$class; } and when I create an object, I can write this: my $object = create Object; Is this: my $object = Object::create("Object"); the only equivalent to that constructor call? ...

How can I have a minimal match between two known tokens?

I have a selection of text that looks like the following. I need to do a rudimentary edit on it, but can't fathom the regex that I need. Maybe it's just been a long day, and I'm not seeing what I need. Sample data: START ITEM = 1235 BEGIN WORD RATE = 98 MORE WORDS CODE = XX STUFF END ...

Whitespace woes in Regex

I am using a simple Perl script to parse XML and convert it to usable SQL. My current SQL lines go something like this: INSERT INTO table VALUES ('data1', 'data2', 'data3', ); Obviously I need to remove the comma at the end there. Sounds simple but I just can't get regex to find it. I tried s/,\s+)/)/ but that doesn't change anything...

Can Perl method calls be intercepted?

Can you intercept a method call in Perl, do something with the arguments, and then execute it? ...