perl

How can I sort a hash of hashes by key in Perl?

I want to sort a hash which actually has a hash as a value. For instance: my %hash1=( field1=>"", field2=>"", count=>0, ); my %hash2; $hash2{"asd"}={%hash1}; and I inserted lots of hashes to %hash2 with different count values of %hash2. How can I sort the %hash1 according to a count value of hash1? Is there a way of doing ...

Is Perl or C faster at parsing?

I have a few very large log files, and I need to parse them. Ease of implementation obviously points me to Perl and regex combo (in which I am a still novice). But what about speed? Will it be faster to implement it in C? Each log file is in the order of 2 GB. ...

Best practice in designing a web app user activities logging?

We have a web e-learning type system, and for this project, I am supposed to design an activities logging feature for the whole system so we can track down their daily activities and perhaps help them to be more productive. Unfortunately this system most likely will be used to track the user's work during the official hours ( And the d...

How do I get text orientation of a text string in a PDF page using CAM::PDF?

I am using CAM::PDF and I want to find out how to get the orientation of a text string. Thanks ...

Is space supposed to be ignored between a sigil and its variable name?

I just discovered that perl ignores space between the sigil and its variable name and was wondering if someone could tell me if this was the expected behaviour. I've never run into this before and it can result in strange behaviour inside of strings. For example, in the following code, $bar will end up with the value 'foo': my $foo = '...

How to find list of possible words from a letter matrix [Boggle Solver]

Lately I have been playing a game on my iPhone called Scramble. Some of you may know this game as Boggle. Essentially, when the game starts you get a matrix of letters like so: F X I E A M L O E W B X A S T U The goal of the game is to find as many words as you can that can be formed by chaining letters together. You can start with an...

Is there a way to output debug messages in Perl that are not piped?

Is there a way to output debug messages in Perl that are not piped? I have a Perl script that I use in a pipe but I really want to print some diagnostic information to the screen instead of to the pipe. ...

How do you manage configuration files in Perl?

I have a program that has to read a configuration file from a PHP script, and a quick search has revealed there are dozens of ways to handle configuration files in Perl: Config data in a separate file AppConfig Config::General Config::IniFiles Config::Scoped Config::Simple ConfigReader::Simple And many others Brian provides an overvi...

How can I list all variables that are in a given scope?

I know I can list all of the package and lexcial variables in a given scope using Padwalker's peek_our and peek_my, but how can I get the names and values of all of the global variables like $" and $/? #!/usr/bin/perl use strict; use warnings; use PadWalker qw/peek_our peek_my/; use Data::Dumper; our $foo = 1; our $bar = 2; { my...

How do I get a list of custom fields in JIRA with Perl SOAP?

I was curious if anyone else had an idea how to get a list of all of the custom fields you have created in JIRA? If so, how did you do it? I've been trying to use a Perl SOAP routine I found on JIRA SOAP service documentation, but I have no idea how to implement it. ...

How do I sanitize user input for proper content-encoding before I save it?

I've got an application where users input text into forms. The data is saved into a MySQL database (collation: utf8_general_ci) and then output as XML (encoding: UTF-8). The problem is that people tend to cut and paste their information from other sources, for instance, Microsoft Word documents or PDFs for instance. This input text of...

How can I use Perl libraries from Python?

Dear All, I have written a bunch of Perl libraries (actually Perl classes) and I want to use some of them in my Python application. Is there a natural way to do this without using SWIG or writing Perl API for Python. I am asking for a similar way of PHP's Perl interface. If there is no such kind of work for Perl in Python. What is the e...

How do I gather output from an external command in a Perl script?

Hi, I have a a tool named TET.EXE, product of the PDFlib family, it is used to extract the co-ordinates of a particular text. Using those coordinates in the Perl script we can extract the required text. This is a manual process to run the .EXE and then give the co-ordinates to Perl, so could any one suggest me to make this entire proces...

How do I count the number of rows in a large CSV file with Perl?

I have to use Perl on a Windows environment at work, and I need to be able to find out the number of rows that a large csv file contains (about 1.4Gb). Any idea how to do this with minimum waste of resources? Thanks PS This must be done within the Perl script and we're not allowed to install any new modules onto the system. ...

Why do I have to use LD_PRELOAD for libcl.2 to use XML::LibXML::Common on HP/UX?

A compulsion of LD_PRELOAD on HP platform only and not on other unix flavors (AIX,Linux, and Solaris). I built Perl Module XML::LibXML::Common on all of Unix flavors.I had to specifically do LD_PRELOAD for libcl.2 library on HP Platform only. While on other unix platforms nothing as such was required. Is this an OS behaviour or somethi...

How do I set the timezone for Perl's localtime()?

In Perl, I'd like to look up the localtime in a specific timezone. I had been using this technique: $ENV{TZ} = 'America/Los_Angeles'; my $now = scalar localtime; print "It is now $now\n"; # WORKS: prints the current time in LA However, this is not reliable -- notably, if I prepend another localtime() call before setting $ENV{TZ}, it b...

Why can't my Perl script load a module when run by cron?

I have a bunch of Perl scripts that all run fine, yet need to have use Plibdata; up top. I set up a cron job that runs (I get the confirmation email from root) and it spits back the following error message: Can't locate Plibdata.pm in @INC (@INC contains: /install/lib /opt/perl58/lib/5.8.8/IA64.ARCHREV_0-thread-multi /opt/perl58/lib/5....

How do I handle every ASCII character (including regex special characters) in a Perl regex?

I have the following code in Perl: if (index ($retval, $_[2]) != -1) { @fs = split ($_[2], $_[1]); $_[2] is the delimiter variable and $_[1] is the string that the delimiter may exist in. ($_[0] is used elsewhere) You may have guessed that this code is in a subroutine by those variable names. Anyway, onto my question, when my del...

How can I use paste and awk inside Perl?

I have the following code that uses 'paste' and AWK script inside Perl. use strict; use Data::Dumper; use Carp; use File::Basename; my @files = glob("result/*-*.txt"); my $tocheck = $ARGV[0] || "M"; foreach my $file ( @files ) { my $base = basename($file,".txt"); my @res = `paste <\(awk '\$4 == "M...

Perl Myths

I keep seeing people trip over common misconceptions of how Perl exists and what it does. There are generally 2 types of Perl Myth. Type 1: Things that people think about the language itself, that are not true Type 2: Behaviors people exhibit when using the language, which generally derive from lack of common sense. The first on...