perl

How can I make a Perl hash from an array with the keys and another array with the values?

In Perl, how do I make hash from arrays @A and @B having equal number of elements? The goal is to have each value of @A as key to value in @B. The resulting hash %C would,then make it possible to uniquely identify an element from @B supplying key from @A. ...

What does "Maximal count of pending signals (120) exceeded" mean?

My Perl web-app, running under Apache mod_fastcgi, frequently gets errors like the following: Maximal count of pending signals (120) exceeded at line 119. I've seen this happen in relation to file uploads but I'm not sure that's the only time it happens. I also get a SIGPIPE right before (or possibly after) I get that error. Any ...

How can I get a traceback in Perl?

Possible Duplicate: How do I force a stack backtrace for all fatal errors in Perl? One of the things I like about Python, is that when a script exits because of an error, it spits out a traceback. I'm wondering is there anyway of getting a Perl to do this as well? ...

How can a Perl subroutine distinguish between file names, file handes, *DATA, and *STDIN?

If I have a function that might be passed a file name or various file handles or typeglobs, how can the function distinguish among these arguments -- including telling the difference, for example, between *DATA and *STDIN? Updated code, based on answers received so far Thanks, everyone. use strict; use warnings; use FileHandle; sub fi...

Explain the deviousness of the Perl "preamble"

The Perl manual describes a totally devious construct that will work under any of csh, sh, or Perl, such as the following: eval '(exit $?0)' && eval 'exec perl -wS $0 ${1+"$@"}' & eval 'exec /usr/bin/perl -wS $0 $argv:q' if $running_under_some_shell; Devious indeed... can someone please explain in detail how this works? ...

How can I substitute Unicode characters with ASCII in Perl?

I can do it in vim like so: :%s/\%u2013/-/g How do I do the equivalent in Perl? I thought this would do it but it doesn't seem to be working: perl -i -pe 's/\x{2013}/-/g' my.dat ...

How can I implement a singleton class in perl?

What's the best practice for implementing Singletons in Perl? ...

How can I set file permissions from Perl?

I'm writing a Perl script that generates a Bash script. I'm using open() with a mode of > to output everything to a new file. Standard stuff: open (FILEOUT, ">", "rename.sh") or die "Can't create rename.sh"; The resultant .sh file is read only, with an octal value of 444. In perldoc it says I can add a + to the > (open (FILEOUT, "+>",...

How can I handle hash keys containing illegal identifier characters in Template Toolkit?

In Template Toolkit, if I have the following variable containing a hashref: [% artist = { 'life-span' => '1975 to 1987', } %] What is the best way to output the data in 'life-span'? I have tried... [% artist.life-span %] ^This fails because of the hyphen. [% artist.'life-span' %] ^This fails because the syntax is in...

How can I diagnose "Cannot determine peer address" in my Perl TCP script?

I've this little script which does it's job pretty well but sometimes it tends to fail. It fails in 2 cases: with error send: Cannot determine peer address at ./tcp-new.pl line 52 with no output or anything, it just fails to deliver what it got to connected Tcp Client. Usually it happens after I disconnect from server, go home and con...

How can I take screenshots of webpages with Perl?

Is it possible to write a script in Perl that opens different urls and saves a screenshot of each of them? ...

What does a { at the end of a Perl one-liner mean?

Hello, I've seen this one-liner perl -lane '$_{$F[0]}+=$F[1]}print"$_ $_{$_}"for keys%_;{' file here: http://stackoverflow.com/questions/2311228/sum-up-different-row-values-in-a-file-using-sed-awk-perl and I don't remember how the "{" at the end works. Could someone explain how it works? ...

Why is s/^\s+|\s+$//g; so much slower than two separate substitutions?

The Perl FAQ entry How do I strip blank space from the beginning/end of a string? states that using s/^\s+|\s+$//g; is slower than doing it in two steps: s/^\s+//; s/\s+$//; Why is this combined statement noticeably slower than the separate ones (for any input string)? ...

Would using a WSDL to generate REST clients be the wrong direction?

I'm out to create a fairly simple web service for intranet use. The service will ultimately be the interface to a DB that will allow me to keep track of what the various internal tools within the company are doing. I'm thinking I want a web service so that various tools (and thus different languages) within the organization can easily ...

Script for changing C++ class names

I have moved my classes from a global namespace into a specific namespace. I have also changed the class names. I want to convert all my source files that use these classes to the new format. I was thinking either a bash script using a sed file on Cygwin or executing a perl script. I'm having troubles with the bash script. Here's th...

How can I use the value of a variable as a variable name in Perl?

If I have a variable, $bar, which is equal to string "foo" and $foo is equal to 0xdead, how can I get $foo's value while I only have the the string for the variable name? Essentially, I want to do a kind of pointer indirection on the global namespace or a hash lookup on the global namespace. The following didn't work: perl -e 'my $foo...

How can I write only certain lines of a file in Perl?

I am looking for a way to read an input file and print only select lines to an output file in Perl. The lines I want to print to the output file all begin with xxxx.xxxx.xxxx, where x is an alphanumeric character (the periods are periods, not wildcards). The lines do not all have the same ending, if that makes a difference. I'm thinking ...

What's the performance difference between DBI's fetchall_hashref and fetchall_arrayref?

I am writing some Perl scripts to manipulate large amounts (in total about 42 million rows, but it won't be done in one hit) of data in two PostgreSQL databases. For some of my queries it makes good sense to use fetchall_hashref because I have synthetic keys. However, in other instances, I'm going to have use an array of three columns ...

How can I make a new, empty hash reference in Perl?

Say I had something like: # %superhash is some predefined hash with more than 0 keys; %hash = (); foreach my $key (keys %superhash){ $superhash{ $key } = %hash; %hash = (); } Would all the keys of superhash point to the same empty hash accessed by %hash or would they be different empty hashes? If not, how can I make sure they...

How can I store per-thread state between calls in Perl?

Now from what I understand under Perl ithreads all data is private unless explicitly shared. I want to write a function which stores per thread state between calls. I assume that a side effect of all data being thread private by default would allow me to use a closure like this: #!/usr/bin/perl -w use strict; use threads; { # closur...