perl

How to extract a particular column of data in Perl?

I have some data from a unix commandline call 1 ab 45 1234 2 abc 5 4 yy 999 2 3 987 11 I'll use the system() function for the call. How can I extract the second column of data into an array in Perl? Also, the array size has to be dependent on the number of rows that I have (it will not necessarily be 4). I want the array to h...

Calling perl module from current directory

I need to test a perl script in a remote server. I tried running it but i got the error Can't locate Date/Manip.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.10.0 /usr/local/share/perl/5.10.0 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl . So I downloaded the DateManip.p...

How to sort numbers in Perl?

print "@_\n"; 4109 4121 6823 12967 12971 14003 20186 How do I sort it in Perl? Using @sorted = sort(@_); gives me an alphabetical ordering 13041 13045 14003 20186 4109 4121 6823 How do I get a numerical ordering? Does Perl have built-in functions for merge-sort, insertion-sort etc.? ...

Warning - "Odd number of elements in hash assignment" in perl

I am getting the warning with use of following syntax - my %data_variables = ("Sno." => (5,0), "ID" => (20,1), "DBA" => (50,2), "Address" => (80,3), "Certificate" => (170,4), ); But I dont get a similar warning at use of similar syntax. my %patterns = ("ID...

Insert BLOB into MS SQL DB using Perl script

Hi all, Please excuse my ignorance of Perl, as I'm a .NET developer (I can hear you all spitting and cursing already ;¬) ) We have a requirment to insert a BLOB (+ some other data) to an MS-SQL DB using a Perl script (our backend systems run on AIX using Perl scripts to go about thier daily business). Our Perl guy, seemingly, ran int...

send data from c to perl

hi for a project i need to send some data from c program to Perl program that both in running mode (Perl program in sleep mode and c program running, and c program sends data to Perl). i know that, can write this program by socket and shared memory but i have performance problem. i think shared memory is better solution, and how can i ...

How to extract a number from a string in Perl?

I have print $str; abcd*%1234$sdfsd..#d The string would always have only one continuous stretch of numbers, like 1234 in this case. Rest all will be either alphabets or other special characters. How can I extract the number (1234 in this case) and store it back in str? This page suggests that I should use \d, but how? ...

What compile time features does Perl provide that other languages don't?

Is Perl considered a general purpose programming language? Reading about it on Wikipedia Perl has a Turing-complete grammar because parsing can be affected by run-time code executed during the compile phase.[41] Therefore, Perl cannot be parsed by a straight Lex/Yacc lexer/parser combination. Instead, the interpreter implements its ...

How do I get the entire inner content of an XML node including element tags?

Using XML::Twig, is there a way to get the entire HTML of a node? I do not want the text of the node, but the entire HTML with tags and all. input XML <content> <p>blah blah <b> bla bla </b> </p> <p> line 2 <i> test </i? </p> </content> Code my $twig = new XML::Twig( TwigRoots => {'content' => 1}, TwigHandlers => $twig_ha...

Is there something like `last` for `map`?

In Perl, is it possible to arbitrarily end a map execution, e.g. something equivalent to last in a loop? It would be a bit like this: map { if (test == true) { last; } dosomething } @myarray ...

What are the Perl equivalents of return and continue keywords in C?

I am getting this error when I use this code sub search { my ($a, @a_list) = @_; foreach (@a_list) { if($_ == $a) return TRUE; # continue; } return FALSE; } syntax error at code.pl line 26, near ") return" What is the right way to return TRUE? Also, what is the right way to continue? I know I sh...

Reverse Engineering a Perl script based on a core dump

A friend's server (yes, really. Not mine.) was broken into and we discovered a perl binary running some bot code. We could not find the script itself (probably eval'ed as received over the network), but we managed to create a core dump of the perl process. Running strings on the core gave us some hints (hostnames, usernames / passwords)...

How should I restructure a large Perl script?

Hi there. I have a more or less large Perl script of ~ 1000 lines. The script accepts a few arguments and it runs straight forward. No modules, no functions. The script could be divided into three parts, initialization part, arguments parsing part and work part, but I don't know how to do that. Everything must be kept in a single file. P...

Why can't my CPAN client from MacPorts find Module::Build?

I am using the macports in snow leopard. I wanted to install certain perl modules to be able to run a script. The DateTime module to be exact. How do I do this? I tried using the following command. perl -MCPAN -e shell cpan > install DateTime But it still says that DateTime.pm not found. What have I done wrong? Edit: I think I have ...

How to read from a file and do a grep in Perl?

open(MR, "<path_to_report"); $rid; The file might be very big in size. It has a unique line inside it in the following format Root identifier: <some number> for example Root identifier: 12987 I need to extract 12987 to $rid. How can I do that in Perl? ...

Regular Expression -

Is it possible to find all text inside a node and take the matched text and replace the contents of a node using only a single regular expression? I should say that this is in a file. Given: <x>This text</x> <!-- Unknown number of nodes between <x> and <y> --> <y>Junk</y> Change to: <x>This text</x> <!-- Unknown number of nodes b...

using idioms in vim for perl

I have the perl-support plugin enabled. now, I tried the \idd idiom shortcut which would give you a my ($,$); statement with the cursor placed on the first var. Now the second var is displayed as <+name+>. In effect the my line after entering the first variables name would be my ( $top, $<+name+> ); If it was a code snippet I could ...

how to use Net::SSH::Perl with public keys?

I'm trying to use Net::SSH::Perl to connect using public keys with this code: my $ssh = Net::SSH::Perl->new($host, debug=>1) || die ...... I put the key in /root/.ssh/id_rsa and /root/.ssh/identity It seems that it's not trying to use the public key and instead trying to ask for a password: I get this output: localhost: Sent ke...

Run a perl script on web site page load

I have a page that when loaded I would like it to run a perl script. Is this possible to do with javascript? I have never ran a perl script on the web before and the only way I have seen to do it is link to it. ...

How can i access variables outside a for loop in perl

I want to access $hash_element->{'test_plan'} and $hash_element->{'build'} outside the for loop my $hash_element; for $hash_element (@bats) { my $dbh = DBI->connect( $dsn, $BAT_DB_user, $BAT_DB_password ); my ( @plan_id, @plan_run ); @plan_id = $dbh->selectrow_array( "select id from plan where name='$hash_elem...