<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://mars.merhot.dk/w/index.php?action=history&amp;feed=atom&amp;title=Talk%3AArrays_perl</id>
		<title>Talk:Arrays perl - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://mars.merhot.dk/w/index.php?action=history&amp;feed=atom&amp;title=Talk%3AArrays_perl"/>
		<link rel="alternate" type="text/html" href="http://mars.merhot.dk/w/index.php?title=Talk:Arrays_perl&amp;action=history"/>
		<updated>2026-04-23T14:11:26Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.29.0</generator>

	<entry>
		<id>http://mars.merhot.dk/w/index.php?title=Talk:Arrays_perl&amp;diff=11175&amp;oldid=prev</id>
		<title>Heth at 11:41, 6 March 2010</title>
		<link rel="alternate" type="text/html" href="http://mars.merhot.dk/w/index.php?title=Talk:Arrays_perl&amp;diff=11175&amp;oldid=prev"/>
				<updated>2010-03-06T11:41:49Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;' lang='en'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 11:41, 6 March 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l37&quot; &gt;Line 37:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 37:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* Kilde [http://ist.marshall.edu/ist334/perl_pointers.html http://ist.marshall.edu/ist334/perl_pointers.html]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* Kilde [http://ist.marshall.edu/ist334/perl_pointers.html http://ist.marshall.edu/ist334/perl_pointers.html]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Perl]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Heth</name></author>	</entry>

	<entry>
		<id>http://mars.merhot.dk/w/index.php?title=Talk:Arrays_perl&amp;diff=9561&amp;oldid=prev</id>
		<title>Tcj at 09:07, 1 October 2009</title>
		<link rel="alternate" type="text/html" href="http://mars.merhot.dk/w/index.php?title=Talk:Arrays_perl&amp;diff=9561&amp;oldid=prev"/>
				<updated>2009-10-01T09:07:26Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;' lang='en'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 09:07, 1 October 2009&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot; &gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Hash of arrays&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;==&lt;/ins&gt;Hash of arrays&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;==&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Another problem we can run into is to have a hash each element of which is an array. In the other words, we would like to associate not just one scalar variable with a key ford, but a whole list of scalar values. The idea of the solution is exactly the same as in the previous section. Instead of keeping scalar values in our hash we will keep pointers to an array.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Another problem we can run into is to have a hash each element of which is an array. In the other words, we would like to associate not just one scalar variable with a key ford, but a whole list of scalar values. The idea of the solution is exactly the same as in the previous section. Instead of keeping scalar values in our hash we will keep pointers to an array.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Tcj</name></author>	</entry>

	<entry>
		<id>http://mars.merhot.dk/w/index.php?title=Talk:Arrays_perl&amp;diff=9560&amp;oldid=prev</id>
		<title>Tcj: New page: Hash of arrays Another problem we can run into is to have a hash each element of which is an array. In the other words, we would like to associate not just one scalar variable with a key f...</title>
		<link rel="alternate" type="text/html" href="http://mars.merhot.dk/w/index.php?title=Talk:Arrays_perl&amp;diff=9560&amp;oldid=prev"/>
				<updated>2009-10-01T09:06:54Z</updated>
		
		<summary type="html">&lt;p&gt;New page: Hash of arrays Another problem we can run into is to have a hash each element of which is an array. In the other words, we would like to associate not just one scalar variable with a key f...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Hash of arrays&lt;br /&gt;
Another problem we can run into is to have a hash each element of which is an array. In the other words, we would like to associate not just one scalar variable with a key ford, but a whole list of scalar values. The idea of the solution is exactly the same as in the previous section. Instead of keeping scalar values in our hash we will keep pointers to an array.&lt;br /&gt;
&lt;br /&gt;
For example, let we have a file like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Bob: 89 76 89 90 100 101&lt;br /&gt;
Bill: 100 89 76 80 34 0&lt;br /&gt;
Sam: 102 99 87 78 90 69&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
For each student mentioned in the file we would like to keep her or his grades. To do that we will write the following code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=perl&amp;gt;&lt;br /&gt;
%grades = ();    # create an empty hash&lt;br /&gt;
while( &amp;lt;&amp;gt; ){&lt;br /&gt;
   chomp;&lt;br /&gt;
   ($name, $grds) = split(/:\s*/, $_);&lt;br /&gt;
   $grades{$name} = [ split(/\s+/, $grds) ];&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
for ( keys(%grades) ){&lt;br /&gt;
   printf &amp;quot;%8s : %.2f\n&amp;quot;, $_, avg( @{$grades{$_}} );&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sub avg&lt;br /&gt;
{&lt;br /&gt;
  my @arr = @_;&lt;br /&gt;
  my $sum = 0;&lt;br /&gt;
  my $count = $#arr + 1;&lt;br /&gt;
  for(my $i=0;$i&amp;lt;$count;$i++){&lt;br /&gt;
     $sum += $arr[$i];&lt;br /&gt;
  }&lt;br /&gt;
  $sum/$count;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The very first loop just reads the file line by line and splits the line into name and grades, then it uses split function again to get an array of grades, then in the assignment $grades{$name} = [ split(/\s+/, $grds) ]; we initialize an element of the has with the key $name and the value is a pointer to an anonymous array that contains all the grades for the student. To create a pointer we use square brackets around the functions split. In the second loop we call function avg to compute the average grade for each student. Please notice that we use @ in front of the hash element to specify that we pass an array not a pointer to the function. &lt;br /&gt;
&lt;br /&gt;
* Kilde [http://ist.marshall.edu/ist334/perl_pointers.html http://ist.marshall.edu/ist334/perl_pointers.html]&lt;/div&gt;</summary>
		<author><name>Tcj</name></author>	</entry>

	</feed>