If I pass a hash to a sub:
parse(\%data);
Should I use a variable to $_[0] first or is it okay to keep accessing $_[0] whenever I want to get an element from the hash? clarification:
sub parse
{ $var1 = $_[0]->{'elem1'};
$var2 = $_[0]->{'elem2'};
$var3 = $_[0]->{'elem3'};
$var4 = $_[0]->{'elem4'};
$var5 = $_[0]...
I have a text file filled with sentences with unique pattern. The unique pattern is:
NAME [ e_NAME ]
simple rule: the "NAME" must follow after "e_" if the "e_" appearers inside the brackets!
The problem comes out when the string is complicated. I'll show the end point situations that may be hard to analyse:
Lines that won't match...
I'm working on a program that uses an epoll-based event loop to handle multiple simultaneous socket connections. When the app detects that there is data to be read, it calls a process_request() sub, which uses buffered IO. For example:
sub process_request {
my ( $fh ) = @_;
if ( my $line = <$fh> ) {
# Do something inte...
I need to insert values in database using Perl's DBI module. I have parsed a file to obtain these values and hence these values are present in an arrays, say @array1, @array2, @array3. I know how to insert one value at a time but not from an arrays.
I know insert one value at a time:
$dbh = DBI->connect("dbi:Sybase:server=$Srv;database...
In DBIx::Class, when I generate a query using this syntax:
...
'Time(submitted_at)' => { '>' => 'Time(Now()-Interval ' . $wait_period . ' minute)' }
...
The generated query is perfect except for the fact that the function on the right hand side is in quotes.
... AND ( Time(submitted_at) > 'Time(Now()-Interval 5 minute)' ) ...
If i...
I'm using Moose roles to apply some wrapper behaviour around some accessor methods in a class. I want to apply this role to a number of modules, each of which have a different set of attributes whose accessors I want to wrap. Is there a way to access the meta class of the module being applied to, from within the role? i.e. something li...
After having heard about new parts of the Perl ecosystem, such as Moose, DeclareX, and Catalyst, I thought that it'd be nice to take a look at Perl. Unfortunately, all of the introductory material I can find targets Perl 5.8 or 5.6, and knows nothing about these newer frameworkslet alone features introduced in recent Perl versions, such...
I have a MySQL database that has a few very simple tables.
I would like to find an app (implemented in Perl, Python or PHP) that will do the following:
Point the app to a database table, and it automatically retrieves the table's schema from the database.
It then generates an HTML view of the table's data. The data is displayed as a ...
Has anyone ever experienced a unit test that fails and when they tried to debug it to find out where the failure was occurring, the unit test succeeds when running the code in the debugger?
I'm using Eclipse 3.5.1 with EPIC 0.6.35 and ActiveState ActivePerl 5.10.0. I wrote module A and module B both with multiple routines. A routine...
I am new to programming and hence I am stuck on a basic level problem.
Following is code I wrote for comparison. But the result I get does not make sense to me. I would appreciate if someone could tell me what is going wrong.
There are two arrays: @array1 , @array2 of unequal length.
I wish to compare both and list down values not p...
Can some one help me understand the output of this Perl program:
use Data::Dumper;
my %hash;
$hash{hello} = "foo";
$hash{hello}{world} = "bar";
print $hash{hello} . "\n";
print $hash{hello}{world} . "\n";
print Dumper(\%hash);
And the output:
foo
bar
$VAR1 = {
'hello' => 'foo'
};
Where is the "foo" coming from? H...
I'm looking for a performance comparison between perl and boost regular expression.
I need to design a piece of code which relies very heavily on regular expressions, and can choose between:
running it through a boost regex
dispatching a perl interpreter and do the work in perl
I know perl is known for it's optimized string pro...
The post is updated. Please kindly jump to the Solution part, if you've already read the posted question. Thanks!
Here's the minimized code to exhibit my problem:
The input data file for test has been saved by Window's built-in Notepad as UTF-8 encoding.
It has the following three lines:
abacus æbәkәs
abalone æbәlәuni
abandon әbænd...
I have to compare columns of tables located in two different databases in two different servers. So far, I know how to connect to one server & one database using Perl script. Is it possible to connect to two different servers using Perl's DBI module? If so, how?
...
I'm struggling to get SOAP working in perl.
In PHP it works perfectly, and without any trouble. And now I'm trying to do the same thing in Perl.
The functional PHP is:
$client = new SoapClient("http://thirdpartyurl.com/api.aspx?WSDL");
$info = $client->GetSomeInfo(array('username' => 'myusername', 'password' => 'mypassword'));
Which...
This code works - It takes an array of full txt file paths and strips them so that when $exam_nums[$x] is called, it returns the file name
for (0..$#exam_nums)
{
$exam_nums[$_] =~ s/\.txt$//; #remove extension
$exam_nums[$_] =~ s/$dir//g; #remove path
}
When I try to do this for a single variable, it doesn't work. I'm calling a sub...
I want to write a script foo which simply calls bar with the exact same arguments it was called with, using Bash or Perl.
Now, a simply way to do this in perl would be
#!/bin/perl
my $args=join(' ', @ARGV);
`bar $args`;
However, the values in ARGV have already been processed by the shell, thus if I call
foo "I wonder, \"does this...
I have to parse a file so that I can import it to excel. So, I thought the best way was to create a csv file. In this file, I have to divide contents into different categories and represent them in different columns. So, I have parsed the file to create different arrays corresponding to the categories. Now, I am trying to create a csv fi...
Given some unix program which I've compiled, what might I need to do to relocate it to a different directory and have it continue running correctly.
I'm thinking of Perl, but would be interested in other systems like Apache which also seem to fail when this is done. To motivate the question, being able to perform this sort of relocation...
I need to make a script to read images from a directory, rename them, resize them to a MAX_HEIGHT, MAX_WIDTH, put a watermark logo and save them in JPG.
I was thinking on doing this with an interpreted language, like Ruby, PHP, Perl, Python, or any with the image manipulation capabilities.
Which language would you recommend for this?
...