perl

What's the proper way to safely run this error-prone system call in perl?

So as part of a startup script for OS X computer lab systems, I am running a built-in shell command called systemsetup to sync the system with a network time server. It's running inside a perl script as follows. #!/usr/bin/perl system("systemsetup -setusingnetworktime off"); system("systemsetup -setusingnetworktime on"); Flipping it ...

Upload Timeout Issue Under Apache/Perl

Our site provides a upload form for our members to upload photos which we then store and allow them to share. We use a simple form POST to enable the upload and then process the files with Perl's CGI.pm. Here is our Apache setup: Apache/2.0.63 (Unix) mod_ssl/2.0.63 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 Fro...

Test::More doesn't know if test dies - so how do I test?

I'm collecting a bunch of subroutines that are common to a bunch of my scripts into a module. (I should've done this way earlier, but started out with inherited scripts.) I'm modelling my work on the very helpful example here, using Test::More and Module::Build All of the subroutines that read or write from files all include a line op...

How can check whether Perl compilation has already completed?

I have some code the requires the application to be completely loaded and compiled before it should be executed. Is there a way to check whether my Perl program is still in the compilation stage? I have something that works, but there must be a better way: sub check_compile { printf("checking\n"); foreach my $depth (0..10) { m...

telnet inline with perl?

Is there a way to allow perl to initiate a telnet session and programmatically issue commands to that telnet session? I initially tried a stupid method: commands.pl: sleep(1); print $command1; sleep(1); print $command2; and then > perl commands.pl | telnet www.host.com port This does not work. ...

perl Net::Telnet module with telnet shell with no prompt character

The telnet host I am using does not have a prompt character, (it just goes into a blank newline when it is done), how then, should I use the Net::Telnet perl module? I tried setting prompt to // '' /\s/ or /\s*/ none of which worked. '' gave error saying it was invalid, and // /\s/ and /\s*/ simply timed out. my $t = new Net::Telnet ...

What is wrong with this Perl code?

$value = $list[1] ~ s/\D//g; syntax error at try1.pl line 53, near "] ~" Execution of try1.pl aborted due to compilation errors. I am trying to extract the digits from the second element of @list, and store it into $value. ...

Can I set up template inheritance inside a template? (Template Toolkit)

I have to display different medical forms according to which state the user is in. There is also a default form that many of the states share. These medical forms are all written in Template Toolkit and they are included in larger templates. The state is available as a variable in a normalized form. I need to select the state-specifi...

How can I diff two files in Perl?

I have two text files which need to have the same values. $ diff A.txt B.txt 4a5 > I have this extra line. $ Open files in Perl open (ONE, "<A.txt"); open (TWO, "<B.txt"); How can I do such a diff from within Perl? Does Perl have a inbuilt diff or do I need to use the unix diff utility? I don't want to implement my own diff algorit...

Give me some info about REAPER

I a perl code have seen the REAPER has used as a signal handler for SIGCHLD signal . $SIG{CHLD} = \&REAPER; The function also not defined in the code . Can any one deeply explain the internal operation on the `REAPER` . Thanks in advance. ...

working with file handles in Perl

I am writing a comparefiles subroutine in Perl that reads a line of text from one file (f1) and then searches for it in another (f2) in the normal O(n^2) way. sub comparefiles { my($f1, $f2) = @_; while(<f1>) { # reset f2 to the beginning of the file while(<f2>) { } } } sub someother { open (one,...

[Tkx] Buffering/Updating issue for text element

Hi! I have this code: #!/usr/bin/perl use strict; use Tkx; my $mw = Tkx::widget->new('.'); $mw->g_wm_minsize( 400, 350 ); my $btn_start = $mw->new_ttk__button( -text => "Start", -width => 60, -command => sub { start(); } ); my $txt_processed_domains = $mw->new_tk__text( -width => 40, -height => 10, -state => "disabled", -wrap => "n...

Does a console application in Java have access to UI threads?

I've written an applet to allow scanning. This applet uses the TWAIN standard. This standard is used to communicate with scanners. I know TWAIN requires access to UI threads in Windows. The code I wrote worked well when it was used in an applet. The problem starts when I try to use the same code in an console application. I suspect this ...

How do you climb up the parent directory structure of a bash script?

Hello, Is there a neater way of climbing up multiple directory levels from the location of a script. This is what I currently have. # get the full path of the script D=$(cd ${0%/*} && echo $PWD/${0##*/}) D=$(dirname $D) D=$(dirname $D) D=$(dirname $D) # second level parent directory of script echo $D I would like a neat way of fin...

How do I map (and sort) values from a hash of hashes?

I have a hash of hashes, like so: %hash = ( a => { b => 1, c =>2, d => 3}, a1 => { b => 11, c =>12, d => 13}, a2 => { b => 21, c =>22, d => 23} ) I want to extract the "b" element and put it into an array. Right now, I am looping through the hash to do this, but I think I can improve efficiency slightly by using...

Perl Getopt Configure Issues

#test.pl use Getopt::Long; Getopt::Long::Configure ("bundling"); GetOptions ( 'TestB|B|b' => \$testb , 'TestA|A|a' => \$testa, ); Here is my situation i may exute perl test.pl -Ba so i use Getopt::Long::Configure ("bundling"); Because of this my program is getting slowed initally even i tryed to execute with options ...

Initializing an object in Perl

Hi everyone, So, i'm a bit of a perl newb. Although I had something much more complicated going, i all of a sudden hit a roadblock and cannot figure out wtf is wrong with the code. I've simplified it so greatly that it's only a very small fragment of code. Test.pl package Test; sub new { my ($class) = shift; my $self = { _att...

Problem encoding multibyte characters with Perl's HTML::Entities

$perl -e 'use HTML::Entities; print encode_entities("<te£st>");' &lt;te&Acirc;&pound;st&gt; I'm expecting to see: &lt;te&pound;st&gt; ...

Dereferencing an array key in perl

This Script: use strict; my %new; my $test_ref = [24, 26, 55]; $new{$test_ref} = 10; foreach my $key (keys %new){ print $key->[0]; } when i try to access this element, it gives an error like: "Can't use string ("ARRAY(0x...)") as an ARRAY ref" any ideas why? ...

Running a perl script in a batch file

Hi guys, i have a perl script that is used in updating my awstats logs of my website. The script works fine if i just paste it in cmd (Windows) but the moment i paste it in a batch file, it messes up the format of the files generated (they should be prepended with current date/time). The code is: perl C:\PROGRA~2\AWStats\tools\awstats_b...