perl

How do you sort CJK (Asian) characters in Perl, or with any other programming language?

How do you sort Chinese, Japanese and Korean (CJK) characters in Perl? As far as I can tell, sorting CJK characters by stroke count, then by radical, seems to be the way these languages are sorted. There are also some methods that sort by sounds, but this seems less common. I've tried using: perl -e 'print join(" ", sort qw(工 然 一 人 三 ...

Is there an interpreter for sending commands to Selenium?

I'm a Perl programmer doing some web application testing using Selenium. I was wondering if there's some kind of interactive interpreter which would allow me to type Selenium commands at a prompt and have them sent to selenium. The way I'm currently developing code is to type all of the commands into a Perl script, and then execute the ...

What's the best practise for Perl hashes with array values?

What is the best practise to solve this? if (... ) { push (@{$hash{'key'}}, @array ) ; } else { $hash{'key'} =""; } Is that bad practise for storing one element is array or one is just double quote in hash? ...

Why does Perl's sysopen report success but $! has an error?

My sysopen fails: sysopen(DEV, "/dev/ttyS0", O_NONBLOCK|O_RDONLY) returns 1, which is a success! Then, why does $! have the error "Illegal seek" in it (where it is undef before the call) before sysopen $!: after sysopen $!: Illegal seek EDIT: Here is the full script: (using the actual O_NONBLOCK|O_RDONLY value 2048) #!/usr/bin/pe...

How can I use Perl to test for Win32 group membership when group contains nested groups?

I'm trying to use Perl to determine if a Windows users is a member of a Windows group, if the the group contains nested groups. I've tried using Win32::NetAdmin::GroupIsMember(), but it only works if the user a direct member of the group. I'm not a AD or LDAP expert, but the examples I googled for exhibit the same behavior. For exampl...

How do I get WWW::Mechanize to properly handle 302 redirects with URI fragments?

I have a webpage which redirects to another url in the form of http://www.example.com/url.html#midpage. I'm wondering if there's anyway for WWW::Mechanize to follow http://www.example.com/url.html instead of http://www.example.com/url.html#midpage? ...

Is there a non-global equivalent of perlbrew?

I'm using perlbrew right now to manage multiple versions of perl, but perlbrew is global. If I do perlbrew switch perl-5.10.1 in any shell, then all shells and scripts will now be using perl version 5.10.1. There is no isolation. Is there any way to make perlbrew switches local to a shell, or is there a similar tool capable of locally ch...

Why doesn't rrdtool generate any PNG output in my Perl CGI program?

I'm trying to output an image from RRD Tool using Perl. I've posted the relevant part of the CGI script below: sub graph { my $rrd_path = $co->param('rrd_path'); my $RRD_DIR = "../data/"; #generate a PNG from the RRD my $png_filename = "-"; # a '-' as the filename send the PNG to stdout my $rrd = "$RRD_DIR/$rrd_path"; my $png = `rrdto...

Perl changing the current package?

Without using a source-filter, is there a way to change the current running package? I'm trying to accomplish the same thing oose.pm does, and I'm wondering if I can drop my users in a non-main package. ...

How Can I Remove Magic Number when using XML::Simple?

Hello. I did a exercise like this, how do I calculate the # of XML elements collapsed into an array by XML::Simple so I don't have to hard-code the # of elements? I plan to use the code to parse a bigger xml file. I don't want to cout the elements by manual. Can I use some count to replace the magic numbers, a little like person.count...

How can I make perltidy work with Method::Signatures?

I'm using Eclipse combined with EPIC to write my Perl code. I configured EPIC to use Perltidy with "-pbp" (perl best practices style) to format my code. This doesn't work well when using Method::Signatures' named parameters. E.g., func (:$arg1, : $arg2) is formatted as func (: $arg1, : $arg2) which yields an error. Also, func keyword i...

How can I make Perl die if a warning is generated?

I would like my script perl to die whenever a warning is generated, including warnings which are generated by used packages. For example, this should die: use strict; use warnings; use Statistics::Descriptive; my @data = ( 8, 9, 10, "bbb" ); my $stat = Statistics::Descriptive::Full->new(); $stat->add_data(@data); use warnings FATAL ...

How does Perl pre-increment letters?

Possible Duplicate: Autoincrementing letters in Perl I am trying to understand Perl's pre-increment operator. For every different variable, I find the pre-increment operator behavior strange in Perl. Example : #!/usr/bin/perl $a = "bz"; print ++$a, "\n"; RESULT: ca #!/usr/bin/perl $a = "9z"; print ++$a, "\n"; RESULT: 10...

How do I make pQuery work with slightly malformed HTML?

pQuery is a pragmatic port of the jQuery JavaScript framework to Perl which can be used for screen scraping. pQuery quite sensitive to malformed HTML. Consider the following example: use pQuery; my $html_malformed = "<html><head><title>foo</title></head><body>bar</body></html>>"; my $page = pQuery($html_malformed); my $title = $page->...

Is there a Perl equivalent of Buildout or RVM?

I've been using Python's Buildout for a while and I really like it. My company has a lot of systems developed in Perl and I'm wondering if there is something similar to either Python's Buildout or Ruby's RVM available for Perl. My goal is to be able to automate deployments, development environment setup, and manage dependencies. ...

How can I send an array in client server program in Perl?

I have a Client-Server Perl program. I want to send a message stored in an array to the server. Server code: use IO::Socket::INET; # Creating a a new socket $socket=new IO::Socket::INET->new(LocalPort=>5000,Proto=>'udp'); print "\nUDPServer Waiting for client on port 5000"; while(1) { $socket->recv($recieved_data,1024); $pee...

Is there something better than the kakasi library for gojûon collation?

"Better" primarily means accuracy, but I am also interested any other criteria in which other systems excel. I sampled the Perl binding Text::Kakasi for correctness in an admitted limited fashion and it works just fine for our needs. use utf8; use Encode; use Text::Kakasi; use Unicode::Collate; my $k = Text::Kakasi->new(qw(-iutf8 -outf...

Is there an equivalent to the perl debugger 'x' in pdl2 (or Devel::REPL)?

I am using pdl2 (the PDL shell) also as a my default Perl interactive shell (it loads all the nice plugins for Devel::REPL). But I am missing the x dumper-printing alias. p is nice for piddles but it does not work for a normal array ref or hash ref. I have loaded Data::Dumper but it lacks an easy way of controlling depth and I like the w...

Should I use Perl's conditional ? : operator as a switch / case statement or instead of if elsif?

Perl has a conditional operator that is the same a C's conditional operator. To refresh, the conditional operator in C and in Perl is: (test) ? (if test was true) : (if test was false) and if used with an lvalue you can assign and test with one action: my $x= $n==0 ? "n is 0" : "n is not 0"; I was reading Igor Ostrovsky's blog o...

How can I get DBD::Pg to time out reliably?

Why doesn't this code execute the signal handler until after $sth->execute completes? And more importantly, how can I fix it? #!/usr/bin/perl use strict; use warnings; use DBI; use Sys::SigAction qw( set_sig_handler ); my $dbh = DBI->connect('dbi:Pg:dbname=dc'); eval { my $h = set_sig_handler('ALRM', sub { die "timeout\n" }); ...