perl

Where is the documentation for $# ?

I can't seem to find explicit documentation for $# in perldoc. Yes, I know what it is, and I can see implicit references in places like perllol and perldsc, but I can't seem to find anything standalone. What's really surprising is that it doesn't have it's own section in perlvar. Does such documentation exist? If so, where? ...

How can I cast UDP streams in Perl?

My Perl script gets a UDP response that is built out of 2 integers + float numbers. The problem is that the UDP stream is one long stream of bytes. How do I cast the stream into parameters using Perl? ...

UTF-8 - Oracle issue

Possible Duplicate: DBD::Oracle and utf8 issue I set my NLS_LANG variable as 'AMERICAN_AMERICA.AL32UTF8' in the perl file that connects to oracle and tries to insert the data. However when I insert a record with one value having this 'ñ' character the sql fails. But if I use 'Ñ' it inserts just fine. What am I doing wrong he...

How to convert a z score to a percentage in Perl

Seems like in Perl this should be easy or a module, but I have not found an easy answer yet. I have a calculated z normal score and the mean, but have not found an easy method to calculate the percentage. The solutions I have found are for looking it up using a statistics table, but it seems like something that common would have a modul...

gcc compile error when installing Data::Alias package from CPAN (Strawberry Perl)

Possible Duplicate: How can I get a working Data::Alias in Perl 5.12? I'm trying to install the Data::Alias package from CPAN and I'm getting compile errors from gcc. I'm on Windows Server 2008: Writing Makefile for Data::Alias cp lib/Data/Alias.pm blib\lib\Data\Alias.pm C:\strawberry\perl\bin\perl.exe "-Iinc" C:\strawberry\...

How do I compose an existing Moose role into a class at runtime?

Say I define an abstract My::Object and concrete role implementations My::Object::TypeA and My::Object::TypeB. For maintainability reasons, I'd like to not have a hardcoded table that looks at the object type and applies roles. As a DWIMmy example, I'm looking for something along these lines in My::Object: has => 'id' (isa => 'Str', req...

wget not behaving via IPC::Open3 vs bash

I'm trying to stream a file from a remote website to a local command and am running into some problems when trying to detect errors. The code looks something like this: use IPC::Open3; my @cmd = ('wget','-O','-','http://10.10.1.72/index.php');#any website will do here my ($wget_pid,$wget_in,$wget_out,$wget_err); if (!($wget_pid = o...

How can I retain insertion order of a nested Perl hash?

I can use IxHash to remember the insertion order of a hash. use Tie::IxHash; my %hash; tie(%hash, 'Tie::IxHash'); %hash = ( x => 10, z => 20, q => { a1 => 1, a3 => 5, a2=>2,}, y => 30, ); printf("keys %s\n", join(" ", keys %hash)); => keys x z q y How about the nested hash? printf("keys %s\n", join(" ", keys %{$hash{q}}));...

In what circumstances are instance variables declared as '_var' in 'use fields' private?

I'm trying to understand the behavior of the fields pragma, which I find poorly documented, regarding fields prefixed with underscores. This is what the documentation has to say about it: Field names that start with an underscore character are made private to the class and are not visible to subclasses. Inherited fields can be overri...

How can I allow undefined options when parsing args with Getopt

If I have a command line like: my_script.pl -foo -WHATEVER My script knows about --foo, and I want Getopt to set variable $opt_foo, but I don't know anything about -WHATEVER. How can I tell Getopt to parse out the options that I've told it about, and then get the rest of the arguments in a string variable or a list. An example: use...

AJAX: how to get progress feedback in web apps, and to avoid timeouts on long requests?

This is a general design question about how to make a web application that will receive a large amount of uploaded data, process it, and return a result, all without the dreaded spinning beach-ball for 5 minutes or a possible HTTP timeout. Here's the requirements: make a web form where you can upload a CSV file containing a list of UR...

How can I debug a Perl program that suddenly exits?

I have Perl program based on IO::Async, and it sometimes just exits after a few hours/days without printing any error message whatsoever. There's nothing in dmesg or /var/log either. STDOUT/STDERR are both autoflush(1) so data shouldn't be lost in buffers. It doesn't actually exit from IO::Async::Loop->loop_forever - print I put there ju...

Difference between '>>' and '>' in Perl

What is the difference between these two code snippets? open (MYFILE, '>>data.txt'); open (MYFILE, '>data.txt'); ...

Socket programming in perl, problem with perlio layer?

I'm noticing some problems with the perlio layer in perl. Took me a good day to track it down and was hoping some other people knew something about this? The scariest thing about this is that since its so low-level, I'm worried it'll reduce the code's portability. Server code: use strict; use Socket; socket(my $sock, AF_INET, SOCK_S...

Changing window focus on OS X

As part of an InstallationCheck script on OS X I need to use finder dialogs to let the user browse for files. When I'm done I want to move the installer application up front again so that the user can easily continue with the installation. I have already tried the simple: tell application "Installer" to activate This does not work be...

Why does HTML::TreeBuilder show mojibake/weird characters in the output?

I am having a problem with HTML::TreeBuilder; it shows mojibake/weird characters in the output. Please help me. Thanks in advance. use strict; use WWW::Curl::Easy; use HTML::TreeBuilder; my $cookie_file ='/tmp/pcook'; my $curl = new WWW::Curl::Easy; my $response_body; my $charset = 'utf-8'; $DocOffline::charset = undef; $curl->setopt (C...

Which tool should I use for finding out my memory allocation in Perl?

I've slurped in a big file using File::Slurp but given the size of the file I can see that I must have it in memory twice or perhaps it's getting inflated by being turned into 16 bit unicode. How can I best diagnose that sort of a problem in Perl? The file I pulled in is 800mb in size and my perl process that's analysing that data has ...

Script to fix broken lines in a .txt file?

I'd love like to read books properly on my Kindle. To achieve my dream, I need a script to fix broken lines in a txt file. For example, if the txt file has this line: He watched Kahlan as she walked with her shoulders slumped down. ... then it should fix it by deleting the newline before the word "down": He watched Kahlan as she wa...

ldapsearch and vcard creation

I'm using openldap on Mac OS X Server 10.6 and need to generate a vcard for all the users in a given group. By using the ldapsearch I can list all the memberUid's for all users in that group. I found a perl script (Advanced LDAP Search or ALS) that was written by someone that will generate the vcard easily. ALS can be found here http://w...

How does the #! work?

In a script you must include a #! on the first line followed by the path to the program that will execute the script (e.g.: sh, perl). As far as I know though, the # character denotes the start of a comment and that line is supposed to be ignored by the program executing the script. It would seem though, that this first line is at some p...