perl

How can I compare international phone numbers in Perl?

Are there any modules that can help me compare phone numbers for equality? For example, the following three numbers are equivalent (when dialling from the UK) +44 (0)181 1234123 00441811234123 0181 1234123 Is there a perl module that can tell me this? ...

Embedding Perl Interpreter

Hi, just downloaded ActivePerl. I want to embed the perl interpreter in a C# application (or at least call the perl interpreter from C#). I need to be able to send send out data to Perl from C#, then receive the output back into C#. I just installed ActivePerl, and added MS Script Control 1.0 as a reference. I found this code on the in...

How do I pass parameters to the File::Find subroutine that processes each file?

Using File::Find, how can I pass parameters to the function that processes each file? I have a Perl script that traverses directories in order to convert some 3-channel TIFF files to JPEG files (3 JPEG files per TIFF file). This works, but I would like to pass some parameters to the function that processes each file (short of using glo...

Does scientific notation affect Perl's precision?

I encountered a weird behaviour in Perl. The following subtraction should yield zero as result (which it does in Python): print 7.6178E-01 - 0.76178 -1.11022302462516e-16 Why does it occur and how to avoid it? P.S. Effect appears on "v5.10.0 built for x86_64-linux-gnu-thread-multi" (Ubuntu 9.04) and "v5.8.9 built for darwin-2level" (...

Should I call Perl subroutines with no arguments as marine() or marine?

Hi, My sample code as below, there are two styles subname and subnam() #!C:\Perl\bin\perl.exe use strict; use warnings; use 5.010; &marine(); # style 1 &marine; # style 2 sub marine { state $n = 0; # private, persistent variable $n $n += 1; print "Hello, sailor number $n!\n"; } Which one(&marine(); and &marine;) is more...

How can I save XML data to a file with XML::Simple?

I'm using XML::Simple package to import an XML file and change a few properties of some of the child tags. The change is visible when the data is dumped with: print Dumper($data); But how can I write this edited data into a new XML file? I did go through the CPAN page, but some code regarding this would really help. ...

Assigning one of multiple values based on what exists

In Perl, if I want to assign $myVar a value of $var1, $var2, or $var3, based on which one evaluates to true, I would code the following: $myVar = $var1 || $var2 || $var3; I am working on separate projects in both Python and PHP, and I have not figured out how to code this situation as concisely in either language. What is the best wa...

How can I add text to an image with Perl?

Hi I have got an image file which has 3 colors as background. I have also got a text file . I need to write a Perl script which copies text file on to the specific background color of the image file. When I execute my Perl script , the script should ask the path for image file and then the path for text file. ...

Print CSV header with Tie::Handle::CSV

Hi All, I wrote a perl script using Tie::Handle::CSV to process a bunch of data in a csv file and print out only what I need into a new csv file. Right now, I print out the header line with all of the field names by just a hardcoding it in like so: print '"TERM", "STUDENT ID", "NAME", ..."'."\n"; I suspect this is a dumb way of doin...

Why is Perl foreach variable assignment modifying the values in the array?

OK, I have the following code: use strict; my @ar = (1, 2, 3); foreach my $a (@ar) { $a = $a + 1; } print join ", ", @ar; and the output? 2, 3, 4 What the heck? Why does it do that? Will this always happen? is $a not really a local variable? What where they thinking? ...

Trapping arrow keys

I have a utility that I use as a pseudo "shell". It basically while()'s stdin for commands and runs them through different subroutines. My question is, is there a module or some example I can use to work toward trapping the up arrow so that I can have it perform a certain action? I plan to incorporate a previous command function similar...

How can I replace the <opt> tag in XML::Simple with the original tag name?

I'm using XML::Simple to edit an XML file. After which the updated data is sent to a new XML file. But this procedure produces <opt></opt> tag to be added and the original parent tag is lost. I want to replace <opt> with the original tag name. How do I do that? ...

How can I install Perl's Event::Lib on Mac OS X?

I want to install Realplexor (a Perl comet server) on Mac and it requires # apt-get install libevent-dev gcc # perl -MCPAN -e "install Event::Lib" I installed the first one using: port install libevent but I can't find "Event::Lib" with port nor fink. Does anyone know how I could install that dependency? ...

Making cookies with php and perl

I am trying to set a cookie using PHP, so it's the same as the one output by the Perl code below: my %auth; $auth{'username'} = $username; $auth{'password'} = $password; my $wholesaleauth = $co->cookie ( -name=>'wholesaleauth', -value=>\%auth, -expires=>'+1h', -path=>'/' ); Now I do not know perl and all and do not want to change ...

How can I add a new row to an existing Excel spreadsheet using Perl?

I have created my Excel sheet a.xls using Perl where I have field as: date name eid 13/jan/2010 asa 3175 When I will compile next time and if date will be more than previous date then it has to update like wise: date name eid 13/jan/2010 asa 3175 14/jan/2010 stone 3180 If the date will be of pr...

Which Perl web framework should I start with?

I have used Perl for years, but mostly for text processing and system management. Now I want to build a web site with "user management(user registration, user logon/logout, user settings)" feature, but I don't know what's the quickest way to do this. I need to find a Perl web framework and develop on it or modify some sample web applica...

How can I properly align UTF-8 strings with Perl's printf?

Hello, what is the right way to get here a beautiful output ( all lines the same indent )? #!/usr/bin/env perl use warnings; use strict; use DBI; my $phone_book = [ [ qw( name number ) ], [ 'Kroner', 123456789 ], [ 'Holler', 123456789 ], [ 'Mühßig', 123456789 ], [ 'Singer', 123456789 ], ...

Passing returned event data

Pretty new to C# (and I would describe myself as a beginner in programming, but I'm ambitious), so this is probably something very simple to solve. I have a function getting called in a switch like this: case "PERL_TEST": FileInfo fi = new FileInfo("hello.txt"); mainproc.process_file(fi); ...

How can I divide a Perl array into smaller arrays?

Is there any Perl equivalent for php's array_chunk()? I'm trying to divide a large array into several smaller ones. Thanks in advance. ...

How can I parse a phone number in Perl?

I am trying to grab any digits in front of a known line number of a phone, if they exist (in Perl). There will be no dashes, only digits. For example, say I know the line number will always be 8675309. 8675309 may or may not have leading digits, if it does I want to capture them. There is not really a limit on the number of leading di...