perl

How can I do paging and sorting in a Perl CGI program?

Here is the table in which I am retrieving the data from an SQLite database. Its having lots of records, so near that ADD button I need something like |< < > >| which would do the paging function whenever I click. Also, besides the table each header (e.g. UserName UserId) I need a sorting button. Something like a ^ button. Please do h...

Why does Perl complain about a syntax error during compilation of my program with this HTML string?

I am facing a problem in my code. Whenever I try to insert a text field then it's giving an error. What's wrong in the syntax here? print '<table>'; print "<tr style='background-color:#CDC9C9;'> <td><A HREF=\"http://localhost/cgi-bin/AddUser.cgi\"&gt;ADD&lt;/A&gt;&lt;/td&gt; <td></td> <td><b>UserId</b></td> <td><input type="text" ...

How do I break an outer loop from an inner one in Perl?

Suppose I have a piece of Perl code like: foreach my $x (@x) { foreach my $y (@z) { foreach my $z (@z) { if (something()) { // I want to break free! } // do stuff } // do stuff } // do stuff } If something() is true, I would like to break ('last') all the loops. how can I do that? I thought of two options, bot...

How can I use Perl regexp characters when inside a bash script?

I would like a command line function that I can run on any file to change the include("myinc.inc"); PHP statement to include 'myfile.inc'; I have made a start by adding the following to my ~/.bashrc file: function makestandard() { perl -p -i -e 's/include\("([\w\.]+)"\)/include '$1'/g' $* } I source ~/.bashrc; and run the command ...

Why can't WWW::Mechanize find the right form?

I'm using WWW::Mechanize to retrieve a form from a webpage: #!/usr/bin/perl use WWW::Mechanize; my $mechanize = WWW::Mechanize->new(); $mechanize->proxy(['http', 'ftp'], 'http://proxy/'); $mechanize->get("http://www.temp.com/"); $mechanize->form_id('signin'); The website HTML has code as follows <form action="https://www.temp.co...

How do I get a slice of a referenced array in Perl?

I have a reference to an array $arr_ref. I would like to get a reference to an array containing only cells i..j in the original array. ...

How do I configure WWW::Mechanize to work behind a proxy and https?

I've written Perl code using WWW::Mechanize to retrieve a webpage. When I retrieve http webpages it works fine but it doesnt work for https. I've checked and I have the Crypt::SSLeay package. What else could be wrong? The error message is.. Error GETing https://www.temp.com: Can't Connect to www.temp.com:443 <Bad hostname 'www.temp.com...

How can I print undef values as zeros in Perl?

I'm building a count matrix in Perl using AoA: my @aoa = () then call $aoa[$i][$j]++ whenever I need to increment a specific cell. Since some cells are not incremented at all, they are left undef (these are equivalent to 0 counts). I would like to print some lines from the matrix, but I get errors for undef cells (which I would simply l...

Premature end of script headers - What, I have no idea!

Hello all, I try to execute a simple perl script on my server and I get an internal 500 server and when I check the error logs it shows: Premature end of script headers: test.pl Here is the perl script: #!/usr/bin/perl -w print "Content-type: text/plain\n\n"; print "testing...\n"; My cgi-bin folder has permissions of 0755. The scri...

Database connection error with Postgres & Movable Type

I'm trying to set up MovableType 4.34 using a Postgres database, and I'm getting the following (unhelpful) error message: Connection error: authentication method 7 not supported The database server doesn't support SSL connections, so I suspect that's to blame -- but I can't be sure (what is "authentication method 7" ?), and at any rat...

Optimize Perl external command

Is there any way I could optimize the following script to run faster? foreach my $arg (@data){ # @score=(); `program $arg $arg1 > $result`; #!!! $arg1 is a very large file with lots of data!!! open(FH,$result); while(<FH>){ chomp; if($_ =~ /\d+.+\s+(\d+\.\d+|\d+\.|\.\d+).+/){ #here i'm looking for any number su...

Perl split with empty text before/after delimiters

I was noticing some curious behavior with Perl's split command, particularly in cases when I would expect the resulting array to contain empty strings '', but it actually doesn't. For example, if I have a delimiter(s) at the end (or the beginning) of the string , the resulting array does not have an empty string(s) '' as the last (or fi...

How can I write in scientific notation using Perl formats?

I've always used printf, and I've never used write/format. Is there any way to reproduce printf("%12.5e", $num) using a format? I'm having trouble digesting the perlform documentation, but I don't see a straightforward way of doing this. EDIT: based on the answers I got, I'm just gonna keep on using printf. ...

How can I parse this text file to get the first group of digits on each line?

I got a text file of this kind INFO [main] (porter.java:100) - Added record 7147 read from file: 1484301 INFO [main] (porter.java:100) - Added record 7148 read from file: 1484302 INFO [main] (porter.java:100) - Added record 17147 read from file: 1484303 INFO [main] (porter.java:100) - Added record 76148 read from...

WWW::Mechanize and Crypt::SSLeay issue with SSL proxy requests

Hi, My perl code is as follows #!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; use Crypt::SSLeay; # proxy $ENV{HTTPS_PROXY}='http://proxy:8080/'; # debugging (SSL diagnostics) $ENV{HTTPS_DEBUG} = 1; my $mechanize = WWW::Mechanize->new(noproxy => 0); $mechanize->proxy(['http', 'https'], 'http://proxy:8080/'); $mechaniz...

Why would Perl's printf output the format specifier rather than the formatted number?

I'm trying to debug a problem on a remote user's site. We've narrowed it down to a problem with formatted output in Perl. The user swears up and down that perl -e 'printf "Number: %lG\n", 0.1' prints Number: %lG not Number: 0.1 The user reports that their Perl is version 5.8. The oldest version I have around is 5.8.1, and it se...

How to do I use a web proxy with Perl's WWW::Mechanize?

I'm trying to use WWW::Mechanize with a proxy server, but seems like I cant get it to work. Since Mechanize is a subclass of LWP::UserAgent, I've been reading about the proxy thing over link text I have a list of proxies, for example: 74.87.151.157:8000 69.171.152.25:3128 190.253.82.253:8080 189.11.196.221:3128 41.234.205.201:808...

How can I assign two arrays to a hash in Perl?

I have lines of code with two large arrays (so can't just write it into a hash) which I want to connect with a hash. For example, $array1[0] becomes the key and $array2[0] becomes the value and so on to $array1[150],$array2[150]. Any ideas how I do this? ...

In a large Perl hash, how do I extract a subset of particular keys?

I have a large hash and have a subset of keys that I want to extract the values for, without having to iterate over the hash looking for each key (as I think that will take too long). I was wondering if I can use grep to grab a file with a subset of keys? For example, something along the lines of: my @value = grep { defined $hash{$_}{...

Sentence Splitter testing file.

Hi all, I am looking for a testing file for my Sentence Splitter Application, and i hope the file can cover as many cases as possible. Thanks! ...