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...
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...
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...
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...
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.)
...
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 ...
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.
...
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...
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...
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.
...
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...
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...
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'?...
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:...
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?
...
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] ];
...
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...
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...
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...
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...