perl

How can I generate a unique ID using a hash in Perl?

I am writing a message transfer program between multiple clients and server. I want to generate a unique message ID for every message. It should be generated by the server and returned to the client. For message transfer, I am using a hash data structure, for example: { api => POST, username => sganesh, pass => "pass", message => "hai...

Why does my Perl regular expression only find the last occurrence?

I have the following input to a Perl script and I wish to get the first occurrence of NAME="..." strings in each of the <table>...</table> structures. The entire file is read into a single string and the regex acts on that input. However, the regex always returns the last occurrence of NAME="..." strings. Can anyone explain what is goi...

How do I eliminate TT's "Wide character in print" warning ?

I have this warning every time I run my CGI-script (output is rendered by Template::Toolkit): Wide character in print at /usr/local/lib/perl5/site_perl/5.8.9/mach/Template.pm line 163. What's the right way to eliminate it? I create the tt object using this config: my %config = ( ENCODING => 'utf8', INCLUDE_PATH...

How can I split a Perl string only on the last occurrence of the separator?

Hi All, my $str="1:2:3:4:5"; my ($a,$b)=split(':',$str,2); In the above code I have used limit as 2 ,so $a will contain 1 and remaining elements will be in $b. Like this I want the last element should be in one variable and the elements prior to the last element should be in another variable. Example $str = "1:2:3:4:5" ; # $a sho...

How can I start XServer in Linux through apache user triggered by Perl script running in background?

I am trying to launch MS Office through WINE using a PERL script hosted by apache and and triggered by other application. I am getting the following error message in log files "Application trying to create a window but no driver could not be loaded. Make sure that your X server is running and that $DISPLAY is set correctly". If I r...

Why does my Perl system call fail with dot?

I'm a beginner in Perl and I have some trouble using the "system" call. Here is a little piece of code where I try to execute 2 shell commands : # First command is : # dot -Tpng $dottmpfile > $pngfile # Second command is : # rm $dottmpfile if (!($pngfile eq "")) { my @args = ("dot", "-Tpng", $dottmpfile, " > ", $pngfile); system (j...

How can I get the ultimate URL without fetching the pages using Perl and LWP?

I'm doing some web scraping using Perl's LWP. I need to process a set of URLs, some of which may redirect (1 or more times). How can I get ultimate URL with all redirects resolved, using HEAD method? ...

Perl program - Dynamic Bootstrapping code

Hi.. I need to understand the working of this particular program, It seems to be quite complicated, could you please see if you could help me understanding what this program in Perl does, I am a beginner so I hardly can understand whats happening in the code given on the following link below, Any kind of guidance or insights wrt this pro...

How can I get the high-res mtime for a symbolic link in Perl?

I want to reproduce the output of ls --full-time from a Perl script to avoid the overhead of calling ls several thousand times. I was hoping to use the stat function and grab all the information from there. However, the timestamp in the ls output uses the high-resolution clock so it includes the number of nanoseconds as well (according...

How can I get 100% test coverage in a Perl module that uses DBI?

I am a bit new to the Devel::Cover module, but have found it very useful in making sure I am not missing tests. A problem I am running into is understanding the report from Devel::Cover. I've looked at the documentation, but can't figure out what I need to test to get 100% coverage. Edit - I should make it clear that I am not sayin...

What's the encoding for the Google main page?

When Google's main page communicates with Firefox or Chrome it uses a particular type of encoding (Perl says it is utf.64). However, I can't decode it using such; is it a gzipped enconding? I need to finish an app in Perl that should be able to make sense of the Google homepage using Firefox (like a proxy). ...

How do I use sprintf to zero fill to a variable length in Perl?

I want to use Perl's sprintf to zerofill a variable. sprintf("%08d", $var); but I want the dynamically determine how many digits to zero fill. How do I replace the "8" in sprintf("%08d", $var) with a variable called $zerofill. Thanks. ...

How do I correctly shutdown a Bot::BasicBot bot (based on POE::Component::IRC)?

This is a sample script. When I hit Ctrl+C, the bot quits IRC but it reconnects back after some time. How do I shut down the bot correctly? #!/usr/bin/perl package main; my $bot = Perlbot->new (server => 'irc.dal.net'); $SIG{'INT'} = 'Handler'; $SIG{'TERM'} = 'Handler'; sub Handler { print "\nShutting down bot...\n"; $bot->shutdown(...

How can I reorganize a directory structure in Perl?

I am writing a script for renaming/copying the content of a file. I have temp & temp1 folders. Inside temp1 I have 1,000 .txt files with names 1.txt, 2.txt, 3.txt ... & in temp folder I have sub directories named 1, 2, 3. In the folders 1, 2, 3 ..., I have one file with extension java or xml. My need is to automate the copy of the c...

How do i pass null into stdin like this perl code?

This is my question and apparently this is the answer. Turns out it was a buffer problem (solution in the accepted answer of my ffmpeg link) not stdin. I found you can stdout to null by writing > NUL in command prompt so i tried writing < NUL at the end of my argument. No luck. How do i pass in null or do something with the IO locks li...

In Python what's the best way to emulate Perl's __END__?

Am I correct in thinking that that Python doesn't have a direct equivalent for Perl's __END__? print "Perl...\n"; __END__ End of code. I can put anything I want here. One thought that occurred to me was to use a triple-quoted string. Is there a better way to achieve this in Python? print "Python..." """ End of code. I can put anyth...

Is there an easy way to get a list of all successful captures from a regex pre-5.10?

I know the right way to do this if I have Perl 5.10 is to use named captures and values %+, but in Perl 5.8.9 and how can I get a list of successful captures? I have come up with two methods that are both just terrible: #you need to list each possible match my @captures = grep { defined } ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, ...

Why are my "+" characters turned into spaces in my CGI program that handles Ajax requests?

I'm collecting text through a web form and noticing that when it is collected by my Perl CGI all instances of "+" are transformed into " ". I run the text through a JavaScript escape before submission, but escape seems to leave + unaltered. There must be something really obvious that I'm missing... how do I send the string "2 + 2 = 4"...

How can I convert between scientific and decimal notation in Perl?

I know this is a total newbie question, but the answer may not be obvious to many new programmers. It wasn't initially obvious to me so I scoured the Internet looking for Perl modules to do this simple task. ...

How do I use beta Perl modules from beta Perl scripts?

If my Perl code has a production code location and "beta" code location (e.g. production Perl code us in /usr/code/scripts, BETA Perl code is in /usr/code/beta/scripts; production Perl libraries are in /usr/code/lib/perl and BETA versions of those libraries are in /usr/code/beta/lib/perl, is there an easy way for me to achieve such a set...