in reply to Using hash elements to create a string
I believe that I have the SQL statment constructor that you were looking for. There are a few things to note about the code. The first is of course that you need at least two items in the hash (I think you knew that). The other is that I had to sort the hash keys to ensure the ordering. I don't know if there is a better way to do that or if it actually matters for your code. I also converted your string arguments into arrays. I figured that if you were storing real values instead of strings, then this would be better. I hope this is what you were looking for.
%hash = ( "view0" => [qw/buffersize size value/], "view1" => [qw/buffersize size value/], "view2" => [qw/buffersize size value/], "view3" => [qw/buffersize size value/]); my $lastview; my $output; foreach $key (sort(keys %hash)){ # Do this only the first time. if(not defined($lastview)){ $lastview = $key; $output = "$key"; next; } $output .= " full outer join $key on $lastview.$hash{$lastview}[1] + = $key.$hash{$key}[1] and $lastview.$hash{$lastview}[0] = $key.$hash +{$lastview}[0]"; $lastview = $key; } print $output, "\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Using hash elements to create a string
by johnirl (Monk) on Sep 10, 2002 at 13:17 UTC | |
by RollyGuy (Chaplain) on Sep 10, 2002 at 14:53 UTC | |
by johnirl (Monk) on Sep 11, 2002 at 08:30 UTC | |
by RollyGuy (Chaplain) on Sep 11, 2002 at 13:40 UTC |
In Section
Seekers of Perl Wisdom