Archive

Posts Tagged ‘cgi’

How to search for pattern in a file and remove the previous 2 lines including the line with pattern ?

April 4, 2011 Leave a comment

How to search for the pattern in a file and remove the previous 2 lines including the line with pattern ?

#!/usr/local/bin/perl

my @buffer;
while ( ) {
if (!/pattern/) {
push @buffer, $_;
} else {
push @buffer, $_;
delete @buffer[-3..-1]; ## Remove 2 lines above including pattern!
}
}
print @buffer;

Categories: Perl, Perl - Examples Tags: ,

Perl Frameworks

April 4, 2011 Leave a comment

What’s the best way to write a CGI application in Perl?
Absolute answer is, using Perl Framework. There are many frameworks available with or without MVC architecture empowered. You can get a list with comparison in this link.

My personal choice is to go with CGI::Application since its very light-weight and easily maintainable. Templates can be designed using amazing perl module called HTML::Template. I found this framework magical mainly for AJAX calls using jQuery along with CGI-Application-Plugin-AutoRunmode module.
If you have existing perl code using CGI::Application and want to migrate the same to mod_perl environment, there is a CPAN module (CGI::Application::Plugin::Apache) available to do so.

You can refer to this tutorial to start using the CGI::Application. Enjoy coding!