Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to perl and having trouble

Status
Not open for further replies.

thack111

Programmer
Oct 16, 2002
8
US
Hello,
Please excuse me if this is a stupid question, but it is frustrating me, and I can't find any definate answers online. I am learning perl and need it to be able to do 3 simple things:

1 send email with attachments
2 talk to oracle
3 use expect

I have gotten all these to work!
My problem is, I can't get cpan to work normaly on windows, and I am having trouble getting my modules set up.

I upgraded to 5.8.1 just to find out DBD-Oracle dosen't work for that. so now I have gone back to 5.6.1 and now it can't find Mail-Sender I am useing ppm3-bin because I can't get CPAN to work like it does on linux. Can anyone tell me where to look next, or what I am doing wrong. The language seems pretty strong, but if it will be this much hassel to get set up mabye I need to look at a different language.

Any help would be greatly appreciated.
Todd
 
Hey Buddy,

Have you tryed using the PPM (if you have installed the ActiveState version of Perl)? IT's a great little system that will download and install Perl Modules for you.

Read the Active Perl user guide callled "using PPM", it'll help.

Good luck, and welcome to Perl!

Jiggy

 
Hi

Sending email with attachments:

example1. (Without Modules)

$filename="myfile.txt";
$email="dmazzini\@scom.com";

system("uuencode $filename $filename | mailx -s 'Title of the email' $email")


example2. (Using Mime::Lite)

use MIME::Lite;

### Create a new multipart message:
$msg = MIME::Lite->new(
From =>'me@myhost.com',
To =>'you@yourhost.com',
Cc =>'some@other.com, some@more.com',
Subject =>'A message with 2 parts...',
Type =>'multipart/mixed'
);

### Add parts (each "attach" has same arguments as "new"):
$msg->attach(
Type =>'TEXT',
Data =>"Here's the GIF file you wanted"
);
$msg->attach(
Type =>'image/gif',
Path =>'/usr/local/tmp/aaa000123.gif',
Filename =>'logo.gif'
);

$text = $msg->as_string;

## MIME::Lite also includes a method for sending these
## things.

$msg->send;

The "Path" attribute is the full path to the file you are sending.

The "Filename" attribute is the filename that will be displayed to the person who receives the email.

Connecting to oracle:

1. Example Without DBI Module:

open FH, "echo 'select name from objects where object_class=3 and name is not null and object_instance is not null;\n' \| sqlplus -s username/password|";
while(<FH>) {
$BSC = $_;
chomp($BSC);
$BSC = trim($BSC);
print "BSC: $BSC\n";
}


sub trim {
my @out = @_;
for (@out) {
s/^\s+//; # trim left
s/\s+$//; # trim right
}
return @out == 1
? $out[0] # only one to return
: @out; # or many
}

1. Example Using DBI Module:

use DBI;

# Initialise DBI Connection
printq ("Opening Database.\n");
unless ($dbh = DBI->connect('DBI:Oracle:',$database_username,$database_password, { RaiseError => 0, AutoCommit => 1})) {
die ("\n\nCould not open database. Exiting\n\n");
}

$sth = $dbh->prepare("select int_id, name, object_instance from objects where object_class = 3 and object_instance = '$bsc_id'");
$sth->execute();
while (@row = $sth->fetchrow_array()) {
$bsc_int = $row[0];
$bsc_name = $row[1];
$bsc_c_no = $row[2];
}
$sth->finish;
 
Thanks for the good information. I have tried the PPM, it works really well, but that is what is returning errors when I try to install my modules. I guess Oracle revoked there rights to compile the DBD-Oracle driver wich DBI uses, after perl version 5.6.1.

I will try the other ways mentioned to produce email and connect to Oracle. Thank you again for the information.

Todd
 


CPAN does work well on Windows, and its well worth the hassle, not all the modules are available under Activestate's repositories

Have a go, and enjoy
--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ... smack the fecker
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top