perl

How can I check if a Perl module is installed on my system from the command line?

I tried to check if XML::Simple is installed in my system or not. perl -e 'while (<@INC>) { while (<$_/*.pm>) { print "$_\n"; } }' The above one-liner was used for listing all modules installed in my system. However, it is not listing XML modules. However, the following executes fine. perl -e "use XML::Simple " What might be the i...

How can I decrypt a file encrypted in Perl using Crypt::CBC (Blowfish) in C?

I have a small encryption tool in Perl which uses the Crypt::CBC and Blowfish to encrypt files. I want to write the decryption algorithm in C or C++ ... Please somebody help me in doing this. ...

In Perl how do you dynamically pick what method to use as a callback?

In Perl, it's pretty trivial to specify a callback or code reference if its package is known: package Foo; sub foo { print "in foo" } # and then package main; sub baz { my $code = shift; $code->(); } baz( \&Foo::foo ); And this prints in foo. Lets say you have an object, ever so trivial, like this: package Foo; sub new ...

Parsing comma separated lines and calculating sum

So basically my problem can be written in pseudo-code as follows: split the line by = using value before =, find the next line check this the value after = matches previous if not, then loop till end of file collect all the values which match and using the line numbers, get the last 2 columns value sum all the values for a given set wit...

Perl REST flow layout

I'm using Apache and Perl (modperl), with Handlers to handle requests. I'm new to this, and I'm not quite sure how to lay things out in a sensible way. Right now I have the following: package MyClass::Handler; use warnings; use strict; # includes our %action = ( 'a' => \&a, # And more ); sub handler { my $a = shift; ...

How can I grab multiple lines after a matching line in Perl?

I'm parsing a large file in Perl line-by-line (terminated by \n), but when I reach a certain keyword, say "TARGET", I need to grab all the lines between TARGET and the next completely empty line. So, given a segment of a file: Line 1 Line 2 Line 3 Line 4 Target Line 5 Grab this line Line 6 Grab this line \n It should become: Line 4 Ta...

How can I change the Apache ErrorDocument from a Perl handler?

Is there a way to have your PerlAuthenHandler, PerlAuthzHandler, or even your PerlHandler change the error document for a request? Example: When the user goes to a specific page and gets an error, I want to have a subroutine choose what error document errors are thrown to. ...

Why does my Perl script exit with 137?

Is there a way to eliminate a warning (exit code 137) in perl? I am running a Perl script on linux within another shell script. This Perl script exits with a warning and exit code 137. I could not pinpoint what exit code 137 stands for. What is the best way to avoid this warning? I tried "no warnings" in the script and I have an exit 0...

How can I import global variables from a base module?

I created a module Foo::Prototype with the global variables $A and $B. I want the package Foo::Bar that uses Foo::Prototype as a base to import the global variable $A and $B. I could not figure how to do that. I understand that using global variables is not a good practice in general, but in this case I want to use them. The code looks...

Interprocess Mutex In Perl

I have a Perl CGI program that executes under mod_perl. Within the program, I would like to prevent a resource from accessing by multiple processes at the same time. # Semaphore Initialization Code # 10023 is unique id, and this id will be same across different apache process. # 1, Only one semaphore being created. # 0722, as all proces...

Replace multiple instances in a string in perl

I have the following use case, input present in the file as: Line1 : AA BB CC DD EE I want to replace this with 1 2 3 4 5 Output Line1: 1 2 3 4 5 In one regular expression in Perl, can I do this I was trying this but was unsucessful my @arr1 = ("AA", "BB", "CC", "DD", "EE"); open F2, $file; my $count = 0; while (<F2>) { ...

How do I produce XML with Perl's XML::Simple?

I am just trying to create the XML use XML::Simple; my %element = ( "a" => "10" , "b" => "20" ,); my $xs = new XML::Simple(); my $ref = $xs->XMLin(%element); my $xml = $xs->XMLout($ref); print $xml; What is wrong on this code ? ( This is got Resolved ) use XML::Simple; my %element = ( "a" => "10" , ...

How can I validate enum types as Perl subroutine arguments?

Building off Does Perl have an enumeration type?, how can I perform dynamic type checking (or static type checking if use strict is able to do so) that my subroutine argument is getting the right type of enum? package Phone::Type; use constant { HOME => 'Home', WORK => 'Work', }; package main; sub fun { my ($my_phone_type...

How can I include the output of a Perl script into a PHP page?

We've been asked to support some rather old Perl forms on a new site, as we're using a PHP based CMS we need to include the Perl scripts into our new CMS. I've tried a bit of shell_exec but that's disabled. Has anyone got any ideas? ...

How can I fix test failures of Perl module HTML::TreeBuilderX::ASP_NET?

I'm trying to install the HTML::TreeBuilderX::ASP_NET mentioned Perl module on my box with CPAN.pm, but the "make test" part of the installation fails so the module doesn't get installed. Distribution: HTML-TreeBuilderX-ASP_NET-0.08 Perl: "This is perl, v5.10.0 built for i486-linux-gnu-thread-multi" OS: Linux 2.6.28-13-server #44-Ubunt...

Is it kosher to assign to $! in Perl?

Is it OK to assign to $! on an error in Perl? E.g., if( ! (-e $inputfile)) { $! = "Input file $inputfile appears to be non-existent\n"; return undef; } This way I can handle all errors at the top-level. Thanks. ...

Is it possible to parse this nightmare using Perl?

I'm working on some doc file, that when copied and pasted into a text file, gives me the following sample 'output': ARTA215 ADVANCED LIFE DRAWING (3 Cr) (2:2) + Studio 1 hr. This advanced study in drawing with the life .... Prerequisite: ARTA150 Lab Fee Required ARTA220 CERAMICS II (3 Cr) (2:2) + Studio 1 hr. This course afford...

How can I list all of the files in a directory with Perl?

Is there a function in Perl that lists all the files and directories in a directory? I remember that Java has the File.list() to do this? Is there a comparable method in Perl? ...

In XS, how do I get a variables address from its name?

In XS, how do I turn a string that holds a variable name into its address, I want to do something like the following perl code: our $var = 1; print ${$main::{var}}; ...

What is the difference betweeen %INC and @INC?

What is the difference between %INC and @INC in Perl? ...