Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I see where I missed part of your specification. Here is try number 2. Now, the thing to note here is that my output is slightly different than the one you posted above. The "whatever = something" pairs are moved around a little bit. If I remember my SQL syntax, I don't believe it should matter too much. Let me know if it does, and I can help you fix it. Anyhow, here is the new updated code:

%hash = ( "view0" => [qw/buffersize size value speed/], "view1" => [qw/buffersize size value speed/], "view2" => [qw/buffersize size value speed/], "view3" => [qw/buffersize size value speed/]); 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 "; my $i; $array_elements_used = scalar(@{ $hash{$key} })-1; #loop through all of the elements except for the last for($i=0;$i<$array_elements_used;$i++){ $output .= "$lastview.$hash{$lastview}[$i] = $key.$hash{$key}[$i]" +; # only add an "and" if this is not the last element used. $output .= " and " if ($i != ($array_elements_used-1)); } $lastview = $key; } print $output, "\n"; ============= output: view0 full outer join view1 on view0.buffersize = view1.buffersize and + view0.size = view1.size and view0.value = view1.value full outer joi +n view2 on view1.buffersize = view2.buffersize and view1.size = view2 +.size and view1.value = view2.value full outer join view3 on view2.bu +ffersize = view3.buffersize and view2.size = view3.size and view2.val +ue = view3.value

In reply to Re: Re: Re: Using hash elements to create a string by RollyGuy
in thread Using hash elements to create a string by johnirl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-20 02:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found