perl

Strange result on perl regexp - end string anchor & ungreedy at once.

I have a very simple substitution: my $s = "<a>test</a> <a>test</a>"; $s =~ s{ <a> .+? </a> $ }{WHAT}x; print "$s\n"; that prints: WHAT But I was expecting: <a>test</a> WHAT What do I misunderstand about "end string anchor" in interaction with ungreedy option? So, I was wrong about regexp engine. Indeed, dont humanize code -...

perl sort temporary directory

I ran into space issues on my machine and therefore the sort command in unix failed because of lack of space in /tmp. In order to circumvent this, I decided to run sort with the -T option allowing it to use some other directory for creating temporary files. here is the perl script I have my $TMPDIR = "/home/xyz/workspace...

Unlocked, shared hash operation safety in threaded perl

Question Is it safe for multiple threads to fetch and store simple, individual values in a shared hash without lock()ing the hash? Can you prove it or cite strong authority? Background My belief was that at worst unlocked hash manipulations could lead to segfaults. However, I've very recently seen code that coordinates worker thread...

In perl, checking an array for a value and removing it if exists for each value of another array

Basically, I have an array, let's say @badvalues. I have another array, let's say @values. Basically, I want this: For each element in @badvalues See if it is in @values If it is, delete it Ultimately, I should end up with either the array @values, containing no elements that are in the array @badvalues, or a new array, @goodvalues,...

How does Python stack up to other scripting languages?

I'm learning Python (and it's my first programming language so don't be too intense with your reasons) and I wanted to know how it stacks up to other scripting languages, like Perl and Ruby. What is Python better in comparison to other scripting languages, and what is it worse for? ...

Perl RegEx for Matching 11 column File

...

Perl system command not acting as a normal prompt

I am trying to modify a perl script to comment out all lines matching some pattern. In normal command prompt, here is the line I'm trying to add: grep -lIRZ --exclude="*\.svn*" "pattern" . | xargs -0 -l sed -i -e 's/.*pattern.*/\/\/&/g' Here it is in the context of the perl script: my $rmcmd = "grep -lIRZ --exclude=\"*\\.svn*\" \"pa...

Simple example of using data from a YAML configuration file in a Perl script

I need to create a YAML file to store some configuration data for a Perl script. This seems like it should be really easy but I haven't been able to work it out, I think if I had just one simple example to copy I'd be fine. I want to do something like this: -----test.yaml----- image_width: 500 show_values: 0 ------------------- ------t...

Apache 2.2 CGI perl timeouts, still times out even with periodic prints.

I have a cgi code that is being called by AJAX from clientside javascript. However, the result of the call is discarded by the client. On the backend this code occurs: $|=1; my $i = 0; while (<$fh_echo>) { #To prevent apache timing out the cgi script. print "." if $i % 100 == 0; #Do stuff $i++; } Despite the period...

To bless or not to bless, that is my question!

Hello everyone, first post from a newbie-user. Every question I google seems to bring me here and I always get a great answer to what I'm looking for; so naturally this was my first stop when I began pondering the usage of blessing in Perl. I've just gotten into Perl's OOP and just today read the post asking what bless does. I now under...

perl + return code 1 from perl script

hi friends in my little perl script (test.pl) I do the following in order to exit from program if EXIT_STATUS equal to 1 if ( $EXIT_STATUS == 1 ) { system (exit); } but I need also to get from the test.pl return code 1 for example ./test.pl echo $? how to enable return code 1 if EXIT_STATUS = 1 ? li...

How do I get the dirname of a file with Perl?

In my perl script, I have the param $FILE=/etc/sysconfig/network in which way (in perl) I can cut only the directory and put the directory in $DIR param in order to get $DIR=/etc/sysconfig (like dirname /etc/sysconfig/network in shell script) lidia ...

RegEx for finding words with NOT ONLY ONE space between them.

Hello. I need help with a RegEx problem: I want to find occurences of two known words ("foo" and "bar" for example), that have any white space other than EXACTLY ONE SPACE CHARACTER between them. In the text that I have to grep, there may be spaces, tabs, CRs, LFs or any combination of them between the two words. In RegEx words: I ne...

Perl File Handling.

Hello all, The below is the Perl script that I wrote today. This reads the content from one file and writes on the other file. It works but, not completely. #--------------------------------------------------------------------------- #!/usr/bin/perl open IFILE, "text3.txt" or die "File not found"; open OFILE, ">text4.txt" or die "Fil...

Designing a perl script with multithreading and data sharing between threads

I'm writing a perl script to run some kind of a pipeline. I start by reading a JSON file with a bunch of parameters in it. I then do some work - mainly building some data structures needed later and calling external programs that generate some output files I keep references to. I usually use a subroutine for each of these steps. Each s...

perl + append text between two lines in file

hi all I need to edit file , the main issue is to append text between two known lines in the file for example I need to append the following text a b c d e f 1 2 3 4 5 6 bla bla Between the first_line and the second_line first_line=")" second_line="NIC Hr_Nic (" remark: first_line and second_line argument can get any line or s...

ls -ltr in perl

I want to replicate ls -ltr unix command in perl script without using backticks, exec or system. Following script is working: use strict; my $dir="/abc/xyz/log"; opendir(DIR, $dir) or die "Can not open $dir $!"; my @latest = (sort {-M $b <=> -M $a} <$dir/*>); my @latest2= grep { !/^\./ && -f "$_"} @latest; closedir DIR; Question: How ...

How to reload the configuration in catalyst

How to reload the configuration when ever the configuration changed in catalyst web framework and need to reload the configuration with out restarting the catalyst server. ...

Regex Group in Perl: how to capture elements into array from regex group that matches unknown number of/multiple/variable occurrences from a string?

In Perl, how can I use one regex grouping to capture more than one occurrence that matches it, into several array elements? For example, for a string: var1=100 var2=90 var5=hello var3="a, b, c" var7=test var3=hello to process this with code: $string = "var1=100 var2=90 var5=hello var3=\"a, b, c\" var7=test var3=hello"; my @ar...

Do Perl subclasses inherit imported modules and pragmas?

Lets say you have a parent Perl class in one file: #!/usr/bin/perl package Foo; use strict; use warnings; use Data::Dumper; sub new{ my $class = shift; my %self = (); return bless %self, $class; } 1; and a subclass in a different file: #!/usr/bin/perl package Bar; use base "Foo"; 1; Will the subclass inherit the use s...