perl

Perl idiom for getting a maximum number of elements in an array

I wanted to chop off all but the first five elements of an array, so I stupidly did: @foo = @foo[ 0 .. 4 ]; and heartily praised my own cleverness. But that broke once @foo ended up with only three elements, because then I ended up with two undefs on the end, instead of a three-element array. So I changed it to: @foo = @foo > 5 ? @fo...

using PHP to display output from a perl script

I'm new to PHP and I have a working perl script that basically logs into remote servers, cats a log file and displays certain log file information to STDOUT. I want to make this now viewable as a web page, hence looking at PHP to display this output. I just want to view the same output as I see on the terminal for now. The goal would b...

Linux/Perl: Additional output buffers other than STDOUT and STDERR?

Out of curiosity, is it possible to create, instantiate, or otherwise access additional output buffers besides STDOUT and STDERR from within a Perl script? The use case would be additional outputs to pipe in to files or other commands, eg ./doublerainbow.pl 3>full_on.txt 4>all_the_way!.txt ...

Cleanest way of choosing between two values in Python

Dicts in Python have a very nice method get: # m is some dict m.get(k,v) # if m[k] exists, returns that, otherwise returns v Is there some way to do this for any value? For example, in Perl I could do this: return $some_var or "some_var doesn't exist." ...

Segmenting AJAX responses in perl CGI?

Is it possible for a perl cgi script to segment its AJAX responses into numerous individual HTTP responses? Say I have this code: xmlhttp=new XMLHttpRequest(); xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { onDataReceived(xmlhttp.responseText); } else if(xmlhttp.statu...

Why can't my Perl script print cookie values?

When I visit usatoday.com with IE, there're cookie files automatically created in my Temporary Internet Files folder. But why doesn't the following Perl script capture anything? use WWW::Mechanize; use strict; use warnings; my $browser = WWW::Mechanize->new(); my $response = $browser->get( 'http://www.usatoday.com' ); my $cookie_jar = ...

DBD::CSV: Returns header in lower case

I've got a problem with the module DBD::CSV v0.30. Since a update to the newes version, all headers in the fetchrow_hashref generated hash are lower case instead of mixed case. Finaly the data will be comited to a mysql database and the column header should be mixed case. This is a snipet of my script using the DBD::CSV my $csv_dbh ...

How to set Oracle nls_date_format using Class::DBI

Hi there, I followed the example on wiki.class-dbi.com to alter the Oracle session but it does not seem to work. Below is a snippet from my code (strictures and warnings removed for clarity of the problem). package MyDB; use base 'Class::DBI::Oracle'; __PACKAGE__->connection('dbi:Oracle:dbname', 'user', 'password'); __PACKAGE__->db_Ma...

Determining if the HTTP scheme is https or http in mod_perl2?

I need to work out if an incoming request is using SSL in a mod_perl environment - how can I do this reliably? ...

Redirecting the output of expect to logfile in expect

Hi I am using expect in perl. I want to redirect all the output that appears on the stdout console to a log file so that i can debug it in future. Currently i am using $exp->log_stdout(0); Instead of redirecting to this can i do it to a log file? if so how to do it? ...

Why does Perl's quotemeta() function behave differently when under the debugger?

I am bitten by this little inconsistent debugger behavior. The quotemeta() function seems to behave differently when invoke under perl -d $ perl -e 'print quotemeta("/a/b/c"),"\n"' Output is \/a\/b\/c, which is correct and as documented in perldoc -f quotemeta. Now, when under debugger, the output becomes \\/a\\/b\\/c. I thought some ...

Are there benchmarks on how bad the performance regression in Perl 5.10.0 was?

I am working in a high availability environment at the moment, so performance is a bit of an issue for this company. I found out today they are running Perl 5.10.0, which according to perl5101delta has a performance regression in list assignments. Now since we're on Debian, updating isn't exactly easy, so I am looking for statistics to m...

uri_for includes port number on redirects

I'm attempting to implement a Catalyst application using nginx as a frontend web proxy for static files, and using Starman for my backend webserver. (I could use Apache & FastCGI and it works just fine, but I'd really like to get the whole PSGI / Plack and Starman thing ironed out) Starman starts up okay and can handle my requests ju...

Why doesn't this positive look-behind assertion work when anchored to the start of the string?

Why doesn't this look-behind assertion work when it's anchored to the front of the string? Run the following code and you'll see that the first test passes but the second, which varies only by the ^ anchor, fails. use Test::More tests => 2; my $s = '/123/456/hello'; $s =~ s{(?<=/)\d+(?=/\d+/hello)}{0}; # unanchored is($s, '/0/456...

what kind of logging and reporting is google using ?

what kind of logging and reporting is google using ? Am just wondering what kind of logging google does for its heavily used applications. As we all know most of the google products are heavily used. Normally any product/tool will have logs, which have to be analysed and report has to be produced. Any guess what kind of tool or program...

passing data structures from java to perl

Hi, I would like to pass some data structures from java to perl. In perl, this should basically be a hash where the keys are strings and each value is either a string, a hash or a hash of hashes. Is there a way to dump data from java that can be easily parsed by perl? ...

Bash: Chroot command passing 2 string parameters or better run a series of commands

I would like to do something like this: chroot /mount-point /path/to/script $var1 $var 2 Will this work? Will the chrooted Perl script be passed on these 2 parameters? If not, how to do this? Otherwise, is there any way to simply do chroot in the script, and then start doing commands such as perl script.pl $var1 $var2 etc? As I u...

Looping through files with perl

Okay I have 2 files. One file is data that is updated every 10 minutes while the second is data that was previously used. What I am trying to do is take one line from the new file and loop through each line of the second file and see if it matches one. If it does I dont want to use it, but if there is no match than I want to add it to a ...

perl dbi handlers interacting with each other

I'm having a weird issue where I have 2 dbi handlers and they are interacting with each other in some non-obvious manner. Specifically, I set up 2 handlers, one for an insert, and one calling a stored proc, and if I call them like $spHandler->execute($cusip); $insertHandler->execute('2010-05-01', '36200A3C1', 595795,'X', 3); Then th...

Monster perl regex

I'm trying to change strings like this: <a href='../Example/case23.html'><img src='Blablabla.jpg' To this: <a href='../Example/case23.html'><img src='<?php imgname('case23'); ?>' And I've got this monster of a regular expression: find . -type f | xargs perl -pi -e \ 's/<a href=\'(.\.\.\/Example\/)(case\d\d)(.\.html\'><img src=\'...