perl

Searching one file but displaying relevant content from another using Perl

Here's the situation: I've got two versions of a novel, both in txt format. One is in the original language and the other in Chinese or English translation.When reading the original version, it sometimes happens I want to take a quick look at the translated version of a particular sentence. What I expect is: a corresponding sentence fro...

How can I split a file into a given number of parts in Perl? (On Unix)

I have several large files, each of which I want to chunk/split it in to predefined number of parts. Is there an efficient way to do it in Unix (e.g. via awk/sed/perl)? Also each file can have varied number of lines. File1.txt 20,300,055 lines File2.txt 10,033,221 lines etc... ...

Making a Perl script detect changes in a separate config module also in Perl.

G'day, We have a Perl script that is processing geolocation requests from the head-end servers in a major web site. The script is a broker providing additional business logic interpreting the data returned by a COTS product that provides data for a given IP address, e.g. country, connection type, routing type, carrier, etc. This Geo se...

Perl - Ruby mapping?

I got involved in a new project where Perl is a must. I'm coming from a good Ruby foundation and want a quick introduction or mapping between Perl and Ruby as I heard that Perl and Ruby are very close in syntax (know nothing about features). Do you have any recommendations for me? What great Perl book do you recommend as an extended ...

Why is the 'Use of "shift" without parentheses is ambiguous' warning issued by Perl?

Does anyone know what parsing or precedence decisions resulted in the warning 'Use of "shift" without parentheses is ambiguous' being issued for code like: shift . 'some string'; # and not (shift) . 'some string'; # or shift() . 'some string'; Is this intentional to make certain syntactic constructs easier? Or is it merely an artif...

How can I send arrow key presses to a process using Expect.pm

Hi all: Seems like this should be obvious, but how do I send arrow key presses to a process using Expect.pm? Does it depend on the terminal type I am using (vt100) or do I send keyboard scancodes? TIA. ...

Can I get the table names from an SQL query with Perl's DBI?

I am writing small snippets in Perl and DBI (SQLite yay!) I would like to log some specific queries to text files having the same filename as that of the table name(s) on which the query is run. Here is the code I use to dump results to a text file : sub dumpResultsToFile { my ( $query ) = @_; # Prepare and execute the query ...

Why does Perl warn me about using pseudo-hashes?

Perl is warning me about using pseudo hashs in my program: Pseudo-hashes are deprecated How do I convert the following code so that is does not use pseudo hashs foreach my $hash (@arrayOfHash) { print keys %{$hash}; } ...

Can you take a reference of a builtin function in Perl?

What syntax, if any, is able to take a reference of a builtin like shift? $shift_ref = $your_magic_syntax_here; The same way you could to a user defined sub: sub test { ... } $test_ref = \&test; I've tried the following, which all don't work: \&shift \&CORE::shift \&{'shift'} \&{'CORE::shift'} Your answer can include XS if need...

Is there a C equivalent for Perl's Carp module?

In some projects I've done in C, I've liked using the following macros which work similar to Perl's warn and die subroutines: #include <stdio.h> #include <stdlib.h> #define warn(...) \ fprintf(stderr, __VA_ARGS__); \ fprintf(stderr, " at %s line %d\n", __FILE__, __LINE__) #define die(...) \ warn(__VA_ARGS__); \ exit(0x...

How can I build a 2D matrix from standard input in Perl?

Okay, I've been struggling with this all weekend, and I've gotten plenty of help but I'm still not getting it. Here is my code so far: what I want to do is build a few matrices from user input. Eventually I want to multiply them. Another story. input is as follows 1 2 2 4 4 5 6 6 1 2 2 3 1 2 2 3 sub makeMatrix { my ($input) = @...

How can I create a new user in all my single-sign-on sites when they register on any of them?

I have an existing website written is Perl and have recently added a WordPress blog and BBPress forums. Each of the three systems has its own login mechanism. To make this a little cleaner I have integrated WordPress and BBPress to enable single sign-on between the two systems which works great. I now want to take the next step and int...

Why does SQLite complain about the syntax of my prepared statement?

I'm having trouble getting a prepared statement in sqlite3 to work. I'm working with Perl and the Perl DBD framework. Below is the code I use: #This is a function I have defined sub query($@){ my $st = $db->prepare(shift); $st->execute(@_); } #And it is used like so query("UPDATE rooms SET name = ?, SET capacity = ? WHERE id = ...

How can I identify unfilled ovals in a PDF document using CAM::PDF?

I need to identify unfilled ovals in a PDF file. After that, I should fill them with color and I need coordinates of ovals with page numbers. Can anybody help me how to solve this using CAM::PDF? ...

How can I speed up Perl's processing of fixed-width data?

We've got a mature body of code that loads data from files into a database. There are several file formats; they are all fixed-width fields. Part of the code uses the Perl unpack() function to read fields from the input data into package variables. Business logic is then able to refer to these fields in a 'human-readable' way. The file...

Why does this map return a single number?

Hello! I am trying to cut down on the number of code lines I am using but am ending up with a fairly simple problem (although it's stumping me since I am just starting to wrap my head around references) I am trying to concatenate several values in a particular order.. My code looks like this.. my $separator = ":"; my @vals = qw(name la...

Where can I get a Xerces-C compatible with XML::XERCES 2.7.0?

This question is in continuation of this post, I have tried installing Xerces-C but the thing is Xerces-C version is 2.8.0 and 3.0.0 and XML::XERCES latest version is 2.7.0 and so am getting following error message: Update2: Here is the error which am getting, it says there is somekind of version mismatch. Using XERCES_LIB = /home/ad...

What does it mean when someone says that Perl is an "expressive language"?

What is an expressive language? What does it mean when someone says that Perl is an expressive language? ...

What would be your choice of Perl XML Parsers for files greater than 15 GB?

I know there are some very good Perl XML parsers like XML::Xerces, XML::Parser::Expat, XML::Simple, XML::RapidXML, XML::LibXML, XML::Liberal, etc. Which XML parser would you select for parsing large files and on what parameter would you decide one over another? If the one you would like to select is not in list then please suggest it. ...

What Perl glob expression matches all the files that look like /home/test-N.txt?

I am a beginner to Perl syntax and have a basic wildcard question. I am looking for an expression that would allow me to retrieve all of the following files. /home/test-1.txt /home/test-2.txt /home/test-3.txt I am just interested in the actual wildcard expression, not the file I/O. ...