perl

How do I tell DBD::mysql where mysql.sock is?

Using DBD::mysql with DBI, I am getting the following error when attempting to connect to the database. DBI connect('database=mydb:host=localhost','someuser',...) failed: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) at ./myscript.pl line 97 Yes MySQL is up and running. The problem is that mysql.sock is ...

Test::File::Find::Rule check that all our perl scripts have use strict

use warnings; use Test::More; use File::Find::Rule; use Test::File::Find::Rule; my $rule = File::Find::Rule->file->name('*.pl')->not_grep(qr/^\s*use\s+strict;/m, sub { 1 }); match_rule_no_result($rule, ".", 'use strict usage'); done_testing(); and the output was : out put : ok 1 - use strict usage 1..1 it is always passing the tes...

What is the difference between DBI and DBD?

Can someone please shed some light on what exactly is DBI and DBD? When should either one be used and the benefits of using one over the other. ...

How do I create new variables with indexed names in Perl?

hi i've read some related question non seems tohelp me. this is a code that will explain what i want. for ($i=0;$i<5;$i++) { my $new$i=$i; print "\$new$i is $new$i"; } expecting variables to be named $new0,$new1,$new2,$new3,$new4,$new5. and to have the abillty to use them in a loop like the print command is trying to do. Thanks ...

Why do I get ARRAY(0x8470d6c) instead of a list from my YAML configuration?

I have this YAML file: name: Firas dirs: [/bin/, /home/phiras/] I am using YAML::Syck in perl to parse this file, and I have a problem with accessing dirs items. my code is: #!/usr/local/bin/perl use strict; use warnings; use YAML::Syck; use ConfigLoader; use Data::Dumper; my $conf = LoadFile("myconf.yml") || die("Error: Open conf...

How can I get a list of results when sqlite returns more than one row?

Hello, this is how my table looks: key | driver | machine | result ----------------------------------- 1 | 1234 | abc_machine | pass 2 | 1234 | xyz_machine | fail when a user selects '1234' from driver and all from machine things get a little messy. (user makes selection from a gui) when i do: $getConfig = `sqlite3 ...

Why does Perl's tr/\n// get slower and slower as line lengths increase?

In perlfaq5, there's an answer for How do I count the number of lines in a file?. The current answer suggests a sysread and a tr/\n//. I wanted to try a few other things to see how much faster tr/\n// would be, and also try it against files with different average line lengths. I created a benchmark to try various ways to do it. I'm runni...

How do you draw filled and unfilled circles with PDF primitives?

Drawing circles on PostScript is easy, and I'm surprised that PDF apparently doesn't carry over those same primitives. There are plenty of commercial libraries that will do it, but shouldn't it be simpler than that? There are also some tricks using Bézier curves, but you don't get a perfect circle and you have to draw them in connecting...

How can I make my Perl script use multiple cores for child processes?

Hi all, I'm an aerospace engineering student, and I'm working on a senior capstone project. One of the mathematical models I'm developing requires an astronomical amount of generated data from XFOIL, a popular aerospace tool used to find the lift and drag coefficients on airfoils. (But I'm digressing.) Cut to the chase: I have a Perl s...

How do I get the PID of the process I start with Perl's system()?

Hi all, I'm writing a Perl script that runs 4 simultaneous, identical processes with different input parameters (see background here - the rest of my question will make much more sense after reading that). I am making a system() call to a program that generates data (XFOIL, again see above link). My single-core version of this program...

How can I auto focus on a textfield using Win32 GUI in Perl?

I'm following an online Win32::Gui tutorial to learn how to add a GUI to my Perl application. So far everything's been good. But I'm having some pesky small problems. So I'm asking for help here again. One problem is, I have to click my mouse in the textfield before I can type. I tried something lie this: $Object->AddTextfield( ...

How can I timeout a forked process that might hang?

Hi all, I am writing a Perl script that will write some inputs and send those inputs to an external program. There is a small but non-zero chance that this program will hang, and I want to time it out: my $pid = fork; if ($pid > 0){ eval{ local $SIG{ALRM} = sub { die "TIMEOUT!"}; alarm $num_secs_to_timeout; ...

How do I access the stash in every request in a parent controller?

Hello! I am trying to refactor my Catalyst application and I would like to introduce a common base class for my controllers. This base controller would load some data and put some other data into the stash for every request. I have got some trouble getting to the stash. Simple solution would be to implement a default auto action in the b...

How can I log only the INFO level in Log4perl?

log4perl has a threshold option in the configuration file that will log all calls that level or higher. Is there an option of setting it log only one type of call? I want to only log calls of level "INFO". Thanks. ...

Is there any C# equivalent to Perl's HTML::TableExtract?

I need to grab a table from a HTML to get the data contained in the table. I've learned from you that it can be solved easily by Perl's HTML::TableExtract. Since the grabbed data will be showed off by "C#" , so if there is C# equivalent to Perl's HTML::TableExtract, it will easier for me to implement the whole app. ...

Why do I get "Invalid predicate" error from getElementsByTagName?

Hi, I get the following XML: <config> <version general="1.2.3"> <subtype type="a" version="1.2" /> <subtype type="b" version="3.6" /> ... </version> ... </config> I have some code in Perl to get the config node from a database. After I get it, if I try the follwoing: my $elem = $cfg->getElementsByTagName("version"...

How can I set the dialect in SQL::Parser?

Why do I get two times "ANSI" and not the first time "ANSI" and the second time "AnyData"? #!/usr/bin/perl use warnings; use strict; use 5.010; use SQL::Parser; my $parser = SQL::Parser->new(); my @dialects = $parser->list( 'dialects' ); say "available dialects : @dialects"; # AnyData CSV ANSI my $...

How do I unpack binary files with Perl?

Hi there, I have two binary files equal in size but not in values. I used unpack as follows but the results are weird. When I use "big" binary files - Both of the outputs shows part of the results: One binary file starts good - ends bad, Second binary file goes wrong at the start. Where do you think may be the week point ? open(BIN...

How do I get Perl::Critic to work with E.P.I.C and eclipse?

I'm running eclipse Galileo with EPIC 0.5.46 and ActiveState ActivePerl 5.10.0, on WinXP SP3. I just downloaded Perl::Critic using the package manager, and integrated it to eclipse using the appropriate Properties page. I can run Perl::Critic just fine from my eclipse source context menu; it runs. But it doesn't put any markers in...

How do I get a list with all reserved words in SQL::Parser?

Hi, with #!/usr/bin/perl use warnings; use strict; use 5.010; use SQL::Parser; my $parser = SQL::Parser->new( 'ANSI', {RaiseError=>1} ); my $word = 'BETWEEN'; my $success = $parser->feature( 'reserved_words', $word ); $success = $success ? '' : 'NOT'; say "$word is $success a reserved word"; I can ...