iowaprogrammer
ISP
I am trying to write a program to extract user info from a database and write them into a file. The
content of the field in the database I am calling can have one or more entries and are separated by a '|'. See sample data below...
user@domain|user2@domain|user3@domain
friend@domain
funny@domain|funny1@domain
lucy@domain|lueue@domain
So I am trying to use split with the '|' as the separator and then write the entry to a file like the following output below..
user@domain
user2@domain
user3@domain
friend@domain
funny@domain
funny1@domain
lucy@domain
lueue@domain
But what I get is only the first entry of each record like...
user@domain
friend@domain
funny@domain
lucy@domain
This is the code I have used so far
#!/usr/bin/perl -w
use Win32::ODBC;
my $DSN="Usermanager";
#my $SqlStatement = "SELECT Useremail FROM allusers where Useremail != ''";
my $SqlStatement = "SELECT Userothermailboxes FROM allusers where Userothermailboxes != ''";
my $user;
unless(open(OUTUSERS,'>c:\queryuserothermailboxes.txt'))
{
die("Can not open OUFILE\n");
exit;
}
if (!($db = new Win32::ODBC($DSN)))
{
print "Error connecting to $DSN\n";
print "Error: " . Win32::ODBC::Error() . "\n";
exit;
}
if ($db->Sql($SqlStatement)){
print "SQL failed.\n";
print "Error: " . $db->Error() . "\n";
$db->Close();
exit;
}
if (! $db->Sql($SqlStatement))
{ @FieldNames = $db->FieldNames();
$Cols = $#FieldNames + 1;
for ($i = 0; $i < $Cols; $i++)
{ print $FieldNames[$i], "\t";
}
print "\n";
}
while( $db->FetchRow()){
undef %Data;
($Data) = $db->Data();
$_=$Data;
print "$_\n";
@user=split(/\|/,$_);
# print OUTUSERS "$user\n";
foreach(@user){
{
print "$_\n";
}
}
}
$db->Close();
close OUTUSERS;
Thanks to all in advance
content of the field in the database I am calling can have one or more entries and are separated by a '|'. See sample data below...
user@domain|user2@domain|user3@domain
friend@domain
funny@domain|funny1@domain
lucy@domain|lueue@domain
So I am trying to use split with the '|' as the separator and then write the entry to a file like the following output below..
user@domain
user2@domain
user3@domain
friend@domain
funny@domain
funny1@domain
lucy@domain
lueue@domain
But what I get is only the first entry of each record like...
user@domain
friend@domain
funny@domain
lucy@domain
This is the code I have used so far
#!/usr/bin/perl -w
use Win32::ODBC;
my $DSN="Usermanager";
#my $SqlStatement = "SELECT Useremail FROM allusers where Useremail != ''";
my $SqlStatement = "SELECT Userothermailboxes FROM allusers where Userothermailboxes != ''";
my $user;
unless(open(OUTUSERS,'>c:\queryuserothermailboxes.txt'))
{
die("Can not open OUFILE\n");
exit;
}
if (!($db = new Win32::ODBC($DSN)))
{
print "Error connecting to $DSN\n";
print "Error: " . Win32::ODBC::Error() . "\n";
exit;
}
if ($db->Sql($SqlStatement)){
print "SQL failed.\n";
print "Error: " . $db->Error() . "\n";
$db->Close();
exit;
}
if (! $db->Sql($SqlStatement))
{ @FieldNames = $db->FieldNames();
$Cols = $#FieldNames + 1;
for ($i = 0; $i < $Cols; $i++)
{ print $FieldNames[$i], "\t";
}
print "\n";
}
while( $db->FetchRow()){
undef %Data;
($Data) = $db->Data();
$_=$Data;
print "$_\n";
@user=split(/\|/,$_);
# print OUTUSERS "$user\n";
foreach(@user){
{
print "$_\n";
}
}
}
$db->Close();
close OUTUSERS;
Thanks to all in advance