perl

How can I set the encoding on a Perl pipe?

Hello! Is "'|-:encoding(utf-8)'" in "open my $column, '|-:encoding(utf-8)', qw(column);" ok? It seems to work almost. In the row with the "Mikołaj" the formatting is not correct; how can I fix it? #!/usr/bin/perl use warnings; use strict; use utf8; binmode STDOUT, ':encoding(utf-8)'; # edit: binmode DATA, ':encoding(utf-8)'; open my $c...

When is Perl's scalar comma operator useful?

Is there any reason to use a scalar comma operator anywhere other than in a for loop? ...

How do I make my popup date picker calendar javascript change the text date next to it and update the database?

We use a DHTML calendar picker that only allows you to change the date, which is desired functionality. However, I need to figure out the javascript to change the date next to the calendar picker, as seen in the image below, and popup an "are you sure" message. The above image is one row in a table, so the JS needs to be aware of whic...

Why does my Perl script die with an "out of memory" exception?

I need to read a 200mb "space"-separated file line-by-line and collect its contents into an array. Every time I run the script, Perl throws an "out of memory" exception, but I don't understand why! Some advice please? #!/usr/bin/perl -w use strict; use warnings; open my $fh, "<", "../cnai_all.csd"; my @parse = (); while (<$fh>) { ...

How to write a function reference in a Perl module?

I'm trying to figure out how to make a function reference work for a Perl module. I know how to do it outside of a module, but inside one? Consider code like this: ==mymodule.pm== 1 sub foo { my $self = shift; ... } 2 sub bar { my $self = shift; ... } 3 sub zip { 4 my $self = shift; 5 my $ref = \&foo; 6 $self->&$foo(); # what synt...

Write an anonymous sub in Perl to a file for later use.

I have a Perl program that generates parsing rules as subs from an input file. The subs are anonymously defined an put into a hash. Now, I want to export that hash, with all the subs and then load them again later to use with a different program. How do I go about doing this? Is there some way to extract the code of each sub, or can ...

Need good resources that guide through the process of creating Perl Modules/Packages

I work as an ETL developer and I have been meaning to create a Perl module where I can put a lot of the subroutines. I would also like, if it is possible, to have the module handle all the logging & error reporting although the second one is more of a nice to have than an immediate need. I have never created a module or package in Perl...

What is Perl's $; variable for?

Does any 1 have any idea what is $; (first split function argument) in the following code snippet: local(@a) = (); local($i) = 0; for ($i = 0; $i < $d; $i++) { @a = split($;, @b[$i]); $c = @a[0]; } The scalar is not found any where in the script other than in the for loop. Any help is app...

Why does a module compile by itself but fail when used from elsewhere?

I have a Perl module that appears to compile fine by itself, but is causing other programs to fail compilation when it is included: me@host:~/code $ perl -c -Imodules modules/Rebat/Store.pm modules/Rebat/Store.pm syntax OK me@host:~/code $ perl -c -Imodules bin/rebat-report-status Attempt to reload Rebat/Store.pm aborted Compilation fai...

Should I create a Java GUI for a Perl command line program?

I have a Perl command line program, for which a GUI is required. I see that this is mostly done using GTk. However we would like to do this in Java as we would like to re-use for another desktop application. Are there any issues in following the Java approach. What would you recommend? ...

Perl iso-8859-1 string comparison

I wrote a small program to go through /usr/share/dict/words finding palindromes while(<>){ chomp; print "$_\n" if $_ eq reverse; } However, this does not work for a list of Danish words encoded in Latin-1 (ISO-8859-1). Just wondering how I'd go about making it work? ...

Perl - Save sockets in a hash and loop it from a thread

I am working on a mulithreaded TCP server. In the main thread i listen on a socket and create a new thread for new incomming connections. I want to save all incoming connections in a hash so that i can access them from yet another thread. From the "monitor" thread i can not read any newly added connections. It seems a new "clients" hash...

How can I print a datetime in the xs:dateTime format in Perl?

I would like to take a time stamp (e.g. 1263531246) and convert it to a string representation suitable for output to an XML file in an attribute field conforming to xs:dateTime. xs:dateTime expects something like: 2002-05-30T09:30:10-06:00 Ideally, I would use the form of output that includes offset from UTC (as above). In this projec...

How can I optimize multiple nested SELECTs in SQLite (w/Python)?

I'm building a CGI script that polls a SQLite database and builds a table of statistics. The source database table is described below, as is the chunk of pertinent code. Everything works (functionally), but the CGI itself is very slow as I have multiple nested SELECT COUNT(id) calls. I figure my best shot at optimization is to ask the SO...

How can I run only a specific test in a Perl distribution?

This question is related to this question I asked before. I have multiple test files (A.t, B.t, C.t etc) created to test their respective module A, B, C & so on. But when I do a make test, it runs all the tests. But, when I'm working on a specific module say B, I'd like to run unit tests for that module. After I'm done with my changes, I...

Using a PFX Certificate to connect to an HTTP site

Here's the scenario: I need to connect to a web site to retrieve electronic lab results formatted in XML. In order to connect, I need to use a digital certificate. I've been able to get a version of this working in Perl. It looks like this: #!/usr/bin/env perl use strict; use WWW::Mechanize; $|++; my $username = 'xxx'; my $password...

Question on Running mod_perl + apache + Windows

I had developed web applications under environment mod_perl + Apache + Linux. Now, I want to deploy a web application solution to my client, under Windows. I was wondering any problem you guys encounter, when running mod_perl + Apache + Windows? (1) Can I get Perl additional library (CPAN?), and being used in my web application easily...

Why doesn't my Perl DBI query return any results in a CGI script?

I'm using DBI for the first time (and not long started Perl [2 weeks]) and I can't seem to get any results from the database. Here's what I have: if( defined( $get{findAllPages} ) && defined( $post{ki} ) ){ my ($database, $hostname, $port, $password, $user ); $database = "#########"; $hostname = "localhost"; $password = "#...

How do I execute an external script while capturing both output and exit code in Perl?

I'm trying to check for an SVN tag existence from a Perl script. So I try calling svn info $url, read exit code and suppress standard output and standard error streams. However, I struggle to do this elegantly (there are probably better ways to ask SVN about a tag, but that's not the point here): my $output = `svn info $url/tags/$tag`; ...

How can I improve this commify routine for speed?

I need an efficient commify filter or routine for use with Template::Toolkit. It is to be used many times on the page. It should support decimals. This one is found in The Perl Cookbook: sub commify { my $text = reverse $_[0]; $text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g; return scalar reverse $text; } Are there more efficien...