perl

Why does my Perl print show HASH(0x100a2d018)?

Here I am thinking I know how to use lists in Perl, when this happens. If I do this (debugging code, prettiness not included): #! /usr/bin/perl -w use strict; my $temp1 = "FOOBAR"; my $temp2 = "BARFOO!"; my @list = { $temp1, $temp2 }; print $temp1; #this works fine print $list[0]; #this prints out HASH(0x100a2d018) It looks like I...

Can I overload Perl's =? (And a problem while use Tie)

I choose to use tie and find this: package Galaxy::IO::INI; sub new { my $invocant = shift; my $class = ref($invocant) || $invocant; my $self = {']' => []}; # ini section can never be ']' tie %{$self},'INIHash'; return bless $self, $class; } package INIHash; use Carp; require Tie::Hash; @INIHash::ISA = qw(Tie::StdH...

How can I extract a substring enclosed in double quotes in Perl?

I'm new to Perl and regular expressions and I am having a hard time extracting a string enclosed by double quotes. Like for example, "Stackoverflow is awesome" Before I extract the strings, I want to check if it is the end of the line of the whole text was in the variable: if($wholeText =~ /\"$/) #check the last character if " wh...

How can I suppress empty leading fields in Perl's split()?

The perlfunc entry for split says: By default, empty leading fields are preserved Hinting that there's a way to over-ride that default, but later on all it says is: Empty leading fields are produced when there are positive-width matches at the beginning of the string ...does this mean that there's no way to skip that first fi...

Is there a way to modify foreach loop variable?

The following code gives an error message: #!/usr/bin/perl -w foreach my $var (0, 1, 2){ $var += 2; print "$var\n"; } Modification of a read-only value attempted at test.pl line 4. Is there any way to modify $var? (I'm just asking out of curiosity; I was actually quite surprised to see this error message.) ...

How many ways can you call a subroutine and ignore its prototype in Perl?

We should all be familiar with the problems related to prototypes in Perl. Here are the two biggies: they don't work like prototypes in other languages, so people misunderstand them. they don't apply to all ways of calling a subroutine. The second item is the one I am curious about at the moment. I know of two ways to subvert/work ...

Is there a script for generating a migration SQL (postgres) file?

On a project I work I have sometimes have to deal with changes on the table structure, like adding fields. Is there a script that can I use for generate a migration SQL file with only the changes? PHP, bash or Perl would be nice. The database is postgresql. ...

Is there a good Perl project plugin for Eclipse Galileo or NetBeans 6.7?

I tried to use Perl Editor and IDE for Eclipse, but I get failures on installation, and I haven't found anything for NetBeans other than a syntax highlighter (no way to execute or debug Perl from within the IDE and no way to make a Perl project). The error that I get when installing the Perl Editor and IDE for Eclipse is: An error occu...

Regexp/perl code for handling both dots and commas as valid decimal separators

I'm trying to create a method that provides "best effort" parsing of decimal inputs in cases where I do not know which of these two mutually exclusive ways of writing numbers the end-user is using: "." as thousands separator and "," as decimal separator "," as thousands separator and "." as decimal separator The method is implemented...

How can Perl fill out fields on a GUI made in Visual Basic?

I have a script that runs several little programs I don't have the source code to, one of which requires filling out some fields in a GUI. I've been doing this by hand, but I'd like to have the Perl script focus the GUI window, then enter some hardcoded text into each field and close the window. ...

Why does my Perl for loop exit early?

I am trying to get a perl loop to work that is working from an array that contains 6 elements. I want the loop to pull out two elements from the array, perform certain functions, and then loop back and pull out the next two elements from the array until the array runs out of elements. Problem is that the loop only pulls out the first two...

Managing Perl habits in a Python environment

Perl habits die hard. Variable declaration, scoping, global/local is different between the 2 languages. Is there a set of recommended python language idioms that will render the transition from perl coding to python coding less painful. Subtle variable misspelling can waste an extraordinary amount of time. I understand the variable de...

How to replace a Perl hash key?

Let us say if I have a hash like this: $data = { 'key1' => { 'key2' => 'value1' }, 'key3' => { 'key4' => { 'key5' => 'value2' } }, }; Now, how can I replace the the key 'key5' with some other key name say 'key6'?...

How do I prevent List::MoreUtils from warning about using $a and $b only once?

The List::MoreUtils module indicates that you use the variables $a and $b when supplying the BLOCK that goes with the pairwise function. For example: use strict; use warnings; use List::MoreUtils qw'pairwise'; my @x = ( 1 .. 5); my @y = (11 .. 15); my @sums = pairwise { $a + $b } @x, @y; But when I do that, I get warnings like this:...

Why is Perl the best choice for most string manipulation tasks?

I've heard that Perl is the go-to language for string manipulation (and line noise ;). Can someone provide examples and comparisons with other language(s) to show me why? ...

How can I partition a Perl array into equal sized chunks?

I have a fixed-sized array where the size of the array is always in factor of 3. my @array = ('foo', 'bar', 'qux', 'foo1', 'bar', 'qux2', 3, 4, 5); How can I cluster the member of array such that we can get an array of array group by 3: $VAR = [ ['foo','bar','qux'], ['foo1','bar','qux2'], [3, 4, 5] ]; ...

How can I ask the user to re-enter input when they enter invalid input, in Perl?

Hi, I've a Perl subroutine which asks input from User. I perform a check inside that subroutine itself whether the input entered is a valid input. If it's not, I want to call the subroutine again to let the user enter a valid input this time. My subroutine is as follows: sub some_routine { print "Enter a number to select (1...

How can I calculate the median and standard deviation of a bunch stream of numbers in Perl?

Hi everyone, In our logfiles we store response times for the requests. What's the most efficient way to calculate the median response time, the "75/90/95% of requests were served in less than N time" numbers etc? (I guess a variation of my question is: What's the best way to calculate the median and standard deviation of a bunch stre...

Why are my backslashes disappearing in my Perl one-liner?

I tried a search and replace across all files in a directory as follows: /usr/bin/perl -p -i -e "s/Else/Else FILE_WRITE(\"C:\\TestDir\\mes.txt","Message received");/g" *.scr That is replace all occurence of Else with "Else FILE_WRITE(\"C:\TestDir\mes_.txt","Message received");" But the replacement is seen to be as follow...

Extracting matches from php regex

In perl regex we can extract the matched variables, ex below. # extract hours, minutes, seconds $time =~ /(\d\d):(\d\d):(\d\d)/; # match hh:mm:ss format $hours = $1; $minutes = $2; $seconds = $3; How to do this in php? $subject = "E:[email protected] I:100955"; $pattern = "/^E:/"; if (preg_match($pattern, $subjec...