perl

Net::SCP / Net::SCP::Expect - how to deal with password vs key authentication

I have a script that works on different clients, and need to SCP files to different hosts. Depending on the combination of client & server, I may need to use password authentication or public key authentication. I cannot really know in advance which one to use. There are 2 CPAN libraries for SCP that I use: Net::SCP: works with public...

MySQL comments causing messed up bind parameter count with Perl DBI

I've got the following Perl code which makes a DBI call: my $artsql = q{ *** SNIP A BUNCH OF SQL *** where a.article_id != ? and at.type_name != 'List Element' -- don't get list children and aw.flowstate = 'Published' and a.visible_as_article = 1 } ...

PHP: Read text file into div, then add positioned form fields

I have multiple text files, which are simple reports, that must be reviewed and validated by users. I would like to pull the report into an html div element then add form fields at absolutely positioned locations. For example, the report may have monthly sales by sales rep: Jan Feb Mar 13 9 11 I want the user to see t...

How do I make a shallow copy of a Perl hash reference?

I want to push a reference to a hash. By that I mean I want to push a reference to a new hash that is a shallow copy of the hash I am given. How do I create the shallow copy? ...

How can I avoid sudo-ing when installing Perl modules with cpan?

I have installed Perl from source into /usr/local, and adjusted my path accordingly, following brian d foy's suggestion here. I'm sure I'm missing something, but, now I'm trying to install stuff with the 'cpan' command and it's failing because it can't write to /usr/local. I have to use sudo, which feels wrong to me. Should CPAN stuff g...

Why does Perl's XML::RSS::Parser complain about "End tag mismatch"?

I'm a complete noob in all of this, but sometime ago I wrote a little script in Perl to parse an RSS feed. It starts like this: use strict; use XML::RSS::Parser; use Data::Dumper; my $url = "http://www.livenation.co.uk/Venue/159/Southampton-Guildhall-tickets/RSS"; my $parser = XML::RSS::Parser->new(); my $feed = $parser->parse_uri($url)...

What causes "suexec policy violation" when Perl is called via server side include?

I'm working on a Perl script which is called from a server side include on an Apache 2 server. The script is displaying the generic "Internal Server Error" page rather than showing me the actual error. When I check the Apache error log, I see these messages: unable to include "/foobar/index.pl" in parsed file /home/foouser/domains/foosi...

How do I implement cookie based auth for a Perl website on shared hosting?

I'm very new to Perl, and I have absolutely no idea how to approach this. We have an old Perl application which previously used Apache auth; we'd like to replace this with a cookie based form-style authentication. I understand that this is very case-specific, and there is no one answer as such, but some general tips would be much appreci...

Can I use a Perl's Apache2::ASP CPAN module on shared hosting?

I'm trying to use a Perl module from CPAN (AuthCookieDBI.pm to be specific) in a shared hosting environment. I tried copying the .pm file to the directory I'm trying to use it with, and I have updated my .htaccess file as per the instructions on the AuthCookieDBI page, but my Apache log says: Invalid command 'PerlModule', perhaps missp...

How can I validate XML with XSD in Perl?

This may be a simple question for most Perl programmers, I have only used Perl for two weeks so far and am very unfamiliar with the Perl packages. I have a simple XSD file as below: <?xml version="1.0" ?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sql="urn:schemas-microsoft-com:mapping-schema"> <xsd:element nam...

What's the Perl equivalent of Ruby "foo".hash ?

The hash method on a Ruby String returns a number based on the string's length and content: >> "foo".hash => 876516207 What's the equivalent in Perl? ...

Why does Perl just give me the last line in the file?

Hi, I have downloaded the following file: rawdata_2001.text and I have the following perl code: open TEXTFILE, "rawdata_2001.text"; while (<TEXTFILE>) { print; } This however only prints the last line in the file. Any ideas why? Any feedback would be greatly appreciated. ...

How do I ignore the Perl shebang on Windows with Apache 2?

I have set up a local Perl web environment on my Windows machine. The application I'm working on is originally from a Linux server, and so the shebang for source .pl files look like so: #!/usr/bin/perl This causes the following error on my Windows dev machine: (OS 2)The system cannot find the file specified. Is it possible to chang...

Why am I unable to load a Perl library when using the `do` function?

I'm new to Perl, and I'm updating an old Perl website. Every .pl file seems to have this line at the top: do "func.inc"; So I figured I could use this file to tag on a subroutine for global use. func.inc #!/usr/bin/perl sub foobar { return "Hello world"; } index.pl #!/usr/bin/perl do "func.inc"; print "Content-type: text/html...

Is it possible to obtain the SQL statements generated by Class::DBI?

I want to find the exact SQL statements that are generated by a Perl ORM package such as Class::DBI. I am not looking for SQL generated for simple inserts and deletes, but for row modifications that result from slightly complicated object manipulations (inserting rows in a table which is a child of a row in a parent table, for example) ...

Why does my usage of Perl's DBI->connect fail silently?

Why does this code fail silently? How do I get it to show me exactly what the SQL error is? $dbh=DBI->connect($db_name,$db_user,$db_pass); I modified the code to look like this: $dbh=DBI->connect($db_name,$db_user,$db_pass) or die("could not connect to db: $db_name"); Which instead of allowing me to use $dbh unassigned, it will...

How can I treat command-line arguments as UTF-8 in Perl?

How do I treat the elements of @ARGV as UTF-8 in Perl? Currently I'm using the following work-around .. use Encode qw(decode encode); my $foo = $ARGV[0]; $foo = decode("utf-8", $foo); .. which works but is not very elegant. I'm using Perl v5.8.8 which is being called from bash v3.2.25 with a LANG set to en_US.UTF-8. ...

How can I generate several Perl filehandles programmatically?

Is there any way in Perl to generate file handles programmatically? I want to open ten files simultaneously and write to them by using file handle which consists of (CONST NAME + NUMBER). For example: print const_name4 "data.."; #Then print the datat to file #4 ...

How do I make these Perl regexs Python compatible?

I have these two lines in an old Perl script. When I write the Python equivalent I get all sorts of errors like valueerror: invalid \x escape, and stuff about encoding. $line =~ s/[^\x{8}-\x{7B}]/ /ig; $line =~ s/(Û|²|°|±|É|¹|Í)/ /g; What do I need to do to get them working in Python? ...

How can I access attributes and elements from XML::LibXML in Perl?

I am having trouble understanding / using name spaces with XML::LibXML package in Perl. I can access an element successfully but not an attribute. I have the following code which accesses an XML file (http://pastebin.com/f3fb9d1d0). my $tree = $parser->parse_file($file); # parses the file contents into the new libXML object. my $xpc =...