perl

What do Perl's grep and map do?

What does this code actually do? @array = ( 'hai','hello','bar','foo' ) ; print grep (/hai/ , @array ); print grep ("hai",@array ) ; print map (/hai/ , @array ); print map ("hai",@array ) ; ...

How can I remove all whitespaces and linebreaks in Perl?

I have a string that looks like this... " http://www.example.com/ example.pdf" I need to remove the whitespaces and linebreaks. How do I do this? My result should be "http://www.example.com/example.pdf" ...

How can I center captions in PerlMagick?

Using ImageMagick on the command line I can say convert -background '#0000' -fill white -stroke black -strokewidth 3 -gravity center -pointsize 78 -size 568x1000 caption:'Lorem ipsum etc etc' -trim +repage out.png And produce the output I'm looking for. What I'd like to do is the same thing but within PerlMagick so that I don't have ...

How can I format messages with Perl's Mail::Outlook?

I'd like to format messages that I send using the Mail::Outlook.For e.g. change the font size or make it bold etc. How do I do this? ...

How can I create a two-dimensional array in Perl?

I am currently trying to pass a matrix file that is 32 by 48 to a multi-dimensional array in Perl. I am able to access all of the values but am having issues accessing a specific value. I need to run specific statistics on each of the values, calculate zscore, subtract the mean from each value, penalize specific values et cetera. I tried...

Why do I get extra line breaks in the web page I download with Perl?

I'm writing a simple Perl script (on Windows) to download the response of a get request to a url to a file. Pretty straight-forward. Except when it writes to the output file, I get extra line breaks. So like instead of: <head> <title>title</title> <link .../> </head> I get <head> <title>title</title> <link .../> </head> ...

Why do I get "issuer is not trusted" when I try to login to Subversion from Perl?

I'm trying to log in to the subversion, I have stored permanently the certificate, but I keep getting this error: RA layer request failed: PROPFIND request failed on '/svn/QFlife/Projects%20DotNet/QFX/trunk/Clients': PROPFIND of '/svn/QFlife/Projects%20DotNet/QFX/trunk/Clients': Server certificate verification failed: issuer is not ...

How can I run a long background process from a Perl CGI program?

I have a problem with a long running CGI and the timeout error: Timeout waiting for output from CGI script The client side is a form programmed in jQuery. The user input some data and receives a message that the analyses has been launch. The user don't expect to see receive more messages except an email with a link when the data h...

How can I get rid of empty lines Perl's Pod so they don't show up with Pod::Usage?

I have following pod which I used with getopt::long: =head1 SYNOPSIS foo [OPTION]... [URL]... =head1 OPTIONS =over 20 =item B<-h, --help> Print a brief help message and exits. =item B<-i, --input=FILE> Reads from FILE =back =cut and when I provides -h it produces: Usage: foo [OPTION]... [URL]... Options: -h, --hel...

How can I wrap lines to 45 characters in a Perl program?

I have this text I am writing in a Perl CGI program: $text = $message; @lines = split(/\n/, $text); $lCnt .= $#lines+1; $lineStart = 80; $lineHeight = 24; I want to force a return after 45 characters. How do I do that here? Thanks in advance for your help. ...

What is the Python equivalent of Perl's backticks?

Possible Duplicate: Equivalent of Backticks in Python When I want to write directly to the command prompt in Perl, I can do something like this: Perl File test.pl: $directory = `dir`; print $directory; Which would output something like.. C:\Documents and Settings\joslim\Desktop>perl test.pl Volume in d...

Why does Perl's DateTime->from_epoch return 1969-12-31 23:59:59?

We are processing data from an API that is returning date/time values of the following form: 1061943540000 When I used the tool on this page it converts the value to the following correct date: Tue Aug 26 2003 17:19:00 GMT-0700 (PDT) We are using the following Perl code to convert the date/time in our script: use DateTime; my $dt ...

In Moose, how can I make a class's constructor return an instance of a subclass?

Possible Duplicate: How to have Moose return a child class instance instead of its own class, for polymorphism Suppose I have two related classes MyClass::A and MyClass::B that are both subclasses of MyClass. I would like the constructor for MyClass to take a filename, read the file, and based on the contents of the file, deci...

perl help to join records and insert characters

Perl newbie here...looking for help to reformat a datafile. Data looks like this: num:3460381591 num:1038198413 num:3380733973 I would like to make it one string and then append each start of the rec with ^a and ^b after the colon like this: ^anum:^b3460381591^anum:^b1038198413^anum:^b3380733973 Can someone show me how to do th...

In Moose, how can I tell whether one object's class is a subclass of another object's class?

Suppose I have two objects $obj1 and $obj2 that are both instances of Moose classes. I want to find out which of the following applies: $obj1's class is the same as $obj2's; $obj1's class is a subclass of $obj2's; $obj1's class is a superclass of $obj2's; Neither object's class is a subclass of the other's. How can I do this? ...

How do I substitute with an evaluated expression in Perl?

There's a file dummy.txt The contents are: 9/0/2010 9/2/2010 10/11/2010 I have to change the month portion (0,2,11) to +1, ie, (1,3,12) I wrote the substitution regex as follows $line =~ s/\/(\d+)\//\/\1+1\//; It's is printing 9/0+1/2010 9/2+1/2010 10/11+1/2010 How to make it add - 3 numerically than perform string concat?...

Can Perl string interpolation perform any expression evaluation?

related to question: http://stackoverflow.com/questions/3939788/perl-regex-substituion/3939854 In Perl, is there a way like in Ruby to do: $a = 1; print "#{$a + 1}"; and it can print out 2? ...

Problem with sending an array using 'pack' function in perl

Hi All, I am using pack function to send contents of a list to a socket. Code is given below. $message_array = pack ("(A*)*", @ul_dcch_message); The list contents are @ul_dcch_message = (101101012411011, "emergency", 25, "simple"); This piece of code sends all the strings and numbers contained in the list. But if the numbers prese...

How can I redirect output of die function to a file in Perl?

I want to redirect the die messages to a separate file so that I can compare that file later to determine what went wrong. But this code gives me errors: $ cat test.pl use strict; use warnings; my $log = "msglog.log"; die $log "DEAD$!"; $ perl test.pl Missing comma after first argument to die function at test.pl line 5, near ""DEAD$!...

How can I check the extension of a file using Perl?

To my perl script, a file is passed as an arguement. The file can be a .txt file or a .zip file containing the .txt file. I want to write code that looks something like this if ($file is a zip) { unzip $file $file =~ s/zip$/txt/; } One way to check the extension is to do a split on . and then match the last result in the arr...