perl

Is there a more concise way to write this in Perl?

This subroutine is passed an array of file handles to close, which it closes one by one using the foreach loop: sub closef { foreach(@_) { my $fh = shift; close $fh; } } Where all can this simple subroutine be modified to make it better? Should I use close shift instead of doing it in two lines? ...

In Perl, how can I parse a string that might contain many email addresses to get a list of addresses?

I want to split the a string if it contains ; or ,. For example: $str = "[email protected];[email protected],[email protected];[email protected];"; The expected result is: result[0]="[email protected]"; result[1]="[email protected]"; result[2]="[email protected]"; result[3]="[email protected]"; ...

Perl: find if a variable's value matches that in an array

I'm a perl newbie. I have a code in which a variable is loaded with several values during a foreach loop. What I want to do is to perform some operation on that variable only if its in that array. What is the most efficient way to do this in perl as the data I am working on is very large. A simple example of my question is, say I have a...

How can I make fork in Perl in different scripts?

Hi everybody I have a process in Perl that creates another one with the system command, I leave it on memory and I pass some variables like this: my $var1 = "Hello"; my $var1 = "World"; system "./another_process.pl $var1 $var2 But the system command only returns the result, I need to get the PID. I want to make something like for...

How to test concurrent access to resource (cache) in Perl?

How can I test that resource (file based cache for caching output of a webapp in Perl) behaves sanely under concurrent access to said shared resource? I wrote a simple file-based cache, written in Perl, which uses locking to serialize write access, i.e. to have only one process that (re)generates cache entry. This cache is to be used...

Is it a convention to avoid using $_ when using other people's Perl API's?

I've just been caught out when using someone else's API in conjunction with the default variable $_ foreach (@rps_server_details) { @server_data = (); @server_data = split(/,/); @$esp_hosts = (); $filters{server_name} = $server_data[0]; print "--->$_<--\n"; $esp_hosts = $esp->get_hosts(fields => $fields, %filters...

Which Perl book would be the best for me?

I started learning Perl a couple of months back. The first stage was learning how to do things differently in Perl. Initially I always had the C mindset of doing things and would translate them to Perl code. Then, mainly through some questions here on SO, I learned about a variety of different techniques that Perl offers for the tasks ...

Perl screencast?

I need to learn Perl for an academic research I am doing. I need to go through a lot of older perl scripts and run them, tweak some perl scripts from open source tools for my use and of course make some of my own. I have a tight schedule so I needed to be comfortable with a perl code pretty quickly. I have previous coding experience fr...

How to write simplest makefile for perl

I know to simply run perl in linux you do perl program.pl args . How do I make convert that for a makefile? CC=perl CFLAGS=-O0 TARGET=./problem1 OUTFILE=./log.txt $(TARGET): problem1.o $(CC) $(CFLAGS) -o $(TARGET) problem1.o problem1.o: problem1.cpp $(CC) $(CFLAGS) -c problem1.perl clean: rm -f *.o $(TARGET) $(OUTFILE) run...

How can I create a directory with the 'right' permissions using Perl's mkdir?

I need help with this program. As a part of my project I need to create a directory. I was using the system function to do this, but later was told that Perl has a builtin called mkdir. I'm on Ubuntu 10.04. The problem is mkdir does not seem to work as needed. It creates the directory but the permissions are different. Here is my fun...

How can I convert a large Multimarkdown file into HTML?

I have a large (~4GB) text file written in Multimarkdown format, and I would like to convert it to HTML. I tried: use strict; use warnings; use File::Map qw (map_file); use Text::MultiMarkdown qw (markdown); my $filename = shift // die; map_file (my $text, $filename); print markdown($text); but it still chokes memory. ...

How can I format Multimarkdown tables?

I'm writing Multimarkdown tables following the guidelines under the Table section in the syntax guide, and I wish to convert them to HTML using Text::MultiMarkdown . It works great, The only problem is I can't figure out how to control the formatting of the tables (show borders, align headers, font size etc). ...

How can I read, analyze, and then "un-read" and reread the beginning of an input stream in Perl?

I'm reading and processing a stream of input from the ARGV filehandle in Perl (i.e. the while(<>) construct) a regular filehandle, which may be STDIN. However, I need to analyze a significant portion of the input in order to detect which of four different but extremely similar formats it is encoded in (different ASCII encodings of FASTQ ...

is it possible to read the text written in a sticky note using a script in linux?

I am using sticky notes in ubuntu . And was wondering if it would be possible to read the text written in sticky notes using any scripting language . ...

How can I simply make my HTML table 'dynamic'?

I'm writing Multimarkdown from Perl to create an HTML table. I wonder if there's a simple way to make the table dynamic , that is, allow the viewer sort it by clicking on a column header, or even filter records by entering a simple rule. I do not really know HTML. I'm coding in Perl and only generate HTML (actually, Multimarkdown conve...

how to merge 2 deep hashes in perl

I write a sub in Perl to merge 2 hashes of the same structure; so that merge($a,$b) $a = { k1 => { sk1 => 'v1' }, k2 => { sk3 => 'v3', sk4 => 'v4' } }; $b = { k1 => { sk2 => 'v2'}, k3 => { sk5 => 'v5'} }; would result in $c = { k1 => { sk1 => 'v1', sk2 => 'v2' }, k2 => { sk3 => 'v3', sk4 => 'v4' } k3 => { sk5 => 'v5'} }; B...

SMTP Authentication problem

I'm writing a simple mail client in Perl, that uses SMTP to log in a Mail server, and from there sends a mail to another E-mail address (on different host). I use raw SMTP commands, because strawberry perl doesn't come with SASL.pm which is needed in order to authenticate. However, when the script tries to authenticate itself, it fails. ...

Does sleep ges interrupted when any signal is received in perl?

I have this simple perl daemon: #!/usr/bin/perl use strict; use warnings; use Proc::Daemon; Proc::Daemon::Init; my $continue = 1; $SIG{TERM} = sub { $continue = 0 }; $SIG{USR1} = sub { do_process(1) }; # basic daemon boxesd_log("started boxesd"); ...

file transfer to multiple sockets simultaneously

Hi, In perl, is there a way to broadcast a file from a server socket to multiple client sockets? I want to transfer a single file to multiple systems in least amount of time. Thanks, Akshey ...

Why does invoking print in a subroutine append 1 to the string?

I have created the following subroutine gender to randomly print string MALE or FEMALE. When subroutine is invoked, the print command suffixes a "1" at the end of the string. See the sample code and output below: sub gender { if ( (int rand(100)) >50) { print "MALE "; } else { print "FEMALE"; } } fo...