<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.webmaster-forums.net/crss/node/1000875" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title></title>
    <link>https://www.webmaster-forums.net/crss/node/1000875</link>
    <description></description>
    <language>en</language>
          <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/help-passing-array#comment-1003732</link>
    <description> &lt;p&gt;I have to agree with Jaffy here for the most part. Here is my version of it.&lt;br /&gt;
&lt;BLOCKQUOTE&gt;code:&lt;/blockquote&gt;&lt;/p&gt;
&lt;pre&gt;
sub1
{
my $hash = (
a =&amp;gt; val,
b =&amp;gt; val2,
c =&amp;gt; val3
);
sub2(%hash);
}

sub 2
{
my %hash = @_;
do (something with %hash);
}
[/code]

You&#039;re free to go from here. What japhy did with the while loop was assign each key and value a scalar so that you could use them individually. This may not be want you want to do.




[This message has been edited by Gil (edited 14 December 1999).] &lt;/pre&gt;</description>
     <pubDate>Wed, 15 Dec 1999 03:22:00 +0000</pubDate>
 <dc:creator>Gil</dc:creator>
 <guid isPermaLink="false">comment 1003732 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/help-passing-array#comment-1003731</link>
    <description> &lt;p&gt;Malte, actually, I beg to differ, because his solution has one line that I find just as inefficient as what I did:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;code:&lt;/p&gt;
&lt;pre&gt;sub1 {
  &amp;amp;sub2({%array});  # THIS HERE
}

sub2 {
  *newarray = shift;
  for (keys %newarray) {
    print $newarray{$_};
  }
}[/code]

I definitely agree that the typeglobbing is nice, but the line I have a problem with is your sub1() function.  By saying {%hash} instead of \%hash, you are effectively copying the elements, and for a big hash, this can be slow.  {%hash} creates a reference to an anonymous hash, whose contents are the same as %hash&#039;s, but \%hash creates a direct reference to %hash.

Also, while we&#039;re on the topic of style, perhaps the for-loop should be substituted by a while-loop, using the each() function; this is also faster, because keys %hash returns a lengthy list for big hashes.

I offer this solution:

&lt;BLOCKQUOTE&gt;code:&lt;pre&gt;sub func1 {
  my %hash;
  # populate %hash somehow
  func2(\%hash);
}

sub func2 {
  local *hash = shift;
  my ($k,$v);
  while (($k,$v) = each %hash) {
    # do whatever
  }
}[/code]

For those interested, I&#039;ve posted a benchmark online at &lt;a href=&quot;http://www.pobox.com/~japhy/tmp/perl/bm.txt&quot; class=&quot;bb-url&quot;&gt;http://www.pobox.com/~japhy/tmp/perl/bm.txt&lt;/a&gt; 

That&#039;s all for now.

------------------
-- 
MIDN 4/C PINYAN, NROTCURPI, USNR &lt;/pre&gt;&lt;/blockquote&gt;&lt;/pre&gt;&lt;/blockquote&gt;</description>
     <pubDate>Tue, 14 Dec 1999 21:06:00 +0000</pubDate>
 <dc:creator>japhy</dc:creator>
 <guid isPermaLink="false">comment 1003731 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/help-passing-array#comment-1003730</link>
    <description> &lt;p&gt;Froma perl style point of view Fred&#039;s answer is the better and much much faster solution.&lt;/p&gt;
&lt;p&gt;You might also find a way doing this using objects.&lt;/p&gt;
&lt;p&gt;Take a look a the perlob man page  &lt;img src=&quot;http://www.webmaster-forums.com/ubb/smile.gif&quot; alt=&quot;&quot; class=&quot;bb-image&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Later,&lt;/p&gt;
&lt;p&gt;Malte&lt;/p&gt;
&lt;p&gt;------------------&lt;br /&gt;
&lt;strong&gt;Malte Ubl - &lt;a href=&quot;http://www.Boardzilla.org&quot; class=&quot;bb-url&quot;&gt;www.Boardzilla.org&lt;/a&gt;&lt;/strong&gt;&lt;br /&gt;
Communication:  public&amp;lt;-&amp;gt;programmers&lt;br /&gt;
of the &lt;strong&gt;Boardzilla BB&lt;/strong&gt;&lt;/p&gt;
 </description>
     <pubDate>Tue, 14 Dec 1999 20:35:00 +0000</pubDate>
 <dc:creator>Malte</dc:creator>
 <guid isPermaLink="false">comment 1003730 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/help-passing-array#comment-1003729</link>
    <description> &lt;p&gt;The following code has been tested (this is always a good thing to do when posting answers) and works:&lt;/p&gt;
&lt;p&gt;sub func1 {&lt;br /&gt;
  func2(@_);&lt;br /&gt;
  # or &amp;func2;&lt;br /&gt;
  # (that would probably be faster, as it&lt;br /&gt;
  # sends the contents of @_ by default)&lt;br /&gt;
}&lt;/p&gt;
&lt;p&gt;sub func2 {&lt;br /&gt;
  my %hash = @_;&lt;br /&gt;
  my $key;&lt;br /&gt;
  foreach $key (keys %hash) {&lt;br /&gt;
    print &quot;$key =&amp;gt; $hash{$key}\n&quot;;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;/p&gt;
 </description>
     <pubDate>Sun, 12 Dec 1999 05:14:00 +0000</pubDate>
 <dc:creator>japhy</dc:creator>
 <guid isPermaLink="false">comment 1003729 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/help-passing-array#comment-1003728</link>
    <description> &lt;p&gt;Try the following code:&lt;/p&gt;
&lt;p&gt;sub1 {&lt;br /&gt;
    &amp;amp;sub2({%array});&lt;br /&gt;
}&lt;/p&gt;
&lt;p&gt;sub2 {&lt;br /&gt;
    *newarray = shift;&lt;br /&gt;
    for (keys %newarray) {&lt;br /&gt;
        print $newarray{$_};&lt;br /&gt;
    }&lt;br /&gt;
}&lt;/p&gt;
&lt;p&gt;Haven&#039;t tested it -- should work.&lt;/p&gt;
&lt;p&gt;------------------&lt;br /&gt;
[ &lt;strong&gt;Web-Reviews&lt;/strong&gt; ]&lt;br /&gt;
 &lt;a href=&quot;http://www.web-reviews.com/&quot; class=&quot;bb-url&quot;&gt;http://www.web-reviews.com/&lt;/a&gt;&lt;/p&gt;
 </description>
     <pubDate>Sun, 12 Dec 1999 04:23:00 +0000</pubDate>
 <dc:creator>Federico Carnales</dc:creator>
 <guid isPermaLink="false">comment 1003728 at https://www.webmaster-forums.net</guid>
  </item>
  </channel>
</rss>
