perl

How do I do vertical alignment of lines of text in Perl?

Suppose two lines of text correspond to each other word by word except for the punctuation marks. How do I make vertical alignment of them? For example: $line1 = "I am English in fact"; $line2 = "Je suis anglais , en fait"; I want the output to be like this: I am English in fact Je suis anglais , en fait ....

Perl: replace pattern from the current position until the end of a line

In Perl, how can I replace a pattern from the current position (the position of the last replacement) until the end of a line? I have done all of these replacements in a single line: ... s/\[//; s/(\/\w\w\w\/)/ getMonth $1 /e; s/:/ /; s/\s\+\d\d\d\d\]//; #NOW: replace all blanks with a plus sign from this position until the end of this...

How do I create valid IP ranges given an IP address and Subnet mask in Perl?

How do I create valid IP ranges given an IP address and Subnet mask in Perl? I understand the concept of generating the IP ranges but need help writing in Perl. For example, if I AND the IP address and subnet mask I get the subnet number. Adding 1 to this number should give me the first valid IP. If I invert the subnet mask and OR with t...

Why does Regexp::Assemble fail with these simple regexps?

I use Regexp::Assemble in my project, but I don't understand why this little sample doesn't work: #!/usr/bin/perl use strict; use warnings; use Regexp::Assemble; my $re1 = "(run (?:pre|post)flight script for .+)"; my $re2 = "((?:Configu|Prepa)ring volume .+)"; my $ra = Regexp::Assemble->new; $ra->add($re1); $ra->add($re2); my $glo...

How can I make PDF tables from Perl?

Are there any perl modules to draw a table in a pdf at specified position with given rows and columns with an empty content in each cell? ...

How can add values in each row and column and print at the end in Perl?

Below is the sample csv file date,type1,type2,..... 2009-07-01,n1,n2,..... 2009-07-02,n21,n22,.... and so on... I want to add the values in each row and each column and print at the end and bottom of each line. i.e. date,type1,type2 2009-07-01,n1,n2,.....row_total1 2009-07-02,n21,n22,....row_total2 Total,col_total1,col_total1,......t...

With a utf8-encoded Perl script, can it open a filename encoded as GB2312?

I'm not talking about reading in the file content in utf-8 or non-utf-8 encoding and stuff. It's about file names. Usually I save my Perl script in the system default encoding, "GB2312" in my case and I won't have any file open problems. But for processing purposes, I'm now having some Perl script files saved in utf-8 encoding. The probl...

What is the proper syntax for storing an array into a Perl hash?

I'm creating a new object like this: TestObject->new(@array1, @array2) My new method looks like this: sub new { my $class = shift; my $self = {}; my $self->{Array1} = shift; my $self->{Array2} = shift; bless($self, $class); return $self; } As a simple test to access the data, I'm trying this, and then once I get it w...

Using Unix Tools to Extract String Values

I wrote a small Perl script to extract all the values from a JSON formatted string for a given key name (shown below). So, if I set a command line switch for the Perl script to id, then it would return 1,2, and stringVal from the JSON example below. This script does the job, but I want to see how others would solve this same problem usi...

Why is this Perl require line taking so much time?

I have a Perl script that runs via a system() command from C. On a specific site (SunOS 5.10), when that script is run, it nearly always takes 6 seconds or more. On other sites, it runs pretty much instantly (0.1s). If I run the script manually, i.e. not from the C code, it also runs instantly. I eventually tracked the slowness down (by...

What does this Perl script achieve?

I was going over a Perl script written by someone else and I am not too familiar with Perl so could someone let me know what do the first three lines do? my $ref = do($filename); $ref != 0 or die "unable to read/parse $filename\n"; @varLines=@{$ref}; foreach $ord (@varLines) { # code here } This is in the beginning of the program ...

Perl XML: SAX Parsing Error -> Attribute value not printing

I am trying to parse XML in Perl using XML::SAX parser. My query is regarding generating attributes values. Right now I am able to generate only values present inside the tag elements but my goal is to generate: Element Name: Element Value: Element Attribute Name: Element Attribute Value: Element Child Name: Element Child Value ...

How to access value outside If/else scope

I have a data that comes in pair like this: A: 100 B: 3.3 A: 210 B: 4.3 What I want to do with the code below is to sum value of each pairs: my $aval = ""; my $bval = ""; while (<DATA>) { chomp; if (/^A/) { $aval = (split(" ",$_))[-1]; } else { $bval = (split(" ",$_))[-1]; my $total = $aval ...

Use proxy with perl script

I want to use a proxy with this perl script but I'm not sure how to make it use a proxy. #!/usr/bin/perl use IO::Socket; $remote = IO::Socket::INET->new( Proto => "tcp", PeerAddr => "localhost", PeerPort => "8080", ) or die "...

Newbie transforming CSV files in Clojure

I'm both new and old to programming -- mostly I just write a lot of small Perl scripts at work. Clojure came out just when I wanted to learn Lisp, so I'm trying to learn Clojure without knowing Java either. It's tough, but it's been fun so far. I've seen several examples of similar problems to mine, but nothing that quite maps to my pro...

Removing files with duplicate content from single directory [Perl, or algorithm]

I have a folder with large number of files, some of with have exactly the same contents. I want to remove files with duplicate contents, meaning if two or more files with duplicate content found, I'd like to leave one of these files, and delete the others. Following is what I came up with, but I don't know if it works :) , didn't try it...

Compare semicolon separated data in 2 files using shell script

I have some data (separated by semicolon) with close to 240 rows in a text file temp1. temp2.txt stores 204 rows of data (separated by semicolon). I want to: Sort the data in both files by field1, i.e. the first data field in every row. Compare the data in both files and redirect the rows that are not equal in separate files. Sample...

Integration Testing for a Web App

I want to make a full integration testing for a web application. I want to test many things like AJAX, positioning and presence of certain phrases and HTML elements using several browsers. I'm seeking a tool to do such automated testing. On the other hand; this is my first time with integration testing, is there any specific recommendat...

How do I set an environment variable in Perl?

How do I set an environment variable in Perl? I want to set $HOME to a different directory than the default. ...

In Perl, how do I put multiple packages in a single .pm file?

I'm pretty sure that I read somewhere that it's possible, but there are a few gotchas that you need to be aware of. Unfortunately, I can't find the tutorial or page that described what you need to do. I looked through the Perl tutorials, and didn't find the one that I remember reading. Could someone point me to a page or document that de...