perl

Is there a Standard or Best Practice for Perl Programs, as opposed to Perl Modules?

I've written any number of perl modules in the past, and more than a few stand-alone perl programs, but I've never released a multi-file perl program into the wild before. I have a perl program that is almost at the beta stage and is going to be released open source. It requires a number of data files, as well as some external perl modu...

Is it possible to mix a named pipe with select in perl?

I need to write a daemon that supposed to have one TCP socket and one named pipe. Usually if I need to implement a multi IO server with "pure" sockets, the select based multi-IO model is always the one I will choose. so does anyone of you have ever used named pipe in select or you can just tell me it is impossible. thanks in advance. ...

Advice on coding Perl to work like PHP

I am first and foremost a perl coder, but like many, also code in PHP for client work, especially web apps. I am finding that I am duplicating a lot of my projects in the two languages, but using different paradigms (e.g. for handling cgi input and session data) or functions. What I would like to do is start to code my Perl in a way w...

Are there any good timer implementations in Perl?

I'm looking for good timer implementation in perl. The situation I met is like: I need to keep track of I/O activities of many files and for thoes files keep untouched for enough time a remove action will be taken upon them, so an efficient timer implementation is really vital for the app I'm involved right now. To avoid recreate the whe...

C++ getch() in perl?

In c++, there is a functio, getch(), which returns the variable of the key you pressed - like enter would be 13. How could I do this in perl? ...

Why can't I add to the middle of an array with Perl's Tie::File?

File : #comment1 #comment2 #comment3 #START HERE a: [email protected] b: [email protected] my perl program : use Data::Dumper; use Tie::File; tie my @array, 'Tie::File', 'ala.txt' or die $!; my $rec = 'p: [email protected]'; my $flag =1 ; my $add_flag = 0; for my $i (0..$#array) { next if ($array[$...

Missing $ on loop variable

Hi, 1 #!/usr/bin/perl 2 use strict; 3 use warnings; 4 5 my @array = qw[a b c]; 6 foreach my($a,$b,$c) (@array) { 7 print "$a , $b , $c\n"; 8 } I receive following error: Missing $ on loop variable What is wrong? I am using: perl v5.10.1 (*) built for x86_64-linux-thread-multi ...

Testing FastCGI script in Perl using standalone Perl FastCGI / FCGI web server

I have a FastCGI Perl web app (written using CGI::Fast, but that should not matter), that I'd like to test in FastCGI mode. What Perl module can I use to run FastCGI application (the module should install from CPAN, best if it didn't use extra libraries), so that can I point web browser e.g. to http://localhost:5000 to check if it work ...

Options to create editable graph or scheme with Perl ?

Hi, I'm searching for a way to create complex/simple graph using Perl. The known modules/applications I've checked are: GraphViz, Graph-Easy, aiSee etc. Each way I walked, new problems appeared. If my need is to create graph dependencies that can be edited live have a directed compass mode work fine and are readable with massive data...

Escape Single Quotes in Template Toolkit

Do you ever escape single quotes in template toolkit for necessary javascript handlers? If so, how do you do it. [% SET s = "A'B'C" %] <a href="/abc.html" onclick="popup('[% s | html_entity %]')">ABC</a> html_entity obviously doesn't work because it only handles the double quote. So how do you do it? ...

Is this trivial function silly?

I came across a function today that made me stop and think. I can't think of a good reason to do it: sub replace_string { my $string = shift; my $regex = shift; my $replace = shift; $string =~ s/$regex/$replace/gi; return $string; } The only possible value I can see to this is that it give...

Simple perl array function doesn't work

This simple Perl script is translating stories from a database into XML, but this one section is giving me problems. The function makeUrl is called for each story, but needs to ensure that duplicate URLs aren't created. my @headlines = (); my $hlCount = 1; . . . sub makeUrl { my $headline; open( URLSOUT, '>>/var/mtkoan/harris/urls'...

How to detect changing directory size in Perl

Hello, I am trying to find a way of monitoring directories in Perl, in particular the size of a directory, and upon detecting a change in directory size, perform a particular action. The issue I have is with large files that require a noticeable amount of time to copy into this directory, i.e. > 100MB. What happens (in Windows, not Uni...

extract word with regular expression

I have a string 1/temperatoA,2/CelcieusB!23/33/44,55/66/77 and I would like to extract the words temperatoA and CelcieusB. I have this regular expression (\d+/(\w+),?)*! but I only get the match 1/temperatoA,2/CelcieusB! Why? ...

Perl Regex - Condensing groups of find/replace

I'm using Perl to perform some file cleansing, and am running into some performance issues. One of the major parts of my code involves standardizing name fields. I have several sections that look like this: sub substitute_titles { my ($inStr) = @_; ${$inStr} =~ s/ PHD./ PHD /; ${$inStr} =~ s/ P H D / PHD /; ${$inStr} =...

Capturing exit status from STDIN in Perl

I have a perl script that is run with a command like this: /path/to/binary/executable | /path/to/perl/script.pl The script does useful things to the output for the binary file, then exits once STDIN runs out (<> returns undef). This is all well and good, except if the binary exits with a non-zero code. From the script's POV, it thin...

deleting all the file of certain size

i have bunch of log files and I have to delete the files of some small sizes, which were erroneous files that got created. ( 63bytes ). I have to copy only those files which have data in it . ...

How to have Moose return a child class instance instead of its own class, for polymorphism

I want to create a generic class, whose builder would not return an instance of this generic class, but an instance of a dedicated child class. As Moose does automatic object building, I do not get to understand if this something possible, and how to create a Moose class with Moose syntax and having this behaviour. e.g.: The user asks:...

Can I send a ESC d command to a POS printer from perl?

I have a Star TSP100 printer and I'm having few problems with it really. My problem is that I'm not as familiar with programming as I should be - but I'm learning! The programmers reference for the Star printer says that if I send a ESC d to the printer - that will activate the built-in cutter - which I would like to do very much. My...

Is there a way to make this perl code capture stderr as well as stdout from a tcsh?

open UNIT_TESTER, qq(tcsh -c "gpath $dir/$tsttgt; bin/rununittests"|); while(<UNIT_TESTER>){ reportError($ignore{testabort},$tsttgt,"test problem detected for $tsttgt:$_ ") if /core dumped/; reportError($ignore{testabort},$tsttgt,"test problem detected for $tsttgt:$_ ") if /\[ FAILED \]/; writelog($tstt...