perl

How can I copy files with special characters in their names with Perl's File::Copy?

I am trying to copy all files in one location to a different location and am using the File::Copy module and copy command from that, but now the issue I am facing is that I have file whose name has special character whose ascii value is &#253 but in unix file system it is stored as ? and so my question is that will copy or move command c...

How can I determine if a value is in a Perl array?

I'm using this small snippet to determine whether or not a URL is currently being stored in an array: if( $self->{_local} eq "true" && ! grep {m|^$new_href?$|} @m_href_array ) { push( @m_href_array, $new_href ); push( @href_array, $new_href ); } It seems to work but then my code throws an error saying: Sequence (?$...) not im...

Calling Java .jar Program from Perl using System()

The title pretty much says it all, I am trying to get a java program (.jar file) to run from a Perl program. I read another post on Stackoverflow saying this syntax is correct: system("java filename.jar"); However this is giving me the following error. I'm not sure if the problem is that it shows the filename as "filename/jar" inste...

How I can calculate the broadcast IP from an IP address and netmask in Perl?

Does someone have example in Perl of how I can calculate the broadcast IP from an IP address and netmask? ...

How can I parse this syntax to an array in Perl?

I have a file that contains parameters using this syntax RANGE {<value> | <value>-<value>} [ , ...] where value s are numbers. for example, all these are valid syntax RANGE 34 RANGE 45, 234 RANGE 2-99 RANGE 3-7, 15, 16, 2, 54 How can I parse the values to an array in Perl? For example for the last example, I want my array to have...

Perl - If table does not exist

I'm currently using the following which works but throws an error every time the table is created (as it is first trying to insert into a db which does not exist and returning false). $result = $dbh->prepare("INSERT INTO `". $host ."` (URL) VALUES ('$href')"); if( ! $result->execute() ){ $result = $dbh->prepare("CREATE TABLE `" . $h...

How can I recover from a timeout with Perl's WWW::Mechanize?

I'm using WWW::Nechanize to read a particular webpage in a loop that runs every few seconds. Occasionally, the 'GET' times out and the script stops running. How can I recover from one such timeout such that it continues the loop and tries the 'GET' the next time around? ...

How can I extract child values from XML with Perl's XML::Twig?

I am parsing the XML file and trying to access the values in XML file. #!/usr/bin/perl -w use strict; use XML::Twig; my $file = 'files/camelids.xml'; print "File :: $file\n"; my $twig = XML::Twig->new(); $twig->parsefile($file); # print "twig :: $twig\n"; my $root = $twig->root; # print "root :: $root\n"; my $num = $root->children(...

How can I check if a value is undef in Perl?

Best asked by an example: my $var1=1; my $var2; my $var3=3; # say "at least one undef" if at least one of $var1, $var2, $var3 is undef Obviously I can explicitly loop and do that, but I always like to find one liners that achieve the same result. ...

How can I make my Perl web crawler go faster?

I've been knocking up a little pet project the last two days which consists of making a crawler in Perl. I have no real experience in Perl (only what I have learned in the past two days). My script is as follows: ACTC.pm: #!/usr/bin/perl use strict; use URI; use URI::http; use File::Basename; use DBI; use HTML::Parser; use LWP::Simple...

How do I insert a line in a file to the beginning of a file in Perl?

I used a Perl helper to code this. It looks I am missing a character or something. I need to write the new text to the top of the text file. open (LOGFILE, ">> complete.txt") ; # writes new to the bottom $datetime = localtime ; print LOGFILE "\n" ; print LOGFILE $datetime\n" ; print LOGFILE "$name\n" ; print LOGFILE "Has completed th...

How can I open a Windows CMD window for Perl and run a command?

Is there a way I can open a new cmd window and pass a variable and once completed close that window? I have found some info but not enough that I can get it to work. system('start "List Perl files" dir c:/dfd/dfdf.pl /B'); Opens window but does not run script. ...

How can I handle Javascript in a Perl web crawler?

I would like to crawl a website, the problem is, that its full of JavaScript things, such as buttons and such that when they are pressed, they do not change the URL, but the data on the page is changed. Usually I use LWP / Mechanize etc to crawl sites, but neither support JavaScript. any idea? ...

How can I complete the process in Win32 on behalf of the process in Perl?

For example, to have rschit process excell.exe means Perl. ...

Ordering of columns in where clause when using SQL::Abstract

I have been reading some recipes in the Perl Hacks book. Recipe #24 "Query Databases Dynamically without SQL" looked interesting. The idea is to use SQL-Abstract to generate the SQL statement for you. The syntax to generate a select statement looks something like this: my($stmt, @bind) = $sql->select($table, \@fields, \%where, \@order...

How can I stop Perl's Mail::Box::Manager from removing directories?

I'm using the Perl module Mail::Box::Manager to read messages from a Maildir and move them into another directory. Once the script has finishing processing the mail messages in the Maildir it appears to also remove the cur/ and new/ Maildir directories and the Maildir files/directories need to be recreated. I don't want the script remo...

How can I extract values from an XML file with Perl's XML::Simple?

Considering that XML::Simple is the only module which can be used, I am stuck in retrieving the values from an XML. The structure goes below: <testxml> <dev> <A> <tables> <datatables> <table>a1</table> <table>a2</table> <table>a3</table> ...

What does this Perl regex mean: m/(.*?):(.*?)$/g ?

I am editing a Perl file, but I don't understand this regexp comparison. Can someone please explain it to me? if ($lines =~ m/(.*?):(.*?)$/g) { } .. What happens here? $lines is a line from a text file. ...

How can I substitute one substring for another in Perl?

I have a file and a list of string pairs which I get from another file. I need substitute the first string of the pair with the second one, and do this for each pair. Is there more efficient/simple way to do this (using Perl, grep, sed or other), then running a separate regexp substitution for each pair of values? ...

How can I list all files in a directory using Perl?

I usually use something like my $dir="/path/to/dir"; opendir(DIR, $dir) or die "can't open $dir: $!"; my @files = readdir DIR; closedir DIR; or sometimes I use glob, but anyway, I always need to add a line or two to filter out . and .. which is quite annoying. How do you usually go about this common task? ...