perl

How can I perform a substitutions on multiple variables whose names I don't know ahead of time?

I'm working on a Perl script where the user adds a number of set variables at the beginning of the script, all prefixed with $XX, as seen below. The user-set variables, however, need to go through a short transformation function to clean them up. Is there a way to run the sub on all the variables with the $XX prefix? my $XXvar1 = "some...

Why can't Perl's Class::XSAccessor find Array.so?

Hello all This is my first post and I am hoping someone can point me in the right direction. I have tried Google but am not coming up with anything; actually, there are hardly getting any hits so I assume this is going to be a pretty obscure error. I am trying to run a perl application (squeezecenter-7.3.3) on Solaris 10 and get the ...

How can I make C-p an emacs prefix key for Devel::PerlySense?

Hi, I just installed Devel::PerlySense 0.0180. I have put the following in my .emacs file: ; PerlySense (load "~/perly-sense") (global-unset-key "\C-p") (global-set-key (kbd "\C-p \C-d") 'perly-sense-smart-docs-at-point) (global-set-key (kbd "\C-p \C-g") 'perly-sense-smart-go-to-at-point) But, now whenever I try to load a Pe...

Extract values after match a keyword

Hi all, I would like to extract values after I match the keyword "coor" multiple times in a string. My code doesn't do that at all. Can anyone help me to fix it please? My code: my $str = ; if ($str =~ /$keyword/) { if ($' =~ /\[/) #'# everything after the matched string { $str=~ /\(coor\s(\d+)\s(\d+)\)\s\(coor\s(\d+)\s(\d+)\)...

How can I store a Perl array in an array?

I want to be able to place an array into an array. For example, I may have an array like this: my @array1 = ("element 1","element 2","element 3"); Then I have another array my $array_ref = ["this will", "go between", "element 1 and 2"]; I want to place $array_ref into the first so that the first array looks like this: ("element 1"...

How can I configure Devel::SmallProf to work with mod_perl?

I have the following version being installed: Apache::SmallProf - 0.09 Apache::Registry - 2.01 Devel::SmallProf - 2.02 And I try to add the following settings in my apache config file (/usr/local/apache_modperl/conf/httpd.conf): <Perl> require Apache::DB; Apache::DB->init; </Perl> <Directory /home/website/www/cgi-m> Set...

How can I write a long regular expression so it fits on the screen?

I have match regular expresion in Perl. The match sentence that spreads over more than one line. I realize that I must enter the match regular expresion in one line only, if I spread to multiple lines it fails: $array_11 =~ m{By Steve (.*), MarketWatch LONDON (.*) -- Shares of Anglo American rallied on Monday morning as (.*) bet that t...

Does Perl's $| setting affect system commands?

I am looking at some old code in Perl, where the author has writtern $| = 1 in the first line. But the code does not have any print statements, it calls a C++ binary using the system command. Now I read that $| will force flush after every print. So does it affect the system command's output in any way or am I safe to remove that line....

How do I access deep data in a nested XML structure in Perl using XML::Simple?

I am using XML::Simple and I have the following XML structure in a variable $xmldata which I need to access through Perl code. <root> <a>sfghs</a> <b>agaga</b> <c> <c1>sgsfs</c1> <c2>sgsrsh</c2> </c> <d> <d1>agaga</d1> <d2>asgsg</d2> </d> </root> I can access the value of a and b b...

How can I get digits out of a Perl bignum?

I have a really big number in Perl. I use "bignum". How can I extract single digits out of this big number. For example if I have a number like this and what to get the 3rd digit from the end: 1029384710985234058763045203948520945862986209845729034856 -> 8 ...

How can I convert JSON boolean values for output using XMLout?

There are boolean values in the JSON data structure I am using. When call decode_json to convert it to a Perl data structure and feed to the XMLout function provided by XML::Simple, it throws an error because XMLout does not know how to deal with JSON::XS::Boolean values. Is there a way to convert the JSON::XS::Boolean values in a data ...

Is there a Python interface to the Apache scoreboard (for server statistics)?

In short: Is there an existing open-source Python interface for the Apache scoreboard IPC facility? I need to collect statistics from a running server WITHOUT using the "mod_status" HTTP interface, and I'd like to avoid Perl if possible. Some background: As I understand it, the Apache web server uses a functionality called the "score...

How do I use Perl's LWP to log in to a web application?

I would like to write a script to login to a web application and then move to other parts of the application: use HTTP::Request::Common qw(POST); use LWP::UserAgent; use Data::Dumper; $ua = LWP::UserAgent->new(keep_alive=>1); my $req = POST "http://example.com:5002/index.php", [ user_name => 'username', user_password => "passwor...

How can I replace only the captured elements of a regex?

I'm trying to extract only certain elements of a string using regular expressions and I want to end up with only the captured groups. For example, I'd like to run something like (is|a) on a string like "This is a test" and be able to return only "is is a". The only way I can partially do it now is if I find the entire beginning and end...

How to read information from file using regex and print it?

I am working with the following data: __DATA__ Branch 1: 10..11 13 E 0.496 -> Q 0.724 18 S 0.507 -> R 0.513 19 N 0.485 -> S 0.681 Branch 2: 11..12 81 R 0.891 -> Q 0.639 88 Y 0.987 -> S 0.836 From the above data, I want to read numbers present before a character and then print them out. So for instance ...

Why is Net::SNMP trying to load the wrong libnetsnmp.so?

Hi, I created a Perl script and tested it on a couple of servers running Net::SNMP 5.3.1-19, but now I'm trying to run it on a different server and I'm getting the following error: Can't load '/usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/auto/NetSNMP/default_store/default_store.so' for module NetSNMP::default_store: libnet...

How can I use Perl libraries from PHP?

I want to use Perl libraries from a PHP application. I have heard that it is possible. I have considered the possibility of re-writing the libraries in PHP, but I do not think that is a good idea because it is difficult. ...

Multiline search replace with Perl

I know this kind of questions have been asked already many times before. The reason why I come here again is that I feel like I've missed something simple and fundamental. Is it possible to make this kind of search-replace routine better. For example without opening same file twice. Also speed related advices are welcome. Please notice...

Perl loop stuck reading file?

Closing this question. Will drink red bull. Sleep. Code and come back with brand spanking new question with unit test cases. UPDATE: The new file is here Also the config file is here I refactored the code again: sub getColumns { open my $input, '<', $ETLSplitter::configFile or die "Error opening '$ETLSpliter::configFile':...

How can I get the absolute path of my Perl program from its relative path?

I need to find the full path to the Perl script I'm currently running, i.e. for ~/dir/my.pl I would need it to be "/home/user/dir/my.pl". The $0 will give me "~/dir/my.pl". for ./my.pl I would still need "/home/user/dir/my.pl" etc. Thanks! ...