perl

How do you specify a package version in Perl?

I'm a bit confused by conflicting advice between pre-5.10.0 documents and the more recent version module. Perl Best Practices makes it pretty clear that version strings ('v1.0.3') are bad and one is supposed to specify a version as follows: use version; our $VERSION = qv('1.0.3'); but the version module says that we're back to using ...

How do I replace multiple words, each hashed to an alternate word, in a HTML attribute using Perl regex?

I'm writing an HTML obfuscator, and I have a hash correlating user-friendly names (of ids and classes) to obfuscated names (like a,b,c,etc). I'm having trouble coming up with a regexp for accomplishing replacing something like <div class="left tall"> with <div class="a b"> If tags could only accept one class, the regexp would simpl...

What's the smallest non-zero, positive floating-point number in Perl?

I have a program in Perl that works with probabilities that can occasionally be very small. Because of rounding error, sometimes one of the probabilities comes out to be zero. I'd like to do a check for the following: use constant TINY_FLOAT => 1e-200; my $prob = calculate_prob(); if ( $prob == 0 ) { $prob = TINY_FLOAT; } This wor...

Why is first value of captured expression getting stored in fourth element in Perl?

I am storing information captured by regex into an array. But for some reason the first value is getting stored at 4 element of array. Any suggestion on whats going wrong and how to store the first value in the first element of array. The following is the script: #!/usr/bin/perl use strict; my @value; my $find= qr/^\s+([0-9]+)\s+([A-Z...

Why can't I get Twitter write access working with Net::Twitter::OAuth?

I registered an application with Twitter. I use Net::Twitter::OAuth to manage the interaction with Twitter. I managed to redirect the user to allow him to install the application in his Twitter account. The application is installed with read & write access. I have read access, but I didn't manage to send any tweet in his behalf: Twitter...

Why doesn't my Perl CGI script work?

I really do not get how to run a Perl file. I have uploaded my .pl to the cgi-bin then chmod to 755. Then when i go to run the file i just get a 500 internal server error. **/cgi-bin/helloworld.pl** #!/usr/bin/perl print 'hello world'; Any ideas as to what I am doing wrong? ...

How to capture and compare subset of value from different arrays?

I have 10 arrays, each consisting of similar type of values. I want to capture subset of these values (capture only the digits) from each array and then compare it with subset from other array. And also, I want to capture the number part of values from both arrays only when there is no dash in the value (i.e. 2EF = capture '2'but if 45F-...

Parse XML iLO response file with Perl

I have the folowing XML file generated by my iLO HP server, Do you have any examples of how can i parse it ? See the example XML file below. I would like to extract fan speeds and temperatures from it. <?xml version="1.0"?> <GET_EMBEDDED_HEALTH_DATA> <FANS> <FAN> <LABEL VALUE = "Fan 1"/> <ZONE VALUE = "System"/> <ST...

Unpack a binary file to a text file - A problem that flips the values

Hello friends, How can I unpack a 4byte binary file, store like the following example, to array or TEXT file ? input file: 00000000 00 00 00 00 00 00 00 01 00 00 00 01 00 00 00 00 |................| 00000001 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 01 |................| desired output file: 0,1,1,0,1,1,1,1 For now I'm u...

Perl Print buffering flush

Hi, I have the following Perl code: STDOUT->autoflush(1); foreach(...) { ... foreach(...) { print("Processing $folder"); $|=1; process($folder); } ... } but the print statement works only in the first iteration of the loop and does not print anything after that. Any idea why? EDIT: I fou...

How can I force unload a Perl module?

Hi I am using a perl script written by another person who is no longer in the company. If I run the script as a stand alone, then the output are as expected. But when I call the script from another code repeatedly, the output is wrong except for the first time. I suspect some variables are not initialised properly. When it is called st...

How do I make a time counter as child process that works in parallel to program?

Hello friends, How can I make a live time counter that ticks on the screen in parallel to part of a working program? let's say I have the following little sub code which run an internal program for a couple of minutes: system (`compile command`); exec "simu -sh"; While waiting it to end, can I open a fork or something that output to...

How can I cleanly handle error checking in Perl?

I have a Perl routine that manages error checking. There are about 10 different checks and some are nested, based on prior success. These are typically not exceptional cases where I would need to croak/die. Also, once an error occurs, there's no point in running through the rest of the checks. However, I can't seem to think of a neat w...

Parser error using Perl XML::DOM module, "reference to invalid character number"

I am a complete Perl newb, but I am certain that learning Perl will be easier than figuring out how to parse XML in awk. I would like to parse the .sgm files from this dataset: http://kdd.ics.uci.edu/databases/reuters21578/reuters21578.html This is a collection of 20,000 Reuters articles from newswire from a decade ago, and is a stand...

Perl qr// and substitution.

Hi guys. I'm writing a tiny program that takes user input using Getops, and based on it, the program will either try to match a pattern against some text, or substitute text for what matched. The problem I'm having is that I can't get the substitution portion to work. I'm looking at the qr// entry in the man pages: http://perldoc.perl....

Need to make multiple files from a single excel file

I have a excel file. With many columns . I need to make multiple files using this Eg: 0 0 0 0 0 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2. So these are the excel columns with each having many rows. I need one file which would contain 0 0 0 0 0 1 1 1 1 1 2 then second will contain only the second no 0 0 0 0 0 1 1 1 1 1 2....similarly the ot...

How should I access instance data in a Perl subclass?

Hi guys, I am extending a module and I want some tips on good practices. Specially namespace conflicts: what exactly are they and how to avoid them. When extending, should I not access variables in the SUPER class and only alter its state through accessors or object methods? What to do in case there are no (or limited) accessors? Am I ...

How can I map numbers to their string equivalents in Perl?

I am writing a script using DBI to execute a select query to an Oracle db. I have successfully able to capture the data but I need help to change the output. Below is the sample output. Type 2 6 I want to display 2=>Good and 6=>Bad Can anyone please suggest me the Perl code to map the output? ...

How can I execute a Perl script using the Ant exec task?

I currently have this in my Ant build script: <exec dir="${basedir}" executable="perl"> <arg line="${basedir}/version.pl -major"/> </exec> However, when that runs, I get this error message: [exec] Could not open -major [exec] Result: 2 To me, that says that what I have is trying to run a file called -major, which doesn't ...

In Perl, why do I get a syntax error when I try to use string eval?

Why isn't this working? eval "$response = $ua->request($r);" print "$@"; gives: syntax error at (eval 8) line 1, near "=" ...