perl

redirect or pipe file to standard out

How do u redirect a small(<20k) file to be piped to another program, so that it is never written to disc. You could use cfront and gcc as an example. Any example will do as long as you are redirecting something that normally outputs a file to something that usually accepts a file. You could could use any script or shell, but I would pr...

Is there a tutorial for Ruby programmers who want to learn Perl?

I'm a Ruby developer (bioinformatics analysis, haven't done Ruby on Rails for a couple of years), and in my spare time I've been given responsibility for a very simple Perl-based website. Although there are plenty of resources that teach Perl, I'm hoping for something aimed at Ruby programmers, so that I can take advantage of the simila...

How to answer a 501 Exception from Apache without Response Header?

I need to access the header to implement methods for a self written client on a mobile phone. The page should be accessible from J2ME without complete Request/Response Headers (Uses less traffic. For Example: J2ME sends only "G i\r\n\r\n"). Is there a way to get this working? (no matter how) ...

Can I pass arguments to the compare subroutine of sort in Perl?

I'm using sort with a customized comparison subroutine I've written: sub special_compare { # calc something using $a and $b # return value } my @sorted = sort special_compare @list; I know it's best use $a and $b which are automatically set, but sometimes I'd like my special_compare to get more arguments, i.e.: sub special_compare...

perl dbi : fetchrow_arrayref

Hi all , Actually I have executed the postgres query, assume that it has return the 10 rows. Now I am having that's statement handler ( $sth ) . print Dumper $sth->fetchrow_arrayref; print Dumper $sth->fetchrow_arrayref; print Dumper $sth->fetchrow_arrayref; print Dumper $sth->fetchrow_arrayref; print Dumper $sth->fetchrow_arrayref;...

How should I define a Moose object subroutine after its initialization?

How should I define a Moose object subroutine after its initialization? I'm writing an object module using Moose and I plan to serialize (nstore) the created objects. Examine the following (simplified!) example: package MyObj 0.001; use Moose; use namespace::autoclean; has 'size' => ( is => 'ro', isa => 'Int', required...

How can I flexibly add data to Moose objects?

I'm writing a module for a moose object. I would like to allow a user using this object (or myself...) add some fields on the fly as he/she desires. I can't define these fields a priori since I simply don't know what they will be. I currently simply added a single field called extra of type hashref which is is set to rw, so users can s...

How can I create internal Moose object variables?

I would like some attributes (perhaps this is the wrong term in this context) to be private, that is, only internal for the object use - can't be read or written from the outside. For example, think of some internal variable that counts the number of times any of a set of methods was called. Where and how should I define such a variabl...

Perl MySQL - How do I skip updating or inserting a row if a particular field matches?

I am pretty new to this so sorry for my lack of knowledge. I set up a few tables which I have successfully written to and and accessed via a Perl script using CGI and DBI modules thanks to advice here. This is a member list for a local band newsletter. Yeah I know, tons of apps out there but, I desire to learn this. 1- I wanted to avo...

Do all my Moose classes have to contain 'namespace::autoclean' and 'make_immutable' or is there some way to get these by default?

According to the Moose best practices doc, my Moose classes should look like this: package Person; use Moose; use namespace::autoclean; # extends, roles, attributes, etc. # methods __PACKAGE__->meta->make_immutable; 1; See Moose::Manual::BestPractices. And 99% of the time this is what I want, so is there some way to have my name...

How can I fill N x M grid efficiently with Perl?

I have a Perl script, which parses datafile and writes 5 output files filled with 1100 x 1300 grid. The script works, but in my opinion, it's clumsy and probably non-efficient. The script is also inherited code, which I have modified a little to make it more readable. Still, it's a mess. At the moment, the script reads the datafile(~4Mb...

When should I use `use`?

As long as I can remember, whenever I use a module I include a use line at the beginning of my code. Recently I was writing two Moose object modules that use each other. Look at this over-simplistic example: One module: package M1 0.001; use Moose; use 5.010; use namespace::autoclean; # use M2; ### SEE QUESTION BELOW has 'name' => ...

How do I install a CPAN module site-wide while local::lib is present?

I've recently set up a new system and wanted to install Padre to check it out. The Padre install instructions specifically said to install local::lib, so I did so (although I've never had need of it before). I then went on my way installing several other modules, running CPAN from my normal user account with sudo to handle the root-req...

Converting CruiseControl to Hudson

Hello Everyone, I am currently writing a Perl script that will convert CruiseControl config.xml files to a Hudson config.xml for each project. However I am stuck at one key part: How do I make it so the sub modules of a project also get the goals from there CC config? I can do the root module fine, and set up the configurations fine as...

How can I add entity declarations via XML::Twig programmatically?

For the life of me I cannot understand the XML::Twig documentation for entity handling. I've got some XML I'm generating with HTML::Tidy. The call is as follows: my $tidy = HTML::Tidy->new({ 'indent' => 1, 'break-before-br' => 1, 'output-xhtml' => 0, 'output-xml' => 1, 'char-encoding' => 'raw', }...

What is the role of the BEGIN block in Perl?

I know that the BEGIN block is compiled and executed before the main body of a Perl program. If you're not sure of that just try running the command perl -cw over this: #!/ms/dist/perl5/bin/perl5.8 use strict; use warnings; BEGIN { print "Hello from the BEGIN block\n"; } END { print "Hello from the END block\n"; } I have be...

How can I assign different actions to same html form ?

I am trying to assign different actions to same html form according to different submit buttons. Can I do something like this ? <FORM> ------ <INPUT type="submit" value="DoSomething" action="DoSomething.pl" method="POST"> <INPUT type="submit" value="DoSomethingElse" action="DoSomethingElse.pl" method="PO...

How to get rid of 'Name ... used only once: possible typo at ...' ?

use YAML::XS; local $YAML::XS::DumpCode=1; ... Name "YAML::XS::DumpCode" used only once: possible typo at .. Well, I know I can suppress this specific warning, but it's kind'a ugly. Am I doing anything wrong? I'm not used to be warned :) ...

Which recommended Perl modules can serialize Moose objects?

I was usually using Storable with nstore, but now I have a module that has CODE and apparently Storable doesn't like that. I found YAML (and YAML::XS which I can't really get to work). I also experimented a bit with MooseX::Storage without much success. Are there other alternatives? What would you recommend? ...

What is the correct way to add a utility module to a CPAN distribution?

I would like to factor out some of the stuff in Crypt::SSLeay's Makefile.PL into a couple of separate classes. These classes would only be used by Makefile.PL. As such, I do want them not to be indexed by the PAUSE indexer not to be installed as part of the module. Should I just put them in inc the way Module::Install does? What el...