RE: DBI / loop

2002-11-14 Thread Bob Showalter
> -Original Message-
> From: Sven Bentlage [mailto:root@;svenbentlage.de]
> Sent: Thursday, November 14, 2002 2:43 PM
> To: [EMAIL PROTECTED]
> Subject: DBI / loop
> 
> 
> Hi everyone!
> 
> I have a small problem which should be very easy to solve, but right 
> now I just do not understand where the mistake is:
> I`m using a small loop to fetch several hundred ids from a MySQL 
> database, all of the ids are pushed into @id. After that the script 
> fetches 1-3 email addresses for each id from another table. Directly 
> after fetching the address it should send an email to each id (using 
> only one of the max. 3 email addresses.
> 
> The script works not completely. It fetches all ids, but 
> sends only 50% 
> of the mails... and I do not understand why.(The code is 
> posted below.)
> 
> If anyone could give me a tip what to change in ma script, I would be 
> really grateful.
> Cheers,
> Sven
> 
> @Wiggins: Thank you very much  for your fast help! As soon as 
> I have a 
> working DBI Version i`ll post it.
> 
> ###
> 
> foreach $id(@id)
>   {
>   $k++;
>   my $dbh2 = DBI->connect( $dsn, $db_user, $db_pass ) || 
> die "danger 
> $DBI::errstr\n" ;
>   my $sth2 = $dbh2->prepare( "select etpa_cont_e, 
> cemail, pemail from 
> memberscopy where id='$id' " );
>   $sth2->execute();
>   while ( ($cont_e, $cemail, $pemail) = 
> $sth2->fetchrow_array)
>   {
>   
>   unless ($ETPA_cont_e eq "") { 
> $recipient = $ETPA_cont_e }
>   else {
>   if ($pemail ne "") { $recipient 
> = $pemail }
>   elsif ($cemail ne "") { 
> $recipient = $cemail }
>   elsif (($pemail eq "") and 
> ($cemail eq "")) {$recipient = 
> "root\@svenbentlage.de"}
> 
>   my $smtp = Net::SMTP->new($SMTP_Server);
>   die "could not connect to $SMTP_Server 
> using $smtp\n" unless $smtp;
>   
>   MIME::Lite->send('smtp', "SMTP_Server", 
  ^
This looks suspicious. Perhaps that should be $SMTP_Server?
Also, why are you creating a Net::SMTP object that never gets
used?

> Timeout=>90); 
>   
>   
>   my $msg = MIME::Lite->new(
>   #To  => $recipient, 
>   To  =>'[EMAIL PROTECTED]',   
> #change to recipient
>   From =>'$sender,
>   ReplyTo => $reply_to,
>   Subject => $subject,
>   Type=>'multipart/related',
>   Encoding => '8bit'
>   );
>   
>   $msg->attach(Type => 'text/html',
> Data => qq{ $mailtext }
>   );
>   $msg->send();
>   
>   $smtp->dataend();
>   $smtp->quit();  
>   if ($k == 828) {die();} 
>   }
>   $sth2->finish();
>   $dbh2->disconnect();
>   
>   }
>   &thx();
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: DBI / loop

2002-11-14 Thread Sven Bentlage
I just replaced my actual server with "SMTP_SERVER",.


On Thursday, Nov 14, 2002, at 21:00 Europe/Berlin, Bob Showalter wrote:


-Original Message-
From: Sven Bentlage [mailto:root@;svenbentlage.de]
Sent: Thursday, November 14, 2002 2:43 PM
To: [EMAIL PROTECTED]
Subject: DBI / loop


Hi everyone!

I have a small problem which should be very easy to solve, but right
now I just do not understand where the mistake is:
I`m using a small loop to fetch several hundred ids from a MySQL
database, all of the ids are pushed into @id. After that the script
fetches 1-3 email addresses for each id from another table. Directly
after fetching the address it should send an email to each id (using
only one of the max. 3 email addresses.

The script works not completely. It fetches all ids, but
sends only 50%
of the mails... and I do not understand why.(The code is
posted below.)

If anyone could give me a tip what to change in ma script, I would be
really grateful.
Cheers,
Sven

@Wiggins: Thank you very much  for your fast help! As soon as
I have a
working DBI Version i`ll post it.

###

foreach $id(@id)
  {
  	$k++;
  	my $dbh2 = DBI->connect( $dsn, $db_user, $db_pass ) ||
die "danger
$DBI::errstr\n" ;
		my $sth2 = $dbh2->prepare( "select etpa_cont_e,
cemail, pemail from
memberscopy where id='$id' " );
		$sth2->execute();
		while ( ($cont_e, $cemail, $pemail) =
$sth2->fetchrow_array)
		{

			unless ($ETPA_cont_e eq "") {
$recipient = $ETPA_cont_e }
			else {
if ($pemail ne "") { $recipient
= $pemail }
elsif ($cemail ne "") {
$recipient = $cemail }
elsif (($pemail eq "") and
($cemail eq "")) {$recipient =
"root\@svenbentlage.de"}

			my $smtp = Net::SMTP->new($SMTP_Server);
			die "could not connect to $SMTP_Server
using $smtp\n" unless $smtp;
			
			MIME::Lite->send('smtp', "SMTP_Server",

  ^
This looks suspicious. Perhaps that should be $SMTP_Server?
Also, why are you creating a Net::SMTP object that never gets
used?


Timeout=>90);	

			
			my $msg = MIME::Lite->new(
			#To  => $recipient,
			To	=>'[EMAIL PROTECTED]',	
#change to recipient
			From	 =>'$sender,		
			ReplyTo => $reply_to,
			Subject => $subject,
			Type=>'multipart/related',
			Encoding => '8bit'
			);
			
			$msg->attach(Type => 'text/html',
  Data => qq{ $mailtext }
			);
			$msg->send();
			
			$smtp->dataend();
			$smtp->quit();			
		if ($k == 828) {die();}	
		}
		$sth2->finish();
		$dbh2->disconnect();
		
  }
  &thx();


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: DBI / loop

2002-11-14 Thread Bob Showalter
> -Original Message-
> From: Sven Bentlage [mailto:root@;svenbentlage.de]
> Sent: Thursday, November 14, 2002 2:43 PM
> To: [EMAIL PROTECTED]
> Subject: DBI / loop
> 
> 
> Hi everyone!
> 
> I have a small problem which should be very easy to solve, but right 
> now I just do not understand where the mistake is:
> I`m using a small loop to fetch several hundred ids from a MySQL 
> database, all of the ids are pushed into @id. After that the script 
> fetches 1-3 email addresses for each id from another table. Directly 
> after fetching the address it should send an email to each id (using 
> only one of the max. 3 email addresses.
> 
> The script works not completely. It fetches all ids, but 
> sends only 50% 
> of the mails... and I do not understand why.(The code is 
> posted below.)
> 
> If anyone could give me a tip what to change in ma script, I would be 
> really grateful.
> Cheers,
> Sven
> 
> @Wiggins: Thank you very much  for your fast help! As soon as 
> I have a 
> working DBI Version i`ll post it.
> 
> ###
> 
> foreach $id(@id)
>   {
>   $k++;
>   my $dbh2 = DBI->connect( $dsn, $db_user, $db_pass ) || 
> die "danger 
> $DBI::errstr\n" ;
>   my $sth2 = $dbh2->prepare( "select etpa_cont_e, 
> cemail, pemail from 
> memberscopy where id='$id' " );
>   $sth2->execute();
>   while ( ($cont_e, $cemail, $pemail) = 
> $sth2->fetchrow_array)
>   {
>   
>   unless ($ETPA_cont_e eq "") { 
> $recipient = $ETPA_cont_e }
>   else {
>   if ($pemail ne "") { $recipient 
> = $pemail }
>   elsif ($cemail ne "") { 
> $recipient = $cemail }
>   elsif (($pemail eq "") and 
> ($cemail eq "")) {$recipient = 
> "root\@svenbentlage.de"}
> 
>   my $smtp = Net::SMTP->new($SMTP_Server);
>   die "could not connect to $SMTP_Server 
> using $smtp\n" unless $smtp;
>   
>   MIME::Lite->send('smtp', "SMTP_Server", 
  ^
This looks suspicious. Perhaps that should be $SMTP_Server?
Also, why are you creating a Net::SMTP object that never gets
used?

> Timeout=>90); 
>   
>   
>   my $msg = MIME::Lite->new(
>   #To  => $recipient, 
>   To  =>'[EMAIL PROTECTED]',   
> #change to recipient
>   From =>'$sender,
>   ReplyTo => $reply_to,
>   Subject => $subject,
>   Type=>'multipart/related',
>   Encoding => '8bit'
>   );
>   
>   $msg->attach(Type => 'text/html',
> Data => qq{ $mailtext }
>   );
>   $msg->send();
>   
>   $smtp->dataend();
>   $smtp->quit();  
>   if ($k == 828) {die();} 
>   }
>   $sth2->finish();
>   $dbh2->disconnect();
>   
>   }
>   &thx();
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Another Hash ref question

2002-11-14 Thread T. Murlidharan Nair
I am writing this  as part of a module, so it prints fine in the main 
but not in
the method...
Any suggestions .

sub new{

while (my $hashRef = $sth->fetchrow_hashref()) {

   foreach $keys(keys %$hashRef){

   $self->{'_colData'}{$keys}=$$hashRef{$keys};

  print "$self->{'_colData'}{$keys}\n"; # IT PRINTS FINE HERE 
   #print "$keys\t";
   #print "$$hashRef{$keys}\n";

}

  }
}


sub dump{
   my $self = shift;

   my ($keys, $n_col, $n_row);

   foreach $keys(keys (%{$self->{'_colData'}})){
  
   print $self->{'_colData'}{$keys};  IT IS NOT DOING IT HERE, I CALLING THE METHODS PROPERLY
  }
  my $getchar =<>;

}

	
Thanks and cheers always!!
Murli






--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



DBI / loop

2002-11-14 Thread Sven Bentlage
Hi everyone!

I have a small problem which should be very easy to solve, but right 
now I just do not understand where the mistake is:
I`m using a small loop to fetch several hundred ids from a MySQL 
database, all of the ids are pushed into @id. After that the script 
fetches 1-3 email addresses for each id from another table. Directly 
after fetching the address it should send an email to each id (using 
only one of the max. 3 email addresses.

The script works not completely. It fetches all ids, but sends only 50% 
of the mails... and I do not understand why.(The code is posted below.)

If anyone could give me a tip what to change in ma script, I would be 
really grateful.
Cheers,
Sven

@Wiggins: Thank you very much  for your fast help! As soon as I have a 
working DBI Version i`ll post it.

###

foreach $id(@id)
 {
 	$k++;
 	my $dbh2 = DBI->connect( $dsn, $db_user, $db_pass ) || die "danger 
$DBI::errstr\n" ;
		my $sth2 = $dbh2->prepare( "select etpa_cont_e, cemail, pemail from 
memberscopy where id='$id' " );
		$sth2->execute();
		while ( ($cont_e, $cemail, $pemail) = $sth2->fetchrow_array)
		{

			unless ($ETPA_cont_e eq "") { $recipient = $ETPA_cont_e }
			else {
if ($pemail ne "") { $recipient = $pemail }
elsif ($cemail ne "") { $recipient = $cemail }
elsif (($pemail eq "") and ($cemail eq "")) {$recipient = 
"root\@svenbentlage.de"}

			my $smtp = Net::SMTP->new($SMTP_Server);
			die "could not connect to $SMTP_Server using $smtp\n" unless $smtp;
			
			MIME::Lite->send('smtp', "SMTP_Server", Timeout=>90);	

			
			my $msg = MIME::Lite->new(
			#To  => $recipient,
			To	=>'[EMAIL PROTECTED]',	#change to recipient
			From	 =>'$sender,		
			ReplyTo => $reply_to,
			Subject => $subject,
			Type=>'multipart/related',
			Encoding => '8bit'
			);
			
			$msg->attach(Type => 'text/html',
  Data => qq{ $mailtext }
			);
			$msg->send();
			
			$smtp->dataend();
			$smtp->quit();			
		if ($k == 828) {die();}	
		}
		$sth2->finish();
		$dbh2->disconnect();
		
 }
 &thx();


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: fetchrow_hashref

2002-11-14 Thread wiggins
See inline comments.



On Thu, 14 Nov 2002 11:22:09 -0800, "T. Murlidharan Nair" <[EMAIL PROTECTED]> wrote:

> Hi!!
> I am retriving data in a while loop using fetchrow_hashref
> How do I assign it to another hash.  I am trying the following
>  

In the below line of code you are trying to catch your fetchrow_hashref into a hash 
rather than a scalar. 

> while (my %hashRef =$sth->fetchrow_hashref()){
  while (my $hashRef = $sth->fetchrow_hashref()) {

Then you can derefernce $hashRef:

> foreach $keys (keys %hashRef){
  foreach $keys (keys %$hashRef) {

> print $keys;
> print "$hashRef{$keys}\t";
  print "$hashRef->{$keys}\n";


> }
> print "\n";
> }
> 
> Its  does not return me anything. Please let me know if there is a  better
> way to handle it.
> 
> Thanks and cheers always!!
> Murli
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: fetchrow_hashref

2002-11-14 Thread Bob Showalter
> -Original Message-
> From: T. Murlidharan Nair [mailto:nair@;sdsc.edu]
> Sent: Thursday, November 14, 2002 2:22 PM
> To: [EMAIL PROTECTED]
> Subject: fetchrow_hashref
> 
> 
> Hi!!
> I am retriving data in a while loop using fetchrow_hashref
> How do I assign it to another hash.  I am trying the following
>  
> while (my %hashRef =$sth->fetchrow_hashref()){

fetchrow_hasref returns a hash reference, which is a scalar.
You need to assign it to a scalar and dereference it.

Using -w would have generated a warning about this.

> foreach $keys (keys %hashRef){
> print $keys;
> print "$hashRef{$keys}\t";
> }
> print "\n";
> }
> 
> Its  does not return me anything. Please let me know if there 
> is a  better
> way to handle it.

Try something like this:

   while (my $h = $sth->fetchrow_hashref) {
   for my $key (keys %$h) {
  print $key, '=', $h->{$key}, "\n";
   }
   }

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




fetchrow_hashref

2002-11-14 Thread T. Murlidharan Nair
Hi!!
I am retriving data in a while loop using fetchrow_hashref
How do I assign it to another hash.  I am trying the following

   while (my %hashRef =$sth->fetchrow_hashref()){
   foreach $keys (keys %hashRef){
   print $keys;
   print "$hashRef{$keys}\t";
   }
   print "\n";
}

Its  does not return me anything. Please let me know if there is a  better
way to handle it.

Thanks and cheers always!!
Murli



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Weekly list FAQ posting

2002-11-14 Thread Christopher G Tantalo
I have noticed that ever since I have signed up for numerous different perl
mailing lists, I have been getting unwanted emails.  Funny thing is, I am 100%
sure my address has been snarfed from one of these mailing lists due to the fact
that we are denied net access here at work.   So whatever can be done in the
future to hide these will be a good thing, but a little late for us already
flushed out.
Chris
--
---
Just Your Friendly Neighborhood
_SPIDEY_



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: Weekly list FAQ posting

2002-11-14 Thread Peter Kappus
Hi Casey et al,

Thanks for the useful information!  I was just noticing that all of our
email addresses are available as-is on the discussion archives
(http://archive.develooper.com/beginners-cgi%40perl.org/) where they could
easily be harvested by evil spam-bots and used to send us junk.

Do you think it would be possible to either hide our addresses completely or
protect them with some manner of "text-armor" (a la slashdot perhaps?
peter[dot]kappus[at]corbis[dot]com, etc.)

I see that we're using MHonArc for our list archiving and it doesn't seem to
support such a feature.  So we may need to hack something onto the existing
system.  If it's a resources issue, I'm happy to help out however I can...

Does anybody else share these concerns or have other approaches for a
solution?  I suspect everybody on the perl.org lists is susceptible to
having their email sucked up and sold...

Many thanks and happy coding,

-Peter


-Original Message-
From: [EMAIL PROTECTED] [mailto:casey@;geeknest.com]
Sent: Thursday, November 14, 2002 5:00 AM
To: [EMAIL PROTECTED]
Subject: Weekly list FAQ posting

  1.4 - Is there an archive on the web?

Yes, there is. It is located at:

http://archive.develooper.com/beginners-cgi%40perl.org/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Weekly list FAQ posting

2002-11-14 Thread casey
NAME
beginners-faq - FAQ for the beginners-cgi mailing list

1 -  Administriva
  1.1 - I'm not subscribed - how do I subscribe?

Send mail to <[EMAIL PROTECTED]>

You can also specify your subscription email address by sending email to
(assuming [EMAIL PROTECTED] is your email address):

<[EMAIL PROTECTED]>.

  1.2 -  How do I unsubscribe?

Now, why would you want to do that? Send mail to
<[EMAIL PROTECTED]>, and wait for a response. Once you
reply to the response, you'll be unsubscribed. If that doesn't work,
find the email address which you are subscribed from and send an email
like the following (let's assume your email is [EMAIL PROTECTED]):

<[EMAIL PROTECTED]>

  1.3 - There is too much traffic on this list. Is there a digest?

Yes. To subscribe to the digest version of this list send an email to:

<[EMAIL PROTECTED]>

To unsubscribe from the digest, send an email to:

<[EMAIL PROTECTED]>

  1.4 - Is there an archive on the web?

Yes, there is. It is located at:

http://archive.develooper.com/beginners-cgi%40perl.org/

  1.5 - How can I get this FAQ?

This document will be emailed to the list once a month, and will be
available online in the archives, and at http://beginners.perl.org/

  1.6 - I don't see something in the FAQ, how can I make a suggestion?

Send an email to <[EMAIL PROTECTED]> with your suggestion.

  1.7 - Is there a supporting website for this list?

Yes, there is. It is located at:

http://beginners.perl.org/

  1.8 - Who owns this list?  Who do I complain to?

Casey West owns the beginners-cgi list. You can contact him at
[EMAIL PROTECTED]

  1.9 - Who currently maintains the FAQ?

Kevin Meltzer, who can be reached at the email address (for FAQ
suggestions only) in question 1.6

  1.10 - Who will maintain peace and flow on the list?

Casey West, Kevin Meltzer and Ask Bjoern Hansen currently carry large,
yet padded, clue-sticks to maintain peace and order on the list. If you
are privately emailed by one of these folks for flaming, being
off-topic, etc... please listen to what they say. If you see a message
sent to the list by one of these people saying that a thread is closed,
do not continue to post to the list on that thread! If you do, you will
not only meet face to face with a XQJ-37 nuclear powered pansexual
roto-plooker, but you may also be taken off of the list. These people
simply want to make sure the list stays topical, and above-all, useful
to Perl/CGI beginners.

  1.11 - When was this FAQ last updated?

Sept 07, 2001

2 -  Questions about the 'beginners-cgi' list.
  2.1 - What is the list for?

A list for beginning Perl programmers to ask questions in a friendly
atmosphere. The topic of the list is, of course, CGI with Perl.

  2.2 - What is this list _not_ for?

* SPAM
* Homework
* Solicitation
* Things that aren't Perl related
* Non Perl/CGI questions or issues
* Lemurs
  2.3 - Are there any rules?

Yes. As with most communities, there are rules. Not many, and ones that
shouldn't need to be mentioned, but they are.

* Be nice
* No flaming
* Have fun
  2.4 - What topics are allowed on this list?

Basically, if it has to do with Perl/CGI , then it is allowed. If your
question has nothing at all to do with Perl/CGI, it will likely be
ignored.

  2.5 - I want to help, what should I do?

Subscribe to the list! If you see a question which you can give an
idiomatic and Good answer to, answer away! If you do not know the
answer, wait for someone to answer, and learn a little.

  2.6 - Is there anything I should keep in mind while answering?

We don't want to see 'RTFM'. That isn't very helpful. Instead, guide the
beginner to the place in the FM they should R :)

  2.7 - I don't want to post a question if it is in an FAQ. Where should I
look first?

Look in the FAQ! Get acquainted with the 'perldoc' utility, and use it.
It can save everyone time if you look in the Perl FAQs first, instead of
having a list of people refer you to the Perl FAQs :) You can learn
about 'perldoc' by typing:

"perldoc perldoc"

At your command prompt. You can also view documentation online at:

http://www.perldoc.com and http://www.perl.com

3 - Other Resources
  3.1 - What other websites may be useful to a beginner ?

* Perl Home Page - http://www.perl.com
* PerlMonks - http://www.perlmonks.org
* Perldoc - http://www.perldoc.com
* Perl Archives - http://www.perlarchives.com
  3.2 - What resources may be harmful to a beginner?

Beware of Perl4-like code-- You might find some script archives and
unauthorized mirrors with old Perl4 versions of Selena Sol and Matt
Wright scripts. Don't use those scripts. They are outdated and may even
in some cases contain bugs or security problems since many may not have
been u