perl

How do you sort parrallel arrays in Perl?

Hi, I have a few arrays of the same length. I want to sort the first array, and make all the others array "sort" accordingly. For example, if the first array is (7,2,9) the second is ("seven","two","nine") and the third is ("VII","II","IX") after the sort (ascendingly according to the first array values) we will have (2,7,9) ("two","sev...

[SOLVED] Perl's tr/// is not doing what I want...

EDIT: tr/// does not support variable interpolation, so I went with s/\Q$_\E//g; instead Or, more likely, I'm not doing something right... I have the following code: #!/usr/bin/perl use strict; use warnings; use utf8; sub strip_invalid { my ($str, @chars) = @_; map { $str =~ tr/$_//; } @chars; return $str; } my @invalid = q...

copy a perl code in a another perl file

i want put this perl code in another perl file : my $ua = new LWP::UserAgent(agent => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.5) Gecko/20060719 Firefox/1.5.0.5'); for example : i want open UP.PL and this perl file copy the above perl code in another perl file (ex:send it into another.pl) what am i going to do ? T...

Writing perl6 Programs using Rakudo Star: Can't install on OS X

I'm trying to install Rakudo Star on OS X 10.6, and I've reached the always frustrating point where my build has failed and I'm not sure how to procede. Does anyone here know a way past this? (I'm trying to set this up to write some local perl6 programs, so I'm not sure if The Rules want this on Server Fault or on Stack Overflow, slap me...

improving Perl regex performance by adding +

I have some regexes in a Perl script that are correct but slow. I am considering trying to improve performance by adding extra + operators (ie *+ instead of * and ++ instead of +) to disable backtracking. I tried replacing all of them and the regexes stopped working... so much for the simple solution. How do I know where I can add the...

in XML:TWIG, how to stop parsing once find the interested element

I only want to parse an interested element of xml (e.g. see below: class element with name equals to math) and I want to stop once the first element hitting this condition is parsed. (since There is only one class whose name is math, it is unnecessary to continue once the element is already found). However, if I implement as follows, ...

Desktop software development (possibly using web technology) and cryptographic checks

OK, go easy on me as it's my first question here. ;) I am experienced in Web Application development, but I need to design 2 different desktop applications at work. I need advice on what languages to use (I use PHP for Web Applications, I have little other experience), any frameworks that may help me accomplish this easier and any IDEs ...

Can XML::Twig start parsing an XML file from a given line number?

I need to parse several large size XML files (one is ~8GB, others are ~4MB each) and merge them. Since both SAX and Tie::File are not suitable due to memory and time issues, I decided to try Twig. Suppose each XML file is composed of several elements as follows: <class name=math> <student>luke1</student> ... (a very very long...

How do I delete an element from an XML file after it is parsed?

Suppose the XML file is: <class name=math> <student>luke1</student> ... <student>luke8000000</student> </class> <class name=english> <student>mary1</student> ... <student>mary1000000</student> </class> after class=math is parsed, I want to delete this element from the XML file so that when class=english is parsed, Twig will not go thr...

Distributing a Perl Application

I recently created a little Perl application that utilizes a few non-core modules that will need to be installed via CPAN. Is there a way to distribute the application with the ability to check to see if the required modules are installed and pull them from CPAN if they aren't? I suppose I am looking for something similar to the CPAN au...

What are R's equivalents to Perl's map and grep?

I am interested in (functional) vector manipulation in R. Specifically, what are R's equivalents to Perl's map and grep? The following Perl script greps the even array elements and multiplies them by 2: @a1=(1..8); @a2 = map {$_ * 2} grep {$_ % 2 == 0} @a1; print join(" ", @a2) # 4 8 12 16 How can I do that in R? I got this far, us...

grep -v and -B|-A|-C not working together

I need to scan the output of iostat -En on a Solaris machine such that when a disk with errors is found, two lines about that disk are sent to the final output. This works fine so far using iostat -En | grep 'Errors: [1-9]' -A 1 but when I try to not include CD/DVD devices, I hit a wall. The contaxt flags (-A|B|C) don't seem to work w...

How do I calculate a DateTime difference in Perl?

use DateTime ; my $date = "2010-08-02 09:10:08"; my $dt = DateTime->now( time_zone => 'local' )->set_time_zone('floating'); print $dt->subtract_datetime($date); It's not working; what is the problem? The error message is: Can't call method "time_zone" without a package or object reference at /opt/perl/perl5.12/lib/site_perl/5.12....

How can I "look behind" the bash command line argument expansion?

I want a Perl script to accept wildcards (foo-*.ba?) for file names (which are then processed for a whole directory subtree). Of course, I can tell the users of my script to quote the argument ('foo-*.ba?'), but this is not really elegant - the wildcard method is meant as a user-friendly alternative to passing regexes (which are accepte...

Extracting Width/Height Dimensions from EMF Image Files

I maintain a small Perl library that extracts width/height from images, for people who want that functionality without using a larger, more generalized library. I've been asked if I can support the Windows EMF format. However, I haven't had much luck with my Google-fu in trying to find a good specification of the format, or better yet ex...

Use curl to parse XML, get an image's URL and download it

Hello! I want to write a shell script to get an image from an rss feed. Right now I have: curl http://foo.com/rss.xml | grep -E '<img src="http://www.foo.com/full/' | head -1 | sed -e 's/<img src="//' -e 's/" alt=""//' -e 's/width="400"//' -e 's/ height="400" \/>//' | sed 's/ //g' This I use to grab the first occurence of an image UR...

perl: iterate over a typeglob

Given a typeglob, how can I find which types are actually defined? In my application, we user PERL as a simple configuration format. I'd like to require() the user config file, then be able to see which variables are defined, as well as what types they are. Code: (questionable quality advisory) #!/usr/bin/env perl use strict; use war...

Why do I get this syntax error in my code generating program?

I want to generate some lines of Perl code by using file handling in Perl, for example: open(FILEHANDLE, ">ex.pl") or die "cannot open file for reading: $!"; print FILEHANDLE "use LWP::UserAgent;" .... .... some code is here .... print FILEHANDLE "my \$ua = new LWP::UserAgent(agent => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; r...

How do I turn Moose objects into JSON for use in Catalyst?

I have a series of Moose objects that I'm looking to feed to JSON::XS by way of Catalyst::View::JSON. JSON::XS is unable to encode blessed data-structures. I know that there is MooseX::Storage::Format::JSON which can -- kinda -- do what I want; but, it seems pretty overly heavy. What I'm looking for is essentially the same information th...

Perl Strange -M Flag in 'If' statement

Hi, What is this flag? if (-M ..filepath..) what is the '-M' flag? ...