perl

How can I tell if a C struct has a member in Perl XS?

Is there an ExtUtils::* or Module::Build (or other) analog to Ruby's mkmf.have_struct_member? I'd like to do something like (in the manner of a hints/ file): .... if struct_has_member("msghdr", "msg_accrights") { $self->{CCFLAGS} = join(' ', $self->{CCFLAGS}, "-DTRY_ACCRIGHTS_NOT_CMSG"); } ... Config.pm doesn't track the spec...

How do I fix Perl's Font::FreeType compilation errors?

I am trying to install the Perl module Font::FreeType on a CentOS linux box using cpan. I run sudo cpan and inside the cpan shell I run install Font::FreeType. However make fails as follows: Writing Makefile for Font::FreeType cp lib/Font/FreeType.pm blib/lib/Font/FreeType.pm cp lib/Font/FreeType/Face.pm blib/lib/Font/FreeType/Face.pm c...

Why does my Perl script keep reading from same file, even though I closed it?

Hi, I'm writing this Perl script that gets two command line arguments: a directory and a year. In this directory is a ton of text files or html files(depending on the year). Lets say for instance it's the year 2010 which contains files that look like this <number>rank.html with the number ranging from 2001 to 2212. I want it to open e...

How can I encode a string for HTML?

Looking for a simple way to HTML encode a string/object in perl. the least amount of additional packages used the better. ...

Perl DBIx::Class - Default Values when using new()?

When using the new() method on a DBIx::Class ResultSource to create a (potentially temporary) variable, it doesn't seem to populate attributes with the default values specified in the DBIC schema (which we have specified for creating tables from that schema). Currently, we are creating one default value for one such class (the first cas...

How can I run Perl on web servers?

I am very new to Perl and I wonder how to run it on webservers and all. (or if it can) ...

How can I match mixed whitespace and () in Perl?

How do I improve my Perl regex to handle the __DATA__ below? my ($type, $value) =~ /<(\w+)\s+(.*?)\(\)>/; __DATA__ <dynamic DynamicVar> <dynamic DynamicVar > # not need attache the blackspace to $value when return <dynamic DynamicFun()> <dynamic DynamicFun() > # not need attache the blackspace to $value when return I want to return...

How can I append the file foo2.txt to foo1.txt?

Hi. Is there any method to execute foo2.pl from foo1.pl in Perl, and append the foo2.txt to the foo1.txt then create foo3.txt? thanks. i.e. foo1.pl print "Hello"; # output to foo1.txt; foo2.pl print "World"; # output to foo2.txt; How to create foo3.txt file based on foo1.pl. foo3.txt Hello World Something like append foo2....

How can I match strings that don't match a particular pattern in Perl?

I know that it is easy to match anything except a given character using a regular expression. $text = "ab ac ad"; $text =~ s/[^c]*//g; # Match anything, except c. $text is now "c". I don't know how to "except" strings instead of characters. How would I "match anything, except 'ac'" ? Tried [^(ac)] and [^"ac"] without success. Is it ...

How can I select records from a CSV file based on timestamps in Perl?

I have CSV file which has timestamp in the first column as shown below sample: Time,head1,head2,...head3 00:00:00,24,22,...,n 00:00:01,34,55,...,n and so on... I want to filter out the data with specific time range like from 11:00:00 to 16:00:00 with the header and put into an array. I have written the below code to get the header in ...

How can I share global values among different packages in Perl?

Is there a standard way to code a module to hold global application parameters to be included in every other package? For instance: use Config;? A simple package that only contains our variables? What about readonly variables? ...

How do I catch a connection failure to a nonexistant Rose::DB database?

My Perl application uses Rose::DB, Rose::DB::Object (ORM) and Tk on Windows XP. I need to check whether the database connection information (host, port, database name, user, password) leads to a valid connection. If I call $db->connect and use e.g. a nonexistant host for testing, Rose::DB says: DBI connect('dbname=my_db;host=192.168.70.8...

Why doesn't wxPerl draw my wxStaticBitmap when I run the program from a Windows shortcut?

I've made a wxPerl application which presents just a simple frame which only contains a wxMenuBar, wxPanel, wxTextCtrl and a wxStaticBitmap. The development and deployment platform is Windows XP and beyond. The image is added to the form like this: my $logoData = Wx::Bitmap->new(App::Resource::Images::getLogoPath(), wxBITMAP_TYPE_BMP);...

Why does installing DBD::Pg fail in DynaLoader?

Error: Can't load '/home/oracle/.cpan/build/DBD-Pg-2.16.1/blib/arch/auto/DBD/Pg/Pg.so' for module DBD::Pg: libpq.so.5: cannot open shared object file: No such file or directory at /usr/lib/perl5/5.8.8/i386-linux-thread-multi/DynaLoader.pm line 230. Did anyone have similar error while instaling DBD::Pg perl module ? what can I do to fi...

How can I merge two XML files in Perl?

UPDATE: Let me go into more details (as requested) I have 2 Perl files, the first one generates a XML request/POST (No file is made). The second file is new and intended to add another element inside of the XML on certain conditions. The problem I'm having is the first file already checks for the conditions but the second file is need...

How do I make the 32-bit Perl read the 64-bit Windows registry?

I have a 32-bit perl installer. Using this I need to be able to install and uninstall both 32- and 64-bit applications. Installing 32- and 64-bit is fine. Uninstalling 32-bit is also ok. However, I have a problem while uninstalling 64-bit applications. The application just knows the name of the application as seen in Add Remove progra...

Converting hexadecimal numbers in strings to negative numbers, in Perl

I have a bunch of numbers represented as hexadecimal strings in logfiles that are being parsed by a Perl script, and I'm relatively inexperienced with Perl. Some of these numbers are actually signed negative numbers, ie 0xFFFE == -1 when represented as a 16-bit signed integer. Can somebody please tell me the canonical way of getting the...

How can I get up to speed about Perl's latest object-oriented capabilities?

I have not done Perl for about 8 years and now I'm going into project that's heavily utilizing object-oriented Perl so I need to resharpen my Perl skills and do it quickly. During these past years I mainly did all sorts of Java development and some PHP. I'm very good at OO and I'm not a novice programmer by any remote extent. So here c...

Does python have the equivalent of Perl's regex "local" variable?

While searching for a solution to a python regular expression problem I found this page which demonstrates that [some version of] perl allows variables within regular expressions. e.g. a perl regex something like: ^(?{ local $d=0}\((?{ $d++ }.*?\)(?d--) Where variable $d is incremented and decremented depending on which part of the ...

How can I count overlapping substrings in Perl?

i need to implement a program to count the occurrence of a substring in a string in perl. i have implemented it as follows sub countnmstr { $count =0; $count++ while $_[0] =~ /$_[1]/g; return $count; } $count = countnmstr("aaa","aa"); print "$count\n"; now this is what i would normally do. however, in the implementation above ...