perl

How can I serialize a closure in Perl?

I think this might be best asked using an example: use strict; use warnings; use 5.010; use Storable qw(nstore retrieve); local $Storable::Deparse = 1; local $Storable::Eval = 1; sub sub_generator { my ($x) = @_; return sub { my ($y) = @_; return $x + $y; }; } my $sub = sub_generator(1000); say $sub->(...

How do I convert escaped characters into actual special characters in Perl?

Possible Duplicate: How can I manually interpolate string escapes in a Perl string? I'm reading a string from a particular file. The problem with it is that it contains escaped characters, like: Hello!\nI\'d like to tell you a little \"secret\"... I'd like it to be printed out without escape sequences, like: Hello! I'd lik...

How should I define 'static' subroutines in Perl?

I'm used to work in Java, so perhaps this question is a Java-oriented Perl question... anyway, I've created a Person package using Moose. Now, I would like to add a few subroutines which are "static", that is, they do not refer to a specific Person, but are still closely related to Person package. For example, sub sort_persons gets an ...

How can I replace aeiou with bfjpv in Perl?

I want to replace aeiou with bfjpv in user inputted string. Here is the code which is not working :- print "Enter any String :"; while(($string = <>) ne "\n"){ @arr = split(//,$string); for($i = 0 ; $i < $#arr ; $i++){ $char = $arr[$i]; if($char eq 'a' || $char eq 'e' || $char eq 'i' || $char eq 'o' || $char e...

What does this following code do?

Hello, What does this following do? Can anybody explain me? $data = "What is the STATUS of your mind right now?"; $data =~/.*/; print "$1,$2\n"; $data =~/(.*?)(u+).*/; print "$1, $2\n"; $data =~/(.?)(u+).*/; print "$1, $2\n"; $data =~/(\w+\s)+/; print "$1, $2\n"; What is $1 and $2? How does this get it's value? and what are all t...

How can I replace multiple whitespace with a single space in Perl?

Why is this not working? $data = "What is the STATUS of your mind right now?"; $data =~ tr/ +/ /; print $data; ...

How do I get the hexadecimal representation of $foo in Perl?

Given the variable $foo containing binary data, how do I get the hexadecimal representation of $foo in Perl? ...

How can I handle configuration files in Perl?

I'm refactoring an old script that does some operations on different sites. It needs to use a configuration file which is now a manually parsed text file with this format: label:domain:username:password:path Of course the number of lines is potentially unlimited. I know there are a few modules which deal with config files. Which one ...

Run Perl code directly in Emacs

On the Emacs on the pc's in school we can use 'F5' to run a selected piece of perl code. However, when im trying to do this at home it fails. I have installed Emacs and Activeperl on my windows7 machine. Whenever i try to run a piece of code i get the error 'F5 is undefined'. However, when i look into the .Emacs file i see that the F5 ...

Geocoding....did I do something wrong?

I am using the Geo::Coder::Many perl module & getting some weird results. When I set Google as the provider, the results are correctly displayed. However, setting the provider to Bing will reverse the latitude & longitude values. For instance: use Geo::Coder::Google; use Geo::Coder::Bing; use Geo::Coder::Many; use Geo::Coder::Many::Util...

How can I suppress system output when using nohup from Perl?

In Perl I am starting a process using the nohup command. The command is below: system("nohup myproc pe88 &"); This works fine and the process starts as expected. However I would like to suppress the following output of this command - which is: Sending output to nohup.out I must have this process redirecting all of it's output to no...

How do I use a Perl variable in a regular expression?

I am trying to do a search and replace with variables. In this case variables that I pulled from a previous match. Here is my code: $fileContentToAlter =~ s/$2/$1/g; Now I realize in that state, it is being read incorrectly as $ has its own meaning inside of a regexp. I did some searching on the web and read that doublequotes could fi...

How can I find out total disk space occupied by a certain user?

How can I find total disk space occupied by a certain user, say located in /home/Mary? What function is available in Perl to know this? ...

How can I implement Unix grep in Perl?

How can I implement grep of Unix in Perl? I tried to use Perl's built-in grep. Here is the code which is not working: $pattern = @ARGV[0]; $file= @ARGV[1]; open($fp,$file); @arr = <$fp>; @lines = grep $pattern, @arr; close($fp); print @lines; And by the way, i am trying only basic grep functionality not full featured and secondly ...

What is the Perl equivalent of PHP's proc_open(), proc_close(), etc.?

Using PHP's proc_open(), I can start a process, read from STDOUT and STDERR (separately) an arbitrary number of bytes at a time using fread() while the process is running, detect when the process is done using feof() on the STDOUT and STDERR pipes, and then use proc_close() to get the exit code of the process. I've done all of this in PH...

What's the best way to convert "awk '{print $2 >> $1}' file" in a Perl one-liner?

How could I convert: awk '{print $2 >> $1}' file in a short Perl one-liner? "file" could look like this: fruit banana vegetable beetroot vegetable carrot mushroom chanterelle fruit apple ...

run perlscript from emacs (cscript example //C:Perlscript)

i would like to create a shortcut key for emacs to execute this command: cscript example //C:Perlscript with example.pl being the perl script that i want to execute i already got a shortcut key for executing perl: (global-set-key (kbd "") 'perl-eval) how do i make this? ...

How can I create a hash of hashes from an array of hashes in Perl?

I have an array of hashes, all with the same set of keys, e.g.: my $aoa= [ {NAME=>'Dave', AGE=>12, SEX=>'M', ID=>123456, NATIONALITY=>'Swedish'}, {NAME=>'Susan', AGE=>36, SEX=>'F', ID=>543210, NATIONALITY=>'Swedish'}, {NAME=>'Bart', AGE=>120, SEX=>'M', ID=>987654, NATIONALITY=>'British'}, ] I would like to write a subroutine that w...

How can I dynamically load perl extensions in an embeded perl interpreter?

I am embeding perl interpreter in my C code (what fun!). I need to dynamically load perl extensions (an extension that extends perl, written in C). When I run a perl script (using my embeded perl interpreter) that needs to use that extension, it will work! ...

How do I use Perl's import, use, require and do?

Can someone explain exactly the usage recomandations regarding the 4 perl imports: do, import, use and require? I'm looking for practical recommendations and keeping in mind possible issues that might arise in the context of mod_perl or something similar. We all love simple examples, good ones! So far the best resource I found was htt...