perl

How can I remove relative path components but leave symlinks alone in Perl?

I need to get Perl to remove relative path components from a Linux path. I've found a couple of functions that almost do what I want, but: File::Spec->rel2abs does too little. It does not resolve ".." into a directory properly. Cwd::realpath does too much. It resolves all symbolic links in the path, which I do not want. Perhaps the...

How can I define Makefile variables from a Perl script?

I am creating a Makefile which I want it to be a single file for different architectures, OSes, libraries, etc. To do this I have a build specific XML file which defines the different configuration options for each architecture. The config file is read by Perl (it could be any language) and the Perl output returns something like: var1...

How can I remove repeated characters but leave two of them?

If there are more than 2 characters "Hiiiiiii My frieeend!!!!!!!" I need to be reduced to "Hii My frieend!!" Please undestand that in my language there are many words with double chars. Thnx in advance kplla ...

Handling Java stdout and stderr in Perl

I am trying to run a Java program from my Perl script. I would like to avoid using System.exit(1) and System.exit(-1) commands in Java. I am however printing to STDOUT and STDERR from Java. In my Perl script, I am reading from Java's stdout and using that line by line output. How do I print stderr and fail if I ever see stderr? This is w...

How can I create a non-modal dialog in Perl/Tk?

I am learning Perl/Tk. I want to give alert to the user whenever he/she receives the mail. I have planned to use message box in Tk, but it is expecting the user to click ok or cancel button. Until user clicked the any one button it wont do any further operations. But I want, it just needs to give alert to the user and user can continu...

How can I redirect the output of Perl's system() to a filehandle?

With the open command in Perl, you can use a filehandle. However I have trouble getting back the exit code with the open command in Perl. With the system command in Perl, I can get back the exit code of the program I'm running. However I want to just redirect the STDOUT to some filehandle (no stderr). My stdout is going to be a line-by...

In Perl, how can I call a method whose name I have in a string?

I'm trying to write some abstract code for searching through a list of similar objects for the first one whose attributes match specific values. In order to do this, I need to call a bunch of accessor methods and check all their values one by one. I'd like to use an abstraction like this: sub verify_attribute { my ($object, $attribu...

What do the columns in Perl's Devel::Cover output mean?

In the "Perl build, unit testing, code coverage: A complete working example by Kurt W. Leucht" we see that we run build testcover and bet the coverage report. We see the result in the figure "File Cover". Can anyone tell what does the number shown under stmt, bran, sub and time indicate? ...

How can I generate images of basic figures with Perl?

I am using jalava library as a diagram drawing tool. It displays figures as images in order to maintain compatibility with majority of browsers. When diagram block is being resized a request is being made and new gif image is generated and send to browser. What I need is generating image of basic blocks, like rounded rectangle, circle,...

Why am I getting a new session ID on every page fetch in my Perl WWW::Mechanize script?

So I'm scraping a site that I have access to via HTTPS, I can login and start the process but each time I hit a new page (URL) the cookie Session Id changes. How do I keep the logged in Cookie Session Id? #!/usr/bin/perl -w use strict; use warnings; use WWW::Mechanize; use HTTP::Cookies; use LWP::Debug qw(+); use HTTP::Request; use LWP:...

Is there a simple way to validate a hash of hash element exists and is defined?

I need to validate a Perl hash of hash element such as $Table{$key1}{$key2} to exist and be defined. Here is what I do. (I have no idea $key1 even exists) if ((defined $Table{$key1}) && (exists $Table{$key1}) && (defined $Table{$key1}{$key2}) && (exists $Table{$key1}{$key2})) { #do whatever } Is there an easier and cleaner w...

Why doesn't Perl's XML::LibXML module (specifically XPathContext) evaluate positions?

I have an XML representation of a document that has the form: <response> <paragraph> <sentence id="1">Hey</sentence> <sentence id="2">Hello</sentence> </paragraph> </response> I'm trying to use XML::LibXML to parse a document and get the position of the sentences. my $root_node = XML::LibXML->load_xml( ... )->documentElem...

How can I read malformed XML (unencoded entities) with Perl?

I'm trying to parse an XML file I get from an external source but am having problems because there are unencoded XML entities in the text nodes. Essentially, I'm asking the same question as this, but for Perl instead of PHP. <report> <company>A & W</company> <company>Some Other Company with a < in Inc.</company> </report> I...

How can I save BioPerl sequence nested features in genbank or embl format?

EDIT: Please close this question. I asked and got an answer for it on BioStar here. In BioPerl, a sequence object can have any number of features, and each of these can have subfeatures nested within them. For example, a feature may be a complete coding sequence of a gene, and its subfeatures might be individual exons that ar...

Checking if any of a list of values falls within a table of ranges

I'm looking to check whether any of a list of integers fall in a list of ranges. The ranges are defined in a table defined something like: # Extra Type Field Default Null Key 0 int(11) rangeid 0 NO PRI 1 int(11) max 0 NO MUL 2 int(11) min 0 ...

Large file uploads from web pages

Hi folks, I code primarily in PHP and Perl. I have a client who is insisting on seeking video submissions (any encoding) from the public via one of their pages rather than letting YouTube do its job. Server in question is a virtual machine and I can adjust ini settings for max post, max upload size etc as needed. My initial thought i...

Appending a prefix when using join in Perl

I have an array of strings that I would like to use the join function on. However, I would like to prefix each string with the same string. Can I do this in one line as opposed to iterating through the array first and changing each value before using join? Actually it's a lil bit trickier. The prefix is not part of the join separator. M...

How do I insert a word into a string in Perl?

#!C:\Perl\bin\perl.exe use strict; use warnings; use Data::Dumper; my $fh = \*DATA; while(my $line = <$fh>) { $line =~ s/ ^/male /x ; print $line ; } __DATA__ 1 0104 Mike Lee 2:01:48 output male 1 0104 Mike Lee 2:01:48 Then I tried to insert male after the racenumber(0104), I replaced the code with style. $line...

How do I split Chinese characters one by one?

If there is no special character(such as white space, : etc) between firstname and lastname. Then how to split the Chinese characters below. use strict; use warnings; use Data::Dumper; my $fh = \*DATA; my $fname; # 小三; my $lname; # 张 ; while(my $name = <$fh>) { $name =~ ??? ; print $fname"/n"; print $lname; } __...

Why is the exit code 255 instead of -1 in Perl?

Why is it that when I shift the exit code, $?, in Perl by eight, I get 255 when I expect it to be -1? ...