perl

How many random strings does this code generate?

I am considering this random string generator in perl: sub generate_random_string { my $length = 12; my @chars = qw/2 3 4 5 6 7 8 9 A B C D E F G H J K M N P Q R S T U V W X Y Z/; my $str = ''; $str .= $chars[int rand @chars] for 1..$length; return $str; } How many unique strings will this generate? If I extend th...

Why do I get this module error: "Can't locate Error.pm in @INC"?

I tried running: perl -e "use Error;" from cmd in windows 7. (active perl 5.12 installed on system) and I am getting the error Can't locate Error.pm in @INC (@INC contains: C:/Perl64/site/lib C:/Perl64/lib ) I manually searched and found Error.pm in C:/Perl64/lib/CPANPLUS. Does anyone have an idea what could be going o...

how to use a shell script to supervise a program?

I've searched around but haven't quite found what I'm looking for. In a nutshell I have created a bash script to run in a infinite while loop, sleeping and checking if a process is running. The only problem is even if the process is running, it says it is not and opens another instance. I know I should check by process name and not pr...

Unicode in Perl not working

I have some text files which I am trying to transform with a Perl script on Windows. The text files look normal in Notepad+, but all the regexes in my script were failing to match. Then I noticed that when I open the text files in NotePad+, the status bar says "UCS-2 Little Endia" (sic). I am assuming this corresponds to the encoding U...

Windows equivalent of perl modules required (not available in activestate ppm) such as file::finder

Hi All, I'm attempting to import code written in linux into eclipse's perl plugin 'epic', and have installed activestate perl in windows. Most of the modules have an activestate equivalent, but some of them I can't find in ppm. Does anyone know how I can get the following modules so that the code can compile? File::Finder Spread...

Is pushing a variable onto an array a threadsafe operation?

I have the following Perl code: push(@myArray, $myValue); Is the operation atomic, or will I need to use locks, if multiple threads will be performing this same operation on many threads? ...

Perl AJAX stripping html characters out of string!!?!

I have a Perl program that is reading html tags from a text file. (im pretty sure this is working because when i run the perl program on the command line it prints out the HTML like it should be.) I then pass that "html" to the web page as the return to an ajax request. I then use innerHTML to stick that string into a div. Heres the pr...

Is NET::SCP uses multiple connections to transfer multiple files ?

HI, Actually i am trying to reduce the time taken to transfer N-number of files from remote machine local machine using secure file transfer, previously i used scp system command it establishes a connection for each file transfer. Thanks in advance. ...

Calling child class method from Base Class in Perl

I have module called Mobile::Auth to authorize and redirect to the login page. I wanted to access all methods from Site::Auth in my Mobile::Auth except a method '*redirect_to_login_page*', which I have specific one for my Mobile::Auth. I did something like this.. package Mobile:Auth; use base Site::Auth; sub redirect_to_login_page{ #g...

perl code for identify usb events on windows

Could someone provide snippet/links for perl code for identification usb events (plug and unplug) on windows. ...

Perl function knowing receiver type

I have a text file, and a function to retrieve from that text file: @thefile = read_file( 'somepathfile' ); I would like to have a different implementation of the read_file function depending on which type is receiving the information. So if I write: %thefile = read_file( 'somepathfile' ); then a different function will be execute...

Vim Perl autocomplete displaying a given modules functions

Is it possible to have Vim autocomplete show which functions are available to a given module? So if I include a module called math and then go: math:: and at that i could get a list of the functions available through that module. ...

How to parse the same element of multiple files at the same time in Perl

I want to merge several xml files in perl. Each file is composed of a lot of elements; I need to merge data with the same element from these files. e.g. file1 has elements {e1, e2, e4} file2 has elements {e1, e3, e4} file3 has elements {e2, e4, e5} so I need to merge e1 of file1 with e1 of file2, merge e2 of file1 and e2 of file3, e...

I need help compensating for the shifting of images when trying to create a grid with one image and apply it on another.

Hi I have two images of yeast plates: Permissive: Xgal: The to images should be in the same spot and roughly the same size. I am trying to use one of the images to generate a grid and then apply that grid to the other image. The grid is made by looking at the colonies on permissive plate, the plate should have 1536 colonies on it....

Different architectures in the same or different directory trees?

At $work, we maintain a set of Perl modules at a central location for easy inclusion via PERL5LIB. As there is a re-installation ahead and we need to provide the modules for both 32 and 64 bit architecture, we are wondering if it's better to install them into the same directory tree, relying on the $archname subdirectories, or keep the t...

java equivalent of Perl Crypt::CBC

use Crypt::CBC; my $crypt = Crypt::CBC->new(-key => "password", -cipher => "Crypt::Blowfish"); print $crypt->encrypt_hex('s'); How do I get the same result using java? Thanks in Advance. ...

taint-mode perl: preserve suid when running external program via system()

I'm trying to add a feature to a legacy script. The script is suid, and uses perl -T (taint mode: man perlsec), for extra security. The feature I need to add is implemented in Python. My problem is that I can't convince perlsec to preserve the suid permissions, no matter how much I launder the environment and my command lines. This is...

can't write to file using print

#!/usr/bin/perl use strict; use warnings; open(my $vmstat, "/usr/bin/vmstat 1 2>&1 |"); open(my $foo, ">", "foo.txt") or die "can't open it for write"; while(<$vmstat>) { print "get ouput from vmstat and print it to foo.txt ...\n"; print $foo $_; } when I run the above code, nothing wrong happend.but after I press ctr-c to qui...

How can I rewrite the text parts of HTML using HTML::Parser without altering the <script> and <head> sections?

The following code is a shortened version of an example from HTML::Parser #!/usr/bin/perl -w use strict; my $code = shift || usage(); sub edit_print { local $_ = shift; tr/a-z/n-za-m/; print } use HTML::Parser 3.05; my $p = HTML::Parser->new(unbroken_text => 1, default_h => [ sub { print @_; }, "text" ], text_h => [ \&edit...

What does this Perl function do?

I am just trying to learn some Perl, so I am going through one function just to get grip on the language. Could somebody explain to me what this function is doing exactly? #! /usr/bin/perl use strict; my %hash; &Parse('first.txt'); &Parse('second.txt'); my $outputpath = 'output.txt'; unlink ($outputpath); open (OUTPUT, ">>$out...