perl

Simple Perl Regex parser

Hey, I am working on a very basic parser. I am almost certain that my regex is correct, but values do not seem to be being stored in my $1 and $2. Am I doing something wrong? I am just looking for tips to alter my code. Thanks for any advice! Also, I am new to Perl, so if I did something wrong, I am looking to get off on the right foot a...

Perl: avoid greedy reading from stdin?

Consider the following perl script (read.pl): my $line = <STDIN>; print "Perl read: $line"; print "And here's what cat gets: ", `cat -`; If this script is executed from the command line, it will get the first line of input, while cat gets everything else until the end of input (^D is pressed). However, things are different when the i...

How can I write a Perl script to automatically take screenshots?

I want a platform independent utility to take screenshots (not just within the browser). The utility would be able to take screenshots after fixed intervals of time and be easily configurable by the user in terms of time between successive shots, the format the shots are stored, till when (time, event) should the script run, etc Sin...

Why can't I install Perl's File::Find::Rule?

perl -MCPAN -e'install File::Find::Rule' CPAN: Storable loaded ok Going to read /root/.cpan/Metadata Database was generated on Mon, 13 Sep 2010 08:41:13 GMT Running install for module File::Find::Rule Running make for R/RC/RCLAMP/File-Find-Rule-0.32.tar.gz CPAN: Digest::MD5 loaded ok Checksum for /root/.cpan/sources/authors/id/R/RC/RCL...

How can I represent sets in Perl?

I would like to represent a set in Perl. What I usually do is using a hash with some dummy value, e.g.: my %hash=(); $hash{"element1"}=1; $hash{"element5"}=1; Then use if (defined %hash{$element_name)) to decide whether an element is in the set. Is this a common practice? Any suggestions on improving this? Also, should I use defined...

How can I check if a key exists in a deep Perl hash?

If I understand correctly, calling if (exists $ref->{A}->{B}->{$key}) { ... } will spring into existence $ref->{A} and $ref->{A}->{B} even if they did not exist prior to the if! This seems highly unwanted. So how should I check if a "deep" hash key exists? ...

How do I maintain the order of values in an XML file with I read it with XML::Simple?

I am using XML::Simple for parsing a XML file. Code is given below with XML file, use Tie::IxHash; tie %$data, "Tie::IxHash"; use XML::Simple; use Data::Dumper; $xml = new XML::Simple; $data = $xml->XMLin("ship_order.xml"); print Dumper($data); XML file, (ship_order.xml) <?xml version="1.0" encoding="UTF-8" ?> <shipment> <sh...

How can I maintain a list of mail recipients in my Perl script?

My Perl script to monitor a directory on Unix, stores a list of users to whom a notification mail is sent when the directory it is monitoring is updated. This is the construct used dirmon.pl my $subject = '...'; my $msg = '...'; my $sendto = '[email protected] [email protected] [email protected]'; my $owner = '[email protected]'; ... ...

how to modify this perl code to get right information from .xls files

I want to modify this code with these conditions : input a date, and notify all events will come in next three or four... days. plz help me :( #!/usr/bin/perl -w use strict; use Spreadsheet::ParseExcel; my $oExcel = new Spreadsheet::ParseExcel; die "You must provide a filename to $0 to be parsed as an Excel file" unless @ARGV; my $o...

Perl: Threading with shared multi-dimensional hash

I am trying to share a multi-dimensional hash over multiple threads. This hash holds 2 connected key-pairs, I need to know if they are already connected, if they are not, I need to connect them, if not, there is no need to go to the database. use threads; use threads::shared; my %FLUobject2param : shared = (); #Start a new thread f...

Is there documentation for writing tests (and building) with Module::Build?

So I've made a few modules for my own use, and I'm wondering if there is any documentation about how to write tests for perl modules using Module::Build. The specific problem I'm running into is that I've got three modules, HomeBrew::IO, HomeBrew::Stats, and HomeBrew::Bio, and I can't figure out how to build or test them separately th...

extract all links from a HTML page, exclude links from a specific table

Hi experts, I'm pretty new to Perl/HTML. Here is what I'm trying to do with WWW::Mechanize and HTML::TreeBuilder: For each chemical element page on Wikipedia, I need to extract all hyperlinks that point to the other chemical elements' pages on wiki and print each unique pair in this format: Atomic_Number1 (Chemical Element Title1) -> ...

How can I print a Perl hash in specific order?

I have this code #!/usr/bin/perl use strict; my @a = ("b","a","d","c"); my %h = ("a",1,"b",2,"c",3,"d",4); #print '"' . join('","', @a), "\"\n"; print "\n"; foreach my $key (@a) { print '"' . $h{$key} . '",'; } print "\n"; that outputs "2","1","4","3", but I would like that it just outputted "2","1","4","3" Notice that la...

Perl: Iterating through this funky array?

I'm trying to iterate over a 2D array that is structured in this specific way. Whether or not this is a good way to structure the array is another question - I still need to be able to iterate over it (if it is possible). @row1 = ( "Current Scan", "Last Month"); @row2 = ( "240", "0"); @row3 = ( "226", "209"); @row4 = ( "215", "207"); ...

How do I get the length of a Perl Unicode string input via Ajax or CGI?

Okay, this should be really simple, but I have searched all over for the answer and also read the following thread: http://stackoverflow.com/questions/1326539/finding-the-length-of-a-unicode-string-in-perl It does not help me. I know how to get Perl to treat a string constant as UTF-8 and return the right number of chars (instead of byt...

Is there a way to overload the regex binding operator `=~` in Perl?

I am working on a small DSL that uses the nomethod fallback for overloading to capture the operators used on the overloaded values. This is similar to the function of the symbolic calculator described in overload's documentation. This works fine for the standard comparison operators, but consider the following: my $ret = $overloaded =...

How can I repeat the menu bar on every page from a Perl CGI program?

I have a page named Main.cgi where in I have a horizontal menu bar with UserList logs and so on like the Menu above Questions Tags Users etc. Whenever I click the Userlist I get navigated to another page where I have a grid. In this page also I want that Menu bar which was in Main.cgi, and so on. It should get repeated to every page. ...

Encoding issue in the web page

Hi , There is an encoding issue in the web page means it showing some special characters in the browser(Cinéma). content is in ISO, web page is rendering in UTF-8. some articles are displaying properly,bcz those are in UTF encode.some of the articles are shows the encoding issue like Cinéma in Perl 5. Can any once help me out for t...

How can I filter the records from an SQLite database in my Perl CGI script?

Here is the table in which ia am retrieving the data from sqlite,, at the top of this datagrid i need a filter button and 2 text boxes..1 for userId and 1 for userName...All i need is tha as a enter the userid and username the record confined to tha id or name should appear ...Please do help me..am newbie to perl... #!C:\perl\bin\perl...

How can I quote a long string in Perl?

I usually use simple quotes, but sometime I get very long lines which I can't break and also need to use escape characters, so I get something like this: my $str = "select query_accession,query_tag,hit_accession,hit_tag,significance from summaryTables where query_id = \'$query_id\';" I know there are various other ways for representin...