perl

How do I skip lines that aren't whitespace or a number in Perl?

I am reading data from a file like this while (<$fh>) { @tmp = split; # <-- ? push @AoA, [@tmp]; } I have a couple of questions regarding this. What does the marked line do? Does it split the file by lines and store elements of each line into an array?? If so, is it possible to convert @tmp into a string or do a regex...

How do I stop pod2html from treating "=head2 open() foo" as a function definition?

I have some POD that looks like =head2 C<close() on unopened filehandle %s> =over =item C<Yer tryna close() %s what ain't been opened yet> =back The pod2html command turns it into <h2><a name="close____on_unopened_filehandle__s"><a href="#item_close"><code>close () on unopened filehandle %s</code></a></a></h2> <dl> <dt><strong><a ...

mod_perl headers_in not working

I'm using mod_perl 2 with Apache 2.2.3 on Red Hat 5.2, and I'm trying to access the request headers, but the Apache2::RequestRec headers_in method (or rather, its return value) is not behaving the way I would expect. Code fragment: $logger->warn('version ' . $mod_perl::VERSION); $logger->warn('r ' . $r); my $headers = $r->headers_in; $...

How can I fill in web forms with Perl?

I want to fill in a web form with Perl. I am having trouble finding out the correct syntax to accomplish this. As in, how do I go to the URL, select the form, fill in the form, and then press enter to be sure it has been submitted? Any examples would be great. Thanks. ...

What is the best way to customise parts of an existing Perl program for multiple customers?

I have an existing Perl application which is deployed to multiple customer sites. Unfortunately, the code has been cloned multiple times to customise it for individual customers. So there are now several complete copies of the code which all have slight (or major) differences. My task is to fix this mess by creating a single, generic co...

How can I verify that a value is present in an array (list) in Perl?

I have a list of possible values: @a = qw(foo bar baz); How do I check in a concise way that a value $val is present or absent in @a? An obvious implementation is to loop over the list, but I am sure TMTOWTDI. Thanks to all who answered! The three answers I would like to highlight are: The accepted answer - the most "built-in" ...

Why is Perl's GD::Graph complaining about "Invalid data set"?

Hi I am writing a small program in Perl for my assignment and I am new to Perl. Code that I have written provides me with exactly the same values I need, but I am getting this error while creating bar chart. Invalid data set: 0 at line 67 Line 67 is marked with a comment in the code below. The values stored in x-axis are: 40 44 48...

How can I create an anonymous hash from an existing hash in Perl?

Hello, How can I create an anonymous hash from an existing hash? For arrays, I use: @x = (1, 2, 3); my $y = [@x]; but I can't find how to do the same for a hash: my %x = (); my $y = ???; Thanks ...

How can I retrieve SQL field names of a temp table using Perl?

Below is the code I'm using to run the query, parse the result set, and parse the rows (respectively) $exec_ret = $DBS->SQLExecSQL($STMT); while ($DBS->SQLFetch() == *PLibdata::RET_OK) { $rowfetch = $DBS->{Row}->GetCharValue($colname[$i]); } Can I grab the column/field name of a temp table using similar syntax? $colname[$i] is...

Can I create a table (if not exists) from Rose::DB::Object metadata?

I'm having trouble finding it in the CPAN documentation -- is there a way to create a table (IF NOT EXISTS) from manually-entered Rose::DB::Object metadata? I'm using SQLite as an engine, if it happens to matter. Thanks! ...

Why does my Parse::RecDescent give me all these warnings and errors?

Having a lot of pain with the following Perl file parsing code [last reply on PM @http://www.perlmonks.org/index.pl?node_id=754947] below: #!/usr/bin/perl -w use strict; use warnings; #use diagnostics; use Parse::RecDescent; use Data::Dumper; # Enable warnings within the Parse::RecDescent module. $::RD_ERRORS = 1; # Make sure the pa...

How can I differentiate between 0 and whitespace in Perl?

Hello, I have the following piece of code in my program: $val = chr(someFunction()); if($val == " ") { #do something } elsif($val == 0) { #do something else } But whenever 0 is passed to $val, the if part executes instead of the elsif which I expect to get executed. How can I fix this? Thank You. ...

What is the modern way of creating an XS module from scratch?

I need to write an XS module for Perl. It is my understanding that h2xs is pretty much deprecated today, what is the preferred method for starting an XS module today? I looked at Module::Starter, but it only handles pure Perl modules. ...

How do I convert a date into epoch time in Perl?

Solaris 10 doesn't seem to like me a lot. I am trying to run a simple script to accept date and return epoch of that date: #!/usr/bin/perl -w use strict; use Time::ParseDate; my $date1 = "Mon Mar 27 05:54:08 CDT 2009"; #Convert to seconds since start of epoch my $time1 = parsedate($date1); print $time1; Works perfectly fine on RHEL ...

Sending Messages to Squid Proxy Users.

Is it possible to send custom HTML messages to users when they first start a session through a squid proxy server? I want to be able to redirect a users first request to the "message of the Day".... then the rest of their browsing requests for the remainder of the session go without being redirected..... Detailed Steps: User o...

How can my Perl script find its module in the same directory?

I recently wrote a new Perl script to kill processes based on either process name / user name and extended it using Classes so that I could reuse the process code in other programs. My current layout is - /home/mutew/src/prod/pskill <-- Perl script /home/mutew/src/prod/Process.pm <-- Package to handle process descriptions I ad...

How do I add text to graph in Perl's GD::Graph?

I am drawing a graph using GD::Graph module in Perl. I can draw the graph fine but in the drawn image I want to add some text around the top of the drawn graph image. Basically just want to add some text to this drawn image. However, I don't see an option to do that. Does someone know if this is doable? ...

Matched elements using regex in Perl

I have a hash which contains a regular expression: the number of matches to be captured in it and variables and their position of match. For example: my %hash = ( reg_ex => 'Variable1:\s+(.*?)\s+\n\s+Variable2:\s+(.*?)\s+\n', count => 2, Variable1 => 1, Variable2 => 2, ); I am going to use this regex in some other par...

How do I add a multidimensional array (AoA) to Excel using Perl?

I want to add my data stored in 2x2 dimension array in Excel using Perl. I know how to open and add simple data. This I can do using for loop. But how can I do it elegantly? This is what I am trying to do $sheet->Range("A1:B"."$size")->{Value} = @$data; or @data; ...

How can I export all subs in a Perl package?

I would like to expose all subs into my namespace without having to list them one at a time: @EXPORT = qw( firstsub secondsub third sub etc ); Using fully qualified names would require bunch of change to existing code so I'd rather not do that. Is there @EXPORT_ALL? I think documentation says it's a bad idea, but I'd like to do it a...