perl

Why does my Perl CGI complain "Can't locate Mysql.pm"?

I have two folders php and perl. They contain index.php and index.pl, respectively. My Perl code looks like: #!/usr/bin/perl use Mysql; print "Content-type: text/html\n\n"; print "<h2>PERL-mySQL Connect</h2>"; print "page info"; $host = "localhost"; $database = "cdcol"; $user = "root"; $password = ""; $db = Mysql->connect($host, $dat...

What is the right way to serve dynamically generated images using Apache and mod_perl?

I have an Apache2/mod_perl2 system up and running. I'm using GD to create an image on the fly, and I'm then printing it like this: $r->content_type('image/png'); binmode STDOUT; print $im->png; But is this the correct way to do things in mod_perl2? (Ignore the fact that I'm generating an image on the fly and not caching it etc ...) ...

How can I invoke a PHP script from Perl?

How can I call a PHP script from a Perl script and get its output as a variable? ...

How can I sum array values by unique key?

For example array ( product1_quantity => 5, product1_quantity => 1, product2_quantity => 3, product2_quantity => 7, product3_quantity => 2, ) with result: product1_quantity - 6, product2_quantity - 10, product3_quantity - 2 Thanx! sorry, guys stupid example, instead this really Array ( [0] => Array ( [product1] => 7 ) [1] =...

How do you create a transparent truecolor PNG with Perl & GD?

It seems like a trivial problem, but nothing I've tried will make the background transparent. use strict; use warnings; use GD GD::Image->trueColor(1); my $im = new GD::Image(100, 100); my $clear = $im->colorAllocateAlpha(255, 255, 255, 127); my $black = $im->colorAllocateAlpha(0, 0, 0, 0); $im->alphaBlending(0); $im->filledRectangle...

How can I manage a fork pool in Perl?

I'm setting something up to SSH out to several servers in 'batches'. I basically want to maintain 5 connections at a time, and when one finishes open up another (following an array of server IPs). I'm wondering for something like this should I be using fork()? If so, what logic can I use to ensure that the I maintain 5 children at a tim...

How can I sort a Perl array of array of hashes?

@aoaoh; $aoaoh[0][0]{21} = 31; $aoaoh[0][0]{22} = 31; $aoaoh[0][0]{23} = 17; for $k (0 .. $#aoaoh) { for $i(0.. $#aoaoh) { for $val (keys %{$aoaoh[$i][$k]}) { print "$val=$aoaoh[$i][$k]{$val}\n"; } } } The output is: 22=31 21=31 23=17 but i expect it to be 21=31 22=31 ...

Using HTML::Template within a value attribute

Hello, my question is how would I use an HTML::Template tag inside a value of form field to change that field. For example <table border="0" cellpadding="8" cellspacing="1"> <tr> <td align="right">File:</td> <td> <input type="file" name="upload" value= style="width:400px"> </td> <...

How do I find the sum of all values from two different arrays in Perl?

How to find the sum of all values from two different arrays in Perl? @array1 = (1, 2, 3); @array2 = (10, 10, 10); @sumofarray1and2 = ? So I figured I can do two kinds of things here. I can do two foreach loops and add contents of @array1 and @array2 first then get the sum of both. ...

Why do I get an extra newline in the middle of a UTF-8 character with XML::Parser?

I encountered a problem dealing with UTF-8, XML and Perl. The following is the smallest piece of code and data in order to reproduce the problem. Here's an XML file that needs to be parsed: <?xml version="1.0" encoding="utf-8"?> <test> <words>בְּרֵאשִׁ֖ית בָּרָ֣א אֱלֹהִ֑ים אֵ֥ת הַשָּׁמַ֖יִם וְאֵ֥ת</words> <words>בְּרֵאשִׁ֖ית בָּרָ֣...

Hopping from a C++ to a Perl/Unix job

Hi all, I have been a C++ / Linux Developer till now and I am adept in this stack. Of late I have been getting opportunities that require Perl, Unix (with knowledge of C++,shell scripting) expertise. Organizations are showing interest even though I don't have much scripting experience to boast off. The role is more in a Support, mainten...

How can I take a reference to specific hash value in Perl?

How do I create a reference to the value in a specific hash key. I tried the following but $$foo is empty. Any help is much appreciated. $hash->{1} = "one"; $hash->{2} = "two"; $hash->{3} = "three"; $foo = \${$hash->{1}}; $hash->{1} = "ONE"; #I want "MONEY: ONE"; print "MONEY: $$foo\n"; ...

How can I pause the console window in .pl and .bat file?

As I know, when I run cs myConsoleApp.cs from windows command line, I can pause the Console Window by add the code below: Console.ReadLine(); Then How can I pause Console Window in myConsoleApp.pl and myConsoleApp.bat? I just want to monitor the running result from the Console window. Thank you. Suppose myConsoleApp.bat like this: ta...

Why does my Perl CGI script complain about "Can't locate CGI/Simple.pm"?

For more information see this Example use strict; use warnings; use CGI::Simple; use DBI; my $cgi = CGI::Simple->new; my $dsn = sprintf( 'DBI:mysql:database=%s;host=%s', 'cdcol', 'localhost' ); my $dbh = DBI->connect($dsn, root => '', { AutoCommit => 0, RaiseError => 0 } ); my $status = $dbh ? 'Connected' : 'Failed to con...

How can I find the Nth largest value without using Perl's sort()?

I have written following code in Perl: #!/usr/bin/perl @array = (3,6,8,1,2); my $second_largest = 0; my $largest = 0; for (@array) { if($_ > $largest) { $second_largest = $largest; $largest = $_; } if($_ > $second_largest && $_ < $largest) { $second_largest = $_; } } print "Second largest::".$s...

How can I maintain a sorted hash in Perl?

@aoh =( { 3 => 15, 4 => 8, 5 => 9, }, { 3 => 11, 4 => 25, 5 => 6, }, { 3 => 5, 4 => 18, 5 => 5, }, { 0 => 16, 1 => 11, 2 => 7, }, { 0 => 21, 1 => 13, 2 => 31, }, { ...

How can I add only unique values to an anonymous array used as a hash value?

EDIT Sorry I forgot the most important part here. Each key can have more than one value. Apologies to those who already answered. print and join will be used later to print multiple values for $key on a single line. In the example code below, assuming that the value $keyvalue is constantly changing, I am attempting to use a single line ...

How can I decrypt encrypted files using a PEM private key?

I have files which have either been encrypted with a public key and the Blowfish algorithm, or a public key and the AES-256 algorithm. I'm looking to put together a Perl script that would be able to use the private keys (which I do have) to decrypt the files. The public and private key files are all in PEM format, and while I can fin...

How can I make WWW:Mechanize to not fetch pages twice?

I have a web scraping application, written in OO Perl. There's single WWW::Mechanize object used in the app. How can I make it to not fetch the same URL twice, i.e. make the second get() with the same URL no-op: my $mech = WWW::Mechanize->new(); my $url = 'http:://google.com'; $mech->get( $url ); # first time, fetch $mech->get( $url ...

Perl for a Python programmer

I know Python (and a bunch of other languages) and I think it might be nice to learn Perl, even if it seems that most of the people is doing it the other way around. My main concern is not about the language itself (I think that part is always easy), but about learning the Perlish (as contrasted with Pythonic) way of doing things; becau...