Perl

How to remove line break in perl?

$line =~s/\n//g;

s - search and replace
\n - line break
g- replace all the occurrence of \n

htmldoc : Convert Html file to PDF

htmldoc helps to convert the hyper-text markup language files and webpages to PDF, postscript files.

How to use this in Unix / Linux

1. Download htmldoc and install it in unix / linux system.
2. Get ready with input html / web page file
3. Use command
htmldoc/bin/htmldoc_path --landscape --top --right 0 left 7mm --bottom --fontsize 10.0 --webpage -f outputfilename inputfilename

To use this in perl running in linux / unix box

Just pass on parameters and execute this command using system command in perl

You can download this from htmldoc.org

How to send mail in perl?

Install cpan module MIME::Lite

use MIME::Lite;

if (my $mimemsg = MIME::Lite->new(from=>'sasikala.chinnasamy@gmail.com', to=>'admin@itechp2pexchange.com', subject =>'test mail',type=> 'text/plain', data=>'test msg', encoding=>'8bit'))
{
MIME::Lite->send('smtp',$smtpmailserver);
$mimemsg->send("sendmail", '/usr/lib/sendmail -t -oi -oem');
}

If you want to attach file then

if (my $mimemsg = MIME::Lite->new(from=>'sasikala.chinnasamy@gmail.com', to=>'admin@itechp2pexchange.com', subject =>'test mail',type=> 'text/plain', data=>'test msg', encoding=>'8bit'))
{
$mimemsg->attach(type=>'application/octet-stream',encoding=>'base64',
path=>'/tmp/test.pdf', filename=>'test.pdf');

MIME::Lite->send('smtp',$smtpmailserver);
$mimemsg->send("sendmail", '/usr/lib/sendmail -t -oi -oem');
}
more details refer http://search.cpan.org/~rjbs/MIME-Lite-3.028/lib/MIME/Lite.pm

one of my application running in apache and created using perl. When i view the pages in Internet Explorer, it shows the web pa

I checked the script, it is perfect passing the headers text/html. The page displays like
<html>
<title>add new trip</title>
<body>
...
</body>
</html>

finally i got this solution:

In apache, i have changed the DefaultType as text/html, so it start displaying page correctly.

DefaultType text/html

Perl : How to print the content to error log?

Use STDERR to push the content to error log.

For example, you want to print you are in particular module.

sub process{
my ($id,$parent) = @_;
print STDERR "Inside process";

.....
}

Are you using STDERR for debugging? Instead use Log4perl cpan module for debugging.

Perl : How to remove the special characters like (-, :, . from given sentence or word)?

my $text = "I : have - many .ideas::";
$text=~s/[^\w\d]//g

It will remove all characters other than alphabets, numbers and _

Syndicate content