perl

What's wrong with my CGI::Session installation?

I installed CGI::Session module on my host by creating the perl-modules directory in my cgi-bin and then extracting the module to that directory so I have: D: cgi-bin/perl-modules/CGI/ F: cgi-bin/perl-modules/CGI/Session.pm D: cgi-bin/perl-modules/CGI/Session/ F: cgi-bin/perl-modules/CGI/Session/File.pm D: cgi-bin/perl-modules/CGI/Sessi...

In Perl, how can I block for a bunch of system calls to finish?

I'm doing a bunch of system calls that I want to run in parallel: system(" sleep 5 && echo step 1 done &"); system(" sleep 3 && echo step 2 done &"); system(" sleep 7 && echo step 3 done &"); // block here How can I block the program flow until all the system calls are finished? ...

perl's rmtree() failing to delete directory on win32, successful on second try

In Perl, I do a: rmtree($myfolder); Often this fails on windows. When ran again, it then succeeds. It seems like somehow it takes a while to delete the files in the folder, and somehow it tries to delete the folder before the files are gone. Is there a "this one actually works" Perl method to erase an directory with all its contents ...

How can I get the frame source with Perl's WWW::Mechanize?

Using WWW::Mechanize::Firefox, I can get the source of the page I visited. However, if the page contains a frame, I get the frame tag and not the actual source of the page that is loaded. Mechanize::Frames seems to be what I am looking for. Is there a way to use them together? ...

How can I report the line number with Log4perl and Moose?

Is it possible to get Log4perl to correctly display the line number and package/class of the log event instead of always Method::Delegation at line 99 when used with Moose? In my case, I have created an attribute isa Log::Log4perl::Logger and delegated the various logging levels to my class (log, warn, error, ...). Doing this also show...

How do I use async programming in Perl?

Is there a simple way to do async in Perl? I have the following logic for an Apache app: get request process request write to log return what I want to do is to have the "write to log" part to be async, so that I can do the "return" part asap. ...

Running only one Perl script instance by cron

I need to run Perl script by cron periodically (~every 3-5 minutes). I want to ensure that only one Perl script instance will be running in a time, so next cycle won't start until the previous one is finished. Could/Should that be achieved by some built-in functionality of cron, Perl or I need to handle it at script level? I am quite n...

Why can't WWW::Mechanize::Firefox locate it's "new" method?

I get the following error when I run the little sample script: Can't locate object method "new" via package "WWW::Mechanize::Firefox" (perhaps you forgot to load "WWW::Mechanize::Firefox"?) at mechtest.pl line 2. use WWW::Mechanize::Firefox; my $mech = WWW::Mechanize::Firefox->new(); $mech->get('http://google.com'); $mech->eval_in_pag...

How can I delete the lines which include subStr1 and subStr2 in a big file?

Hi. How can I delete the whole lines which included both subStr1 and subStr2 in a big file and save as a new smaller file. Part of my file content below. 12-23 20:27:35:265 GetVariable [Tunnel] INFO iVid = 536876042 data [Reruen] = System.Object[] 12-23 20:27:35:265 GetVariable [Tunnel] INFO iVid = 536876043 data [Reruen] =...

How can I screen-scrape output from telnet in Perl?

I can setup a telnet connection in Perl no problems, and have just discovered Curses, and am wondering if I can use the two together to scrape the output from the telnet session. I can view on a row, column basis the contents of STDOUT using the simple script below: use Curses; my $win = new Curses; $win->addstr(10, 10, 'foo'); $win->r...

How do I convert local time to unix time stamp in Perl?

For ex : from date : 10/02/2010 How to convert equal time stamp for 10/02/2010 00:00:00 in Perl I cant use local time or time .. is there any other way to achieve this .. ...

How can I parse and echo CGI query string parameters?

I would like to execute a command on the server by using the system request parameters in the URL. I am running the server. In the browser ->> //localhost:9009/?comd which is displaying the list of files in the directory as i placed in the code if (/comd/i ) { print $client `dir`; } How I can parse the request parameters...

What is the default scope of foreach loop in Perl?

In Perl, does using 'my' within a foreach loop have any effect? It seems that the index variable is always local whether or not 'my' is used. So can you drop the 'my' within the foreach loop and still have private scope within the body of the loop? As can be seen, using the 'for' loop there is a difference between using / not using 'm...

How can I generate HTML documentation for Perl code comments?

I've come into ownership of a bunch of code that's held together with various Perl scripts. There's some documentation in the form of comments (not Pod) embedded in these scripts that I'd like to be able to extract and browse in an HTML format. Basically, I'm looking for something like javadoc or rubydoc, but for Perl. "perldoc" seeme...

How can I get structured exceptions from Moose?

Consider this simple class: package Foo; use Moose; has foo => ( is => 'rw', isa => 'Int' ); And then this code: use Try::Tiny; use Foo; my $f = try { Foo->new( foo => 'Not an Int' ); } catch { warn $_; }; The code dies with a nice big error message about type constraints failing. I'd like to be able to extract what attrib...

If statements inside or outside loops?

Is it better if I do this: foreach my $item ( @array ) { if ( $bool ) { .. code .. } else { .. code .. } } or if ( $bool ) { foreach my $item ( @array ) { } } else { foreach my $item ( @array ) { } } ...

Why do I have to use a * in front of a Perl bareword filehandle?

While trying to do this: my $obj = new JavaScript::Minifier; $obj->minify(*STDIN, *STDOUT); // modified above line to $obj->minify(*IP_HANDLE,*OP_HANDLE) The above works if IP_HANDLE and OP_HANDLE are filehandles but still I am not able to figure out what actually the * does when applied to a filehandle or any other datatype. Than...

Best strategy to build custom batch search engine?

Hi I need to build a site similar to indeed.com and so many others, that tracks a number of advertising sites and parses the HTML to list the ads in my own site. I know that each source-site needs a particular strategy. That's no problem. My concern is that I want to scan the sites hourly in a batch-fashion. Is there a better suitable...

how to parse request URL in simple server in Perl which listen to port

here is the request URL http://localhost:9009/?comd&user=kkc&[email protected] what are the modification need to do in the server perl script. server-Perl-script use IO::Socket; use Net::hostent; # for OO version of gethostbyaddr $PORT = 9009; # pick something not in use $server = IO::Socket::INET->new( Proto ...

How can I pass value to Perl Subroutine parameters on command line?

Hi. my test.pl script as below. #!C:\Perl\bin\perl.exe use strict; use warnings; sub printargs { print "@_\n"; } &printargs("hello", "world"); # Example prints "hello world" If I replaced printargs("hello", "world"); with print($a, $b);. How to pass 'hello' ,'world' to $a , $b when I run perl test.pl hello world at comman...