perl

Cleaner way to store to replace a scalar hash value with an array ref?

I am building a hash where the keys, associated with scalars, are not necessarily unique. The desired behavior to be that if the key is unique, the value is the scalar. If the key is not unique, I want the value to be an array reference of the scalars associated witht the key. Since the hash is built up iteratively, I don't know if the...

Inheritance Problem in Perl OOP

Hello, I have a sub class that calls a method from a super class. and the method in the super class use a method that is defined in the super class as asbstract(not really abstract) but implemented in the sub class. for example: package BaseClass; sub new { } sub method1 { return someAbstractMethod(); } sub someAbtsractMetho...

How can I determine if an object or reference has a valid string coercion?

I've run into a situation (while logging various data changes) where I need to determine if a reference has a valid string coercion (e.g. can properly be printed into a log or stored in a database). There isn't anything in Scalar::Util to do this, so I have cobbled together something using other methods in that library: use strict; use...

Error: Cannot parse function definition from ' hello()' in Mytest.xs, line 9

Hi I am trying to use perl XS in RHEL 5. but simple programm is giving error.I followed same code as in Example 1 in perldoc perlxstut Can anyone help me in correcting the following error? [root@localhost Mytest]# [root@localhost Mytest]# pwd /home/nikole/perlcode/Mytest [root@localhost Mytest]# ls blib lib MANIFEST Myt...

importing 2 modules with use

I have 2 perl modules every module use the second one i.e Module1.pm use Module2 Module2.pm use Module1 what happen on the background when I load those 2 modules with use use Module1; use Module2; could someone explain what happen on the background and why I not enter infinate loop ? ...

What can I do using awk that I cannot do in Perl?

I had read somewhere about one specific feature that is present in awk but not in Perl. I have failed in locating it again. I would appreciate it if anyone here can point it out. This might be a useless trivia, but I am still curious to know. ...

WSDL Perl handlers in Apache broken unless "touch"ed

The Short Version I have a mod_perl handler in Apache that uses generated code (from wsdl2perl) to make SOAP calls to a web service. One of the methods from the WSDL is failing to create valid SOAP XML unless I "touch" the generated perl module after Apache has been started. Other methods from the WSDL are fine. A standalone perl script ...

How can I write a Template.pm filter to generate PNG output from LaTeX source code?

I am looking for a way of generating PNG images of equations from LATEX source code embedded in templates. For example, given: [% FILTER latex_display ] \begin{eqnarray*} \max && U(x,y) \\ \mathrm{s.t.} && p_x x + p_y y \leq I \\ && x \geq 0, y \geq 0 \end{eqnarray*} [% END %] I would like to get the output: <div class="latex display...

How can one prevent double encoding of html entities when they are allowed in the input

How can I prevent double encoding of html entities, or fix them programmatically? I am using the encode() function from the HTML::Entities perl module to encode HTML entities in user input. The problem here is that we also allow users to input HTML entities directly and these entities end up being double encoded. For example, a user ma...

Spreadsheet::WriteExcel Memory Usage

Hi; I'm trying to create a multi-sheet excel document, and thus far I'd been doing it in PHP - but using PHPExcel was eating up 70MB of RAM for about 60,000 spreadsheet cells total. I'm wondering if anyone has experience with Spreadsheet::WriteExcel and if it has problems with creating very large documents. I'd just give it a shot bu...

How to shift PDF page using perl (CAM::PDF, PDF::API2)?

Hi all, I have a PDF document which I need to shift the pages to the right several inches. I.e like putting a margin on the left hand side of the page. Can either CAM::PDF or PDF::API2 do it? Or is there anyone have experience with it? Thanks. ...

binary sed replacement

I was attempting to do a sed replacement in a binary file however I am beginning to believe that is not possible. Essentially what I wanted to do was similar to the following: sed -bi "s/\(\xFF\xD8[[:xdigit:]]\{1,\}\xFF\xD9\)/\1/" file.jpg The logic I wish to achieve is: scan through a binary file until the hex code FFD8, continue re...

How do you use scripting language (PHP, Python, etc) to improve your productivity?

Hi, I'm a Delphi developer on the Windows platform, recently read the PHP tutorial at W3CSchools, it looks interesting. We all know scripting languages are very good at web site development, but I also want to utilize it to improve my productivity or get some tedious tasks done quickly, maybe some quick-and-dirty string/file processin...

how to find perl has installed in a system

I have written a perl script , I just want to give it to every one , for that I planned to write a bash script which is used to test the environment of a user and find whether that environment is capable of running the perl script. I want to test the things like Whether perl has installed in that system Perl should have the vers...

List CPAN modules that have been made but not installed

Is there an easy/clean way to do this in Linux/ a Linux-like environment? Purpose My aim is to run CPAN with admin permissions only during the installation phase, not at the get/make/test phases. ...

awk or perl file editing & manipulation

I have a standard passwd file & a usermap file - which maps unix name (eg jbloggs) with AD account name (eg bloggsjoe) in the format: jbloggs bloggsjoe jsmith smithjohn ... etc. How can I edit the passwd file to swap the original unix name with the AD account name so each line of the passwd file has the AD account name instead. A...

Perl version of php's memory_get_peak_usage

Is there something in perl similar to PHP's memory_get_peak_usage? For example, in PHP I can stick in the line: echo "Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB\r\n"; and it does pretty much what it says. I need a way to get the same sort of information in a perl script. I should note that this for a C...

Encrypting with Perl CBC and decrypting with PHP mcrypt

I have an encrypted string that was encrypted with Perl Crypt::CBC (Rijndael,cbc). The original plaintext was encrypted with encrypt_hex() method of Crypt::CBC. $encrypted_string = '52616e646f6d49567b2c89810ceddbe8d182c23ba5f6562a418e318b803a370ea25a6a8cbfe82bc6362f790821dce8441a790a7d25d3d9ea29f86e6685d0796d'; I have the 32 character...

Fork in Perl not working inside a while loop reading from file

Hi, I'm running a while loop reading each line in a file, and then fork processes with the data of the line to a child. After N lines I want to wait for the child processes to end and continue with the next N lines, etc. It looks something like this: while ($w=<INP>) { # ignore file header if ($w=~m/^\D/) { next;}...

DBD::Oracle and utf8

Hello, I have some troubles inserting an UTF8 string into an oracle 10 database on Solaris, using the latest DBD::Oracle on perl v5.8.4. This are my DB settings > --------SELECT * from NLS_DATABASE_PARAMETERS------------------------------- > NLS_NCHAR_CHARACTERSET AL16UTF16 > NLS_LANGUAGE AMERICAN > NLS_TERRITORY AMERICA NLS_CURRENCY $...