perl

What does __PACKAGE__->{foo} mean ?

I'm refactoring a perl module in legacy code, and this is a function from the module: sub get_user { my $user = __PACKAGE__->{user}; if (!defined $user) { # more code __PACKAGE__->{user} = $user; } return $user; } This module compiles under use strict. And there's no package variables defined. What do...

How can call a PHP function from Perl code?

I have a function written in PHP and would like to call this inside a CGI script. Is there any direct way to do this? I am not sure if its even possible. The CGI script will be inside cgi-bin directory and the PHP function will be outside this folder. ...

Undefined symbol building WWW::Curl::Easy Perl module on AIX 5.3

I'm trying to get the WWW::Curl::Easy Perl module installed on AIX 5.3. I have curl installed (from source) in /usr/local. When trying to build the Perl module, I get this: $ perl Makefile.PL Found curl.h in /usr/local/include/curl/curl.h Building curlopt-constants.c for your libcurl version Building Easy.pm constants for your libcurl ...

perl print array from subroutine

#! /usr/local/bin/perl sub getClusters { my @clusters = `/qbo/bin/getclusters|grep -v 'qboc33'`; chomp(@clusters); return \@clusters; } ummm okay .. how do I get at this array to print since ... foreach $cluster (getClusters()) { print $cluster."\n"; } doesn't seem to work. Thanks. ...

how to create methods from arrays or hashes in perl6

I am trying to add new methods to an object dynamicaly. Following code works just fine: use SomeClass; my $obj = SomeClass.new; my $blah = 'ping'; my $coderef = method { say 'pong'; } $obj.^add_method($blah, $coderef); $obj.ping; this prints "pong" as expected, whereas the following will not work as expected: use SomeClass; my $...

perl file upload can't init filehandle

Hi! I tried to use this very simple script for uploading a file to my server. For some reason it is not working. I get the following message in my apache error log: Use of uninitialized value in <HANDLE> at /opt/www/demo1/upload/image_upload_2.pl line 15. readline() on unopened filehandle at /opt/www/demo1/upload/image_upload_2.pl li...

Trouble with downloading files

I am trying to download a file from a site using perl. I chose not to use wget so that I can learn how to do it this way. I am not sure if my page is not connecting or if something is wrong in my syntax somewhere. Also what is the best way to check if you are getting a connection to the page. #!/usr/bin/perl -w use strict; use LWP; use ...

MySQL driver module issue with Movable Type

I am able to get mt-check to run, but it says that DBD::MySQL module is not installed. Here is what it says: DBI (version >= 1.21) Your server has DBI installed (version 1.52). DBD::mysql Your server does not have DBD::mysql installed, or DBD::mysql requires another module that is not installed. The DBD::mysql database driver is requi...

Perl - Is it good practice to use the empty string as false?

Is it safe/good practice in Perl to use an empty string as false in boolean comparisons? ex: my $s = ''; if($s) { print 'true'; } else { print 'false'; } or would the length function be a better way to go: my $s = ''; if(length($s) > 0) { print 'true'; } else { print 'false'; } ...

Most efficient way to call Perl Libraries from within PHP?

Possible Duplicate: How can I use Perl libraries from PHP? I would like to make use of some libraries only available in Perl from my PHP applications. I haven't used Perl before but have been looking into it some and am still not sure of the best way to do this.. it seems a lot of the resources I found online were pretty old t...

How can I get the contents of a followed link in WWW::Mechanize?

This is my last question for this I hope. I am using $mech->follow_link to try to download a file. For some reason though the file saved is just the page I first pull up and not the link I want to follow. Is this the correct way I should download the file from the link? I do not want to use wget. #!/usr/bin/perl -w use strict; ...

How to configure MAMP to serve perl CGI scripts (NOT localhost!)

I'm using MAMP-pro to serve my domain to the outside world. I'm not a very experienced sys-admin, though I've slogged my way through a few basic things. I know what apache is, and I can read-most-of but not generate-without-guide related .conf files. I've got a perl script which I've tested from the command line and it works (outputs ...

perl split string into 2d array

Okay .. this works ... sub getApSrvs { my %apsrv; my $cluster; foreach $cluster (getClusters()) { $apsrv{$cluster} = [split('\s+', `/$cluster/bin/gethosts -t app|sort -u`)]; } return %apsrv; } ... now how in the ham sandwich do I get this to print like so $cluster --> $hostname okay I added : my %apsrv = getApSrvs(); for...

perl how to pass argument to ARGV from a text file

I have a list of arguments to pass into a perl script, using ARGV. The 4th argument, is a servername, but I want to pass it a text file with a list of servers called servers.txt. How do I pass that in and use it as an argument to ARGV? Sample file 'servers.txt': server1 server2 server3 Working code: # usage example: ./test.pl Jul 05...

How to print all values of an array in perl

I am trying to do print all of the values of an array from a CSV file. I am sort of manually doing this in the example below. Can someone show me the code for doing this for all of the fields of the array no matter how many fields there are? I'm basically just trying to print each field on a new line. #!/usr/bin/perl use strict; use ...

How can I get links that match a regex using WWW::Mechanize?

I'm trying to use regular expressions to catch a link, but can not. I have all the links, but there are many links that do not want. What I do is to grab all links: http://valeptr.com/scripts/runner.php?IM= To comply with this pattern. I put the script I'm doing: use warnings; use strict; use WWW::Mechanize; use WWW::Mechanize::Sleepy...

Perl pack/unpack/shift

I've been having this problem in Perl for a few days now, and after scouring countless man pages, perldocs and googling too many search terms, hopefully someone here can help me out. I am given two strings which represent hex values, i.e. "FFFF", not the Perl hex number 0xFFFF. Given two of these strings, I wish to convert them to bina...

array to hash in perl

I have a source list from which I am picking up random items and populating the destination list. The item that are in the list have a particular format. For example: item1{'name'} item1{'date'} etc and many more fields. while inserting into the destination list I check for unique names on items and insert it into that list. For this...

Is there any Perl module to set up an object from a default configuration plus a hashref of optional configurations?

I'm finding myself repeatedly writing and rewriting the following kind of code: my %default = (x => "a", y => "b"); sub new { my ($package, $config) = @_; my $self = {%default}; for my $k (keys %default) { $self->{$k} = $config->{$k} if defined $config->{$k}; } for my $k (keys %$config) { ...

How can I call a shell command in my Perl script?

Can anyone give me an example on how I can call a shell command, say 'ls -a' in a Perl script and the way to retrieve the output of the command as well. ...