perl

Is there anything exciting in perl 5.11 (to become perl 5.12)?

Perl 5.11 is now released! Is there anything really exciting in this release, or is it mostly maintenance patches? (From what I've read so far, it appears to be a rollup of improvements we have already seen in prior releases.) the CHANGES file Jesse Vincent's announcement chromatic's blog post 5.11 is the development release of what...

How to "pad" a variable-length string to have an aligned last column

I have an input of the following format: 09:08:11 XXXXXXXXXXXXX 1.1.1.1 09:09:03 YYYYYYYY 2.2.2.2 09:12:37 ZZZZ 3.3.3.3 I am able to extract these individuals fields easily using the regex /(\S+)\s+(\S+)\s+(\S+)\s+/. I named them $time, $name, and $number. My problem is I want to display...

What is the difference between Perl's ( or, and ) and ( ||, && ) short-circuit operators?

Which of these subroutines is not like the other? sub or1 { my ($a,$b) = @_; return $a || $b; } sub or2 { my ($a,$b) = @_; $a || $b; } sub or3 { my ($a,$b) = @_; return $a or $b; } sub or4 { my ($a,$b) = @_; $a or $b; } I came to Perl 5 from C and Perl 4 and always used || until I saw more scripts us...

How can I search multiple files for a string in Perl?

My question is probably simple but I'm a complete newbie. I want to search the contents of multiple text files for a particular phrase and then display the lines of the finds on screen. I've already learnt how to deal with a single file. For example, if I want to search for a word, say "Okay" in a text file named "wyvern.txt" in the root...

How can I use an existing array as a value in a hash in Perl?

I have an existing array I wish to add as a value in a hash. I know you can use arrays as values but can see no way of assigning an existing one. I basically want to go: $hash{fieldName} = @myArray; Only that obviously doesn't work! Help appreciated! ...

How can I validate a filename with only eight digits and an extension, in Perl?

Perl (no modules loaded and -Tw & strict) I found much info on regex and pattern matching here but not exactly what I need. I want to know if this is the correct way to validate a couple things. Sorry about the beginner attempt here. I am quite new to this. my $this = "12345678"; if ($this != m/\b[0-9]{8}\b/x) { print "$this is bad"; }...

How can I run individual tests with Test::Class::Load?

After having accumulated enough tests that running them all takes some real time, I looked at the Test::Class::Load doc to find a tip for running individual test classes. It provides a manner to do this, but I must be missing something, because I can't make it work. Here's what I have: My test directory: drewfus:~/sandbox$ ls t/ lib/...

Should I use Nmap::Parser or Nmap::Scanner to audit a network?

I'd like to audit the equipment of my large network in the fastest way possible. Should i use Nmap::Parser or Nmap::Scanner? I want to create a list of IP addresses that return a ping as well as a related OS footprint and identification. Example: ping 192.168.*.* Then when I get a successful ping, store the IP address in a hash along...

How do I change the Gitweb default diff format to `--color-words`?

I want gitweb to output the same diff format as git diff --color-words. Does anybody know how I can do this? I looked at HTML::FromANSI but couldn't get it working with git diff --color-words from the command line. ...

How do I separate error handling from business logic in Perl?

How do I separate out exception handling / error handling from business logic? I'm writing code in Perl, and the error/exception handling and business logic makes it very difficult to understand code while reviewing. How can I refactor my code to make it more readable yet have error handling. Also note that I do not use try catch or any...

How do I get Perl POD in string and print it in page?

I have a POD document. Now, I want to convert that POD to a parsed section like usage/description and get it in a string. Why not pod2usage? This doesn't help me to get the output in string but in STDOUT/file. I am stressing on the point "getting it in string", because I want to display the POD in "pages" if the length exceeds screen ...

Why does chomp fail to remove newlines on Windows XP with Eclipse and Cygwin Perl?

I'm running WinXP, Eclipse 3.2 with EPIC and Cygwin for my Perl interpreter and I'm get an unexpected result. FYI... when I run it on my Ubuntu distro (vmware, same pc) I get the expected results. What gives? ############ CODE: ############# use warnings ; use strict ; my $test = "test" ; my $input = <STDIN> ; print length $te...

How can I create a TCP server daemon process in Perl?

I wish to create a TCP server daemon process in Perl. Which is the best framework/module for it?. Is there anything that comes bundled with Perl? Edit: Something that has start | stop | restart options would be great. Edit: It has to be a Multi threaded server. ...

What are the good frameworks for unit-testing and mock objects in Perl?

What frameworks and tools would you recommend for unit-testing and mock objects in Perl? I have an existing Perl application, that mainly does database access, reading and writing files. The application is basically a batch job type of application, it reads in bunch of stuff from files and database and writes a bunch of new files and so...

Is it a bad idea to write a multithreaded TCP server daemon in Perl?

Is it a bad idea to write multithreaded programs (specifically, TCP server daemons) in Perl? ...

Are there any conventions for writing POD comments for Perl?

I was able to find a page from Safari Books Online that provides a template, but having never written POD comments, I'm not sure how good it is or if it is missing anything that might be considered convention to include. What are the conventions to follow when writing POD comments for Perl scripts? Is there anything like Sun's Javadoc C...

Why do I get a trailing '1' after Perl's printf output?

When I implement the code below I get the correct dates: 10/05/2008 10/05/2009 When I use printf instead of sprintf, I get the following: 10/05/200910/05/20081 1 Any ideas on why printf prints the trailing 1? #!/usr/bin/perl use strict; use warnings; my ($from_date, $to_date) = to_from_dates(); print "$from_date\n"; print "$t...

What is the Perlish way to iterate from item n to the end of an array?

The problem is that I have n command-line arguments. There are always going to be at least 2, however the maximum number is unbounded. The first argument specifies a mode of operation and the second is a file to process. The 3rd through nth are the things to do to the file (which might be none, since the user might just want to clean the...

Should I sanitize file upload input field in my Perl CGI HTML form?

I understand the need to sanitize inputs from a HTML form, but when I sanitized the file upload field in a recent module of mine, the file upload started failing. It's important to sanitize all form inputs, right? Even the special file upload field? My form output code looks something like this: use CGI; my $cgi = new CGI; print $c...

How can I send mail to Gmail with an attachment, in Perl?

How can I send mail to Gmail using Perl? Here's what I'm trying: my $mailer = Email::Send->new( { mailer => 'SMTP::TLS', mailer_args => [ Host => 'smtp.gmail.com', Port => 587, User => 'xxx', Password => 'xxx', ] } ); use Email::Simple::Cre...