i nned ur help
HI , I'll give u my perl codeings . I need to add these out puts to a hash ( array ) , but now already i have added that into a normal array . Could u help me pull those results in to a hash . Actually i'm using perl . #! /usr/bin/perl -w use strict; use DBI; my ($dbh, $sth); #my @array_data; #my $counter = 0; $dbh = DBI-connect (DBI:mysql:SMSC;localhost,root,smsc) || die Error Opening DataBase: $DBI::errstr\n; print Successfully Connected \n ; $sth = $dbh-prepare(SELECT ServiceNo, ServicePort, ServiceString FROM SmsIndex;) || die Prepare failed: $DBI::errstr\n; $sth-execute() || die Unable to execute query: $DBI::errstr\n; my $matches=$sth-rows(); unless ($matches) { print Sorry, there r no matches\n; } else { print $matches matches found: \n; while (my @row = $sth -fetchrow_array) { print @row\n; [EMAIL PROTECTED] = @row; #$counter++; } } $sth-finish(); $dbh-disconnect || die Failed to disconnect\n; pls help me . Thanx chandana -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
RE: i nned ur help
Replace the commented lines with: Method 1 (with counter): @array_data = (); ... $array_data[$counter++] = @row; Method 2 (without counter): @array_data = (); # initialize it $array_data[$#array_data] = @row; # put the array into the array Method 3 (with hash) (I assume that u use ServiceNo as hash key): %array_data = (); $array_data{$row[0]} = @row; What is important to know: If you reference the whole array, you have prepend the variable with @ If you reference only one element in the array, you have to prepend $ For hashes, use % To print the whole new array, you could use: foreach @ad ( @array_data ) { foreach $elem ( @ad ) print $elem, ; print \n; } Have fun! /rudy -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: donderdag 10 juli 2003 10:43 To: [EMAIL PROTECTED] Subject: i nned ur help HI , I'll give u my perl codeings . I need to add these out puts to a hash ( array ) , but now already i have added that into a normal array . Could u help me pull those results in to a hash . Actually i'm using perl . #! /usr/bin/perl -w use strict; use DBI; my ($dbh, $sth); #my @array_data; #my $counter = 0; $dbh = DBI-connect (DBI:mysql:SMSC;localhost,root,smsc) || die Error Opening DataBase: $DBI::errstr\n; print Successfully Connected \n ; $sth = $dbh-prepare(SELECT ServiceNo, ServicePort, ServiceString FROM SmsIndex;) || die Prepare failed: $DBI::errstr\n; $sth-execute() || die Unable to execute query: $DBI::errstr\n; my $matches=$sth-rows(); unless ($matches) { print Sorry, there r no matches\n; } else { print $matches matches found: \n; while (my @row = $sth -fetchrow_array) { print @row\n; [EMAIL PROTECTED] = @row; #$counter++; } } $sth-finish(); $dbh-disconnect || die Failed to disconnect\n; pls help me . Thanx chandana -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
RE: i nned ur help
Instead of using arrays, try using hashes directly: ... while (my $hash = $sth-fetchrow_hashref) { while (my ($key, $value) = each(%{$hash})) { print $key = $value\n; } } ... On Thu, 2003-07-10 at 04:58, Rudy Metzger wrote: Replace the commented lines with: Method 1 (with counter): @array_data = (); ... $array_data[$counter++] = @row; Method 2 (without counter): @array_data = (); # initialize it $array_data[$#array_data] = @row; # put the array into the array Method 3 (with hash) (I assume that u use ServiceNo as hash key): %array_data = (); $array_data{$row[0]} = @row; What is important to know: If you reference the whole array, you have prepend the variable with @ If you reference only one element in the array, you have to prepend $ For hashes, use % To print the whole new array, you could use: foreach @ad ( @array_data ) { foreach $elem ( @ad ) print $elem, ; print \n; } Have fun! /rudy -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: donderdag 10 juli 2003 10:43 To: [EMAIL PROTECTED] Subject: i nned ur help HI , I'll give u my perl codeings . I need to add these out puts to a hash ( array ) , but now already i have added that into a normal array . Could u help me pull those results in to a hash . Actually i'm using perl . #! /usr/bin/perl -w use strict; use DBI; my ($dbh, $sth); #my @array_data; #my $counter = 0; $dbh = DBI-connect (DBI:mysql:SMSC;localhost,root,smsc) || die Error Opening DataBase: $DBI::errstr\n; print Successfully Connected \n ; $sth = $dbh-prepare(SELECT ServiceNo, ServicePort, ServiceString FROM SmsIndex;) || die Prepare failed: $DBI::errstr\n; $sth-execute() || die Unable to execute query: $DBI::errstr\n; my $matches=$sth-rows(); unless ($matches) { print Sorry, there r no matches\n; } else { print $matches matches found: \n; while (my @row = $sth -fetchrow_array) { print @row\n; [EMAIL PROTECTED] = @row; #$counter++; } } $sth-finish(); $dbh-disconnect || die Failed to disconnect\n; pls help me . Thanx chandana -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED] -- ,_, \ Ryan Yagatich [EMAIL PROTECTED] \ / Pantek Incorporated (877) LINUX-FIX / \ http://www.pantek.com/security(440) 519-1802 \ / Are your networks secure? Are you certain? / \___A9062F5C3EAE81D54A28A8C1289943D9EE43015BD8BC03F1___\ -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]