perl

How do I return a list as an array reference in Perl?

Hey. In Python I can do this: def fnuh(): a = "foo" b = "bar" return a,b Can I return a list in a similarly elegant way in perl, especially when the return type of the subroutine should be a reference to an array? I know I can do sub fnuh { my $a = "foo"; my $b = "bar"; my $return = []; push (@{$return}, ...

Perl XS included from a “use lib” directory can’t be found by ISAPI.

I have a Perl web application that runs on both Apache and IIS6 on Windows Server 2003. On Apache this script works just fine. In IIS using ISAPI, I am getting the following error message: Software error: Can't load 'lib/auto/Sub/Name/Name.dll' for module Sub::Name: load_file:The specified module could not be found at C:/...

"Real" and non-embedded use of Ruby, Python and their friends

Hello! So I'm aware of the big ammount of general-purpose scripting languages like Ruby, Python, Perl, maybe even PHP, etc. that actually claim being usable for creating desktop applications too. I think my question can be answered clearly Are there actually companies using a special scripting language only to create their applicatio...

How to escape a native SQL function in perl bind_param()?

So I have the following snippet code: my $sql = "INSERT INTO mytbl (first_name, last_name, birthdate) VALUES (?, ?, ?)"; my $sth = $dbh->prepare($sql) or die "Error:".$dbh->errstr; $sth->bind_param(1, $fname); $sth->bind_param(2, $lname); $sth->bind_param(3, $bdate); $sth->execute() or die "Execution failed: " . $dbh->...

Where can I find information about the $[ variable in Perl?

I tried Google. I tried Yahoo. I tried Bing. None of them had results for the $[ variable. Does anyone know where I can find the documentation for it? ...

How do I use an environment variables in xi:include of a XML file?

I would like to use an environment variable in the href link of the xi:include node of an XML file. Currently the Perl XInclude parser doesn't support any variables but only absolute paths. Is there a method where this can be overcome? for example, my xi:include node will look like this: <xi:include href="$GLOBAL_ROOT/alternative.xml"> ...

Do I need "close FILEHANDLE" check for errors?

Hello, does the "or die $!"-part in the "close $fh or die $!;"-line any good? #!/usr/bin/env perl use warnings; use strict; my $file = 'my_file'; open my $fh, '<', $file or die $!; print <$fh>; close $fh or die $!; ...

Perl script not working.. (Error : Premature end of script headers)

I am trying to print a XML file in the browser using a perl script. While I am trying to run the script in my browser I am having the following error. Server error! The server encountered an internal error and was unable to complete your request. Error message: Premature end of script headers: get_data.pl If you think this is a server...

Perl: opening a file, and saving it under a different name after editing.

Hello! I'm trying to write a configuration script. For each customer, it will ask for variables, and then write several text files. But each text file needs to be used more than once, so it can't overwrite them. I'd prefer it read from each file, made the changes, and then saved them to $name.originalname. Is this possible? ...

how to reverse an anonymous list in template toolkit?

Is it possible to reverse an anonymous list in template toolkit? e.g. [% FOREACH month IN [1..12].reverse %] [% month %] [% END %] (except that doesn't work). Just wondered if there was a neat way to do it without using variables or explicitly typing out the array. ...

Why isn't my image in the center when I use Perl::Magick's Extent with Gravity?

I am trying to use ImageMagick to extent an image a little bit: my $image = Image::Magick->new; open( IMAGE, $filename ); $image->Read( file => \*IMAGE ); close(IMAGE); $image->Extent( gravity => 'Center', width => 150, height => 150, ); $image->Write( $outfile ); while the the image is extented to the correct size, it is not in the...

Are there some up-to-date tutorials on Perl network programming?

Are there links, materials, or books about network programming with Perl that are relevant to 2010? I saw some books on programming the network with Perl are very old (about a decade) and the tutorials on the internet are also old and using old modules. Could someone provide a good reference about programming sockets and network layer/...

What are the potential implications of a deep call stack in Perl?

I was told that the following portion of code is deeply recursive. However I don't understand how - can someone explain? If so, what are the associated implications? Note: Trivial example check: # Grab some data held in a file while ((ReadFile ()) != 0 ) { if ((checkSomething ...

How can I extract digits at the end of a string using Perl?

I have a string of the form: "jflsdlf f fas253k46l ;sf635jsf sd;lfwio sfkljflsk-=fsd f 24461 425 " Toward the end it contains eight digits. There may be spaces between the digits, but there are always eight digits in the end. How do we obtain each of these digits separately using Perl? ...

How can I create a SOAP server in Perl?

I'm working with a third-party vendor who unfortunately requires that we set up a SOAP server to handle requests from them. I'm having some trouble finding the best way to go about this. One limitation I'm imposing is that it runs as a mod_perl2 handler. After some searching I've found that the best way may be to use XML::Compile and ...

How can I handle arrow keys in a Perl script under cygwin?

I am running Perl script under cygwin which takes input from <STDIN> and process the requests continuously. #!/usr/bin/perl print "Enter Input:"; while(<STDIN>) { print "Recieved Input: $_"; print "Enter Input:"; } $perl testPerl.pl Enter input:input1 Recieved input:input1 Enter input:inpt2 Reciev...

What are the pros and cons of using the two different programming styles of CGI.pm with Perl?

I am in a Web Scripting class at school and am working on my first assignment. I tend to overdo things and delve deeper into my subject than what is required in my classes. Right now I am researching CGI.pm to do my HTTP requests and it says there are two programming styles for CGI.pm: An object-oriented style A function-oriented style...

What's wrong with this findnodes statement in my Perl's script?

I have a simple xml file that looks like this: <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <microplateDoc xmlns="http://moleculardevices.com/microplateML"&gt; <camelids> <species name="Camelus bactrianus"> <common-name>Bactrian Camel</common-name> <physical-characteristics> <mass>450 to 500 kg.</mass> ...

Why can't I access elements inside an XML file with XPath in XML::LibXML?

I have an XML file, part of which looks like this: <wave waveID="1"> <well wellID="1" wellName="A1"> <oneDataSet> <rawData>0.1123975676</rawData> </oneDataSet> </well> ... more wellID's and rawData continues here... I am trying to parse the file with Perl's libXML and output the wellName and the rawDat...

Why don't I get zero when I subtract the same floating point number from itself in Perl?

Possible Duplicates: Why is floating point arithmetic in C# imprecise? Why does ghci say that 1.1 + 1.1 + 1.1 > 3.3 is True? #!/usr/bin/perl $l1 = "0+0.590580+0.583742+0.579787+0.564928+0.504538+0.459805+0.433273+0.384211+0.3035810"; $l2 = "0+0.590580+0.583742+0.579788+0.564928+0.504538+0.459805+0.433272+0.384211+0.3035810"; $...