perl

How do I hook into an event triggered once a MySQL query is true?

How does one create a PHP script that checks the MySQL row consistently and if a set query is matched, it starts an event, such as sending an email? For example, on query match Fire start email: To: [email protected] From: [email protected] Subject: Set query met, auto email complete. It would be around MySQL5. I'm stuck on this. Am I best to ...

Vim ex knowing number typed before

I'm making a shortcut that places a # at the front of each line, in the next x lines. x is a number I type before entering the shortcut, like typing 11dd deletes the next eleven lines. The command is .,+10 s/^/#/g. Here the number ten should really be whatever was typed before the shortcut. How do I make the shortcut change according to...

How to have variable as regex in perl

I think this question is repeated but searching wasn't helpful for me. my $pattern = "javascript:window.open\('([^']+)'\);"; $mech->content =~ m/($pattern)/; print $1; I want to have an external $pattern in the RegEx. How can I do this? The current one returns: Use of uninitialized value $1 in print at main.pm line 20. ...

Problems reading a binary file with ActivePerl?

I'm trying to read a binary file with the following code: open(F, "<$file") || die "Can't read $file: $!\n"; binmode(F); $data = <F>; close F; open (D,">debug.txt"); binmode(D); print D $data; close D; The input file is 16M; the debug.txt is only about 400k. When I look at debug.txt in emacs, the last two chars are ^A^C (SOH and ETX...

How to search and replace in text files only?

I have a directory containing a bunch of files, some text some binary, with no consistent naming. I want to search and replace a string in text files only. So I went with: perl -i -pne 's#/some/text/to/replace#/replacement/text#' * Remove the -i option and you will see that binary files get caught. How do I modify this one-liner to sk...

perl - how do you extract all elements of an array except the last?

I need to extract all elements in an array except the last and store them in a scalar for later use. At first, I thought this would be possible using array slices, but it appears that you cannot count backwards. For example: my $foo = ($bar[0..-2]); or my $foo = ($bar[-2..0]); Any help would be greatly appreciated as this i...

How do I print the average time taken to open a file for reading?

I am new to Perl and I have to do some automation at my work. I have to take a path to a directory containing multiple files and print the average time taken to read or open a particular file. Any help is very much appreciated. ...

Using the perl MooseX extention in silent mode?

I have perl 5.10.1 installed on my ubuntu machine. I wanted to install the Moose and MooseX extentions, so I did install the packages with the aptitude package manager. Here are all the packages I have installed: $ sudo apt-cache pkgnames | grep moose libmoosex-singleton-perl libmoosex-compiletime-traits-perl libmoosex-types-structured-...

How do I get yesterday's date using localtime?

How do I tweak this to get yesterday's date using localtime? use strict; sub spGetCurrentDateTime; print spGetCurrentDateTime; sub spGetCurrentDateTime { my ($sec, $min, $hour, $mday, $mon, $year) = localtime(); my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ); my $currentDateTime = sprintf "%s %02d %4d", $abbr[$mon], ...

Need help installing MooseX::Declare

I am running with Perl 5.10.1 installed using the package manager. I have successfully installed Moose from the CPAN shell, and I have tried to install the MooseX::Declare extention without success.. Here is what I have done: $ sudo cpan > cpan.log cpan[1]> install MooseX::Declare Cannot determine perl version info from lib/MooseX/...

Perl Script Portability and Future Proofing

Due to pressure from outside our group, we have to port over one hundred Perl scripts from Sparc to x86. This means changing dozens of shebang lines from #!/home/Perl/bin/perl -w to something else, which is a real pain. What is good way to do this (I can't find anything on Lycos)? Also what happens when we're forced to move from x86 to...

Need to compare values in a file where 1st column repeats

So my data sample is in the following format. jgi|Xentr4|100164|gw1.1441.2.1 scaffold_1441 18150 18354 jgi|Xentr4|100164|gw1.1441.2.1 scaffold_1441 19856 19974 jgi|Xentr4|100164|gw1.1441.2.1 scaffold_1441 21455 21638 jgi|Xentr4|100164|gw1.1441.2.1 scaffold_1441 21727 21897 jgi|Xentr4|100164|gw1.1441.2.1 scaffold_144...

Perl: Why does this create thousdands of child processes?

So when I run this code it seems to fork bomb the system can you guys help me out? All I want to do is start a thread for each one of the appWatch domains and enviroments. #!/usr/bin/perl # # # Starts the mass processes to watch each directory & enviroment. # # # ##################################################################...

Autoincrementing letters in Perl

Hey guys, I do not understand autoincrementing letters in Perl. This example seems perfectly understandable: $a = 'bz'; ++$a; ca #output b gets incremented to c. There is nothing left for z to go to, so it goes back to a (or at least this is how I see the process). But then I come across statements like this: $a = 'Zz'; ++$a; AAa #...

How to Capture STDOUT in a variable

I am calling a function that writes to STDOUT using print. How can I capture this in a variable? Note that all this happens within the same process ...

HTML::Element -> Replace text node with new HTML::Element

How to replace a text node with new <p>test</p> in HTML::Element? Thanks in advance. ...

How to set our variable $walkHandle in B::Concise

In my function I am doing this my $output; open (MEM, '>', \$output or die "Can't open MEM: $!"); $B::Concise::walkHandle = \*MEM; But I get the error Not a GLOB reference at C:/Perl/lib/mycrap.pm line 157. CHECK failed--call queue aborted. What should I do ...

How to support the searching file based on regular expression

From here #!/usr/bin/perl my @arr = ('/usr/test/test-[\d.*].*.con'); How to support the searching file based on regular expression ...

Using Test::MockDBI multiple times with different results

Hi, I'm trying to test some code in different situations (for different result sets). I've got the first test running well, but the next one is trying to reuse the first "table". My result sets: my $usernames_many = [ { username => '1234567' }, { username => '2345678' }, ]; my $usernames_empty = [ ]; but now when I ...

problem passing 0 as command-line argument

I've just noticed a strange behavior of perl5 (5.10.0) when I passed 0 as the command-line argument to a script, which assigns it to a variable. The problem I encountered is that if I give the variable a default value in my script which is greater than 0, say 1, then I can pass any value except 0 to override the default value 1. Follo...