perl

perl pattern match Downloaded: 1 files, 8.7K in 0s (16.9 MB/s)

I have the following string "Downloaded: 1 files, 8.7K in 0s (16.9 MB/s)" which I got from wget and want to pattern match it by making a regular expression of it. I tried with: /^Downloaded: ([0-9]*) files, ([0-9GK]*) in ([0-9.]*)s ([0-9.]) [KM]B\/s/ But it does not work. I would appreciate any help. Thanks! ...

How can I save an XML DOM tree to a new document using Perl's XML::LibXML?

I write the following (DOM) Perl script (shown below) in order to create the following XML DOM: <books> <computer/> </books> How can I save the XML output into test.xml file? I tried to save the XML with $doc->printToFile('/tmp/test.xml'); but I get: can't locate object method "printToFile" via package "XML::LibXML::Document"...

directory input sanitation

I have a very simple perl script that moves files (don't ask why i cant use cp, its long, sad, and will make you cry). I take 2 inputs from command line, dir1 and dir2. Then i have an internal file list i pull and concatenate the two together. my $file = dir1 . filename That works great as long as the user puts a traling / on their d...

Saving a file with WWW::Selenium

Im trying to download a file with perl's WWW::Selenium. I get a popup box asking me if I want to save/open the file. I want to manipulate it and say 'save' at some given location. Im not sure how this can be done. Please help. P.S: I could not use WWW::Mechanize for this page and I have to use Selenium Thanks a lot! ...

How do i remove "new line" from a command that ends in | wc -l in perl

ps efax 2>/dev/null|grep firstbo|grep -v grep|wc -l if i store this as a scalar, then, the scalar contains a new line, how do i remove the new line ...

"Copy failed: File too large" error in perl

Ok so i have 6.5 Million images in a folder and I need to get them moved asap. I will be moving them into their own folder structure but first I must get them moved off this server. I tried rsync and cp and all sorts of other tools but they always end up erroring out. So i wrote a perl script to pull the information in a more direct met...

Copying a string(passed as command line arguments to Perl) into text file

I have a string containing lots of text with white-spaces like: String str = "abc xyz def"; I am now passing this string as a command line argument to a perl file using C# as in: Process p = new Process(); p.StartInfo.FileName = "c:\\perl\\bin\\perl.exe"; p.StartInfo.Arguments = "c:\\root\\run_cmd.pl " + str + " " + text_file; In t...

Matching double char delimited strings with regular expressions

Suppose you want to match text that is delimited by double characters like so: a = << Hello World! >> The regular expression /<<(.*)>>/ would seem to do it, but unfortunately when these can be repeated greedy matching gets too much: a = << Hello World! >> b = << Goodbye World! >> The previous regexp will capture Hello World! >> ...

How to eliminate Perl rounding errors

Consider the following program: $x=12345678901.234567000; $y=($x-int($x))*1000000000; printf("%f:%f\n",$x,$y); Here's what is prints: 12345678901.234568:234567642.211914 I was expecting: 12345678901.234567:234567000 This appears to be some sort of rounding issue in Perl. How could I change it to get 234567000 instead? Did I do som...

Perl Programming and Distribution...

Hi all, I'm very new to Perl programming. I've just finished reading the Llama book. Up until now I have scripted in Bash, but I'm wanting to try out Perl and it's benefits over Bash scripting. I'm creating a script that uses a number of standard modules (e.g. Getopt) and some not-so-standard modules (e.g. PerlMagick) At some point I ...

perl open file error handling

I want to do some task when the file is not opened in the Perl program below. But when I run it, I am getting syntax errors. What's wrong with it? my $LOGPATH = $ENV{DATA_OU}; my $LOGFILE = "cdj_rep" . "." . "test" . ".rpt"; if ! (open(OUT,">$LOGPATH/test1/work/$LOGFILE")) { print "testin"; return; } close(OUT); ...

Posting parameter with Proxy (perl)

my question maybe obscure but its very important for me . I have this perl code : my $ua = LWP::UserAgent->new(); my $req = POST 'http://example.com', [ phd => 'text' , go => 'submit']; $content = $ua->request($req)->as_string; print $content; i want send the parameter (phd => text , go => submit) with a http proxy . what am i goi...

High Performance Socket Server using Perl

Hi, i need to write a socket server using perl which will run on a 64bit linux (2.6x kernel). Is there a library to support IO Completion Ports and some equivalent on Linux? I need to listen to multiple ports. 8000-8100 is there a smart way doing this? The protocol has to use a length byte. What threading library do you recommend?...

code working fine on Perl 5.12.1 doesn't work on 5.10.0

I wrote some code (about 100 lines) that is working fine on version 5.12.1. Unfortunately my client is using version 5.10.0. So I tested the code on 5.10.0 and found it doesn't work! Where can I find a list of differences between 5.10 and 5.12? Edit: I think the best answer to the question of "Where can I find a list of differences ...

perl + DOM + use XML::LibXML + how to remove xml version title from XML file? with DOM

Hi all I create the following XML file, by perl script (Showing down) , using XML::LibXML: more test.xml <?xml version="1.0"?> <books> <computer/> </books> My question: how to remove "xml version title": <?xml version="1.0"?> from the test.xml file? With DOM commands in the perl script? in order to get only the fo...

Using the Perl split function, but keeping certain delimiters

I have a string that I need to split on a certain character. However, I only need to split the string on one of those characters when it is flanked by digits. That same character exists in other places in the string, but would be flanked by a letter -- at least on one side. I have tried to use the split function as follows (using "x" ...

How does Cron affect the Getopt::Long module?

I've written a wrapper program for mailx using perl that allows me to easily add attachments and do some other nifty things that were a little frustrating to accomplish with mailx. In the first few lines I have: use strict; use warnings; use Getopt::Long; my ( $to, $from, $subject, $attachments, $body, $file ) = (undef) x 7; GetOptio...

Removing array elements

Hi, how do I remove an element from a Perl array ref? I've got its index and I don't want to set the element to undef, but to remove it completely. For example, how do I change $a = [1, 2, 3]; into $a = [1, 3];. ...

Perl alarm working intermittently

I am currently working on a project that involves crawling certain websites. However sometimes my Perl program will get "stuck" on a website for some reason (can't figure out why) and the program will freeze for hours. To get around this I inserted some code to time out on the subroutine that crawls the webpage. The problem with this i...

How to use a variable as modifier in a substitution

Is there a way to use a variable as modifier in a substitution? my $search = 'looking'; my $replace = '"find: $1 ="'; my $modifier = 'ee'; s/$search/$replace/$modifier; I need to use an array of hashes to make bulk search-replace with different modifiers. ...