<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Forwarded because I don't believe it went to the list.<br>
<br>
-------- Original Message --------
<table class="moz-email-headers-table" border="0" cellpadding="0"
cellspacing="0">
<tbody>
<tr>
<th align="RIGHT" nowrap="nowrap" valign="BASELINE">Subject: </th>
<td>RE: [Thousand-Oaks-pm] Thousand Oaks PM cancelled this
month</td>
</tr>
<tr>
<th align="RIGHT" nowrap="nowrap" valign="BASELINE">Date: </th>
<td>Thu, 15 Dec 2011 15:05:54 -0800</td>
</tr>
<tr>
<th align="RIGHT" nowrap="nowrap" valign="BASELINE">From: </th>
<td>Barry Brevik <a class="moz-txt-link-rfc2396E" href="mailto:BBrevik@StellarMicro.com"><BBrevik@StellarMicro.com></a></td>
</tr>
<tr>
<th align="RIGHT" nowrap="nowrap" valign="BASELINE">To: </th>
<td>Chuck Hardin <a class="moz-txt-link-rfc2396E" href="mailto:chardin@valueclick.com"><chardin@valueclick.com></a>,
ThousandOaks.pm <a class="moz-txt-link-rfc2396E" href="mailto:thousand-oaks-pm@pm.org"><thousand-oaks-pm@pm.org></a></td>
</tr>
</tbody>
</table>
<br>
<br>
<pre>Of course I failed to notice this email, so like an idiot, I showed up
at ValueClick last night <g>.
Since I missed out, I thought I would share this very short snippet with
you.
I have to deal with many Excel files and CSV files, so I have code that
reads each line into an array to be processed. The problem is that my
users keep jacking around the column order before giving me the final
file. I decided to fix that by reading row 0 (or, to my great annoyance,
row 1 in Excel-speak), which in my case always contains column headers,
look for the column names I need and extract the array offset to use in
extracting data from subsequent rows.
There is, of course, more than 1 way to do this, but to keep it simple,
this is the way I do it. One gotcha is if your array contains any
duplicate values, you are screwed. My apologies if this code is too
elementary for the list members:
use warnings;
use strict;
# Array represents columns read from a CSV file.
# Or whatever you want.
my @array = ('zero', 'one', 'two', 'three', 'four');
# Create hash where the keys are the values from the
# array, and the values are the positions in the array.
my $i = 0;
my %hash = map {$array[$_] => $i++} (0..$#array);
# Display the results.
print "$_, $hash{$_}\n" foreach (keys(%hash));
</pre>
<br>
<div class="moz-signature">-- <br>
<table columns="2">
<tbody>
<tr>
<th>Chuck Hardin</th>
<th>Software Engineer, ValueClick Media</th>
</tr>
<tr>
<td>+1-818-575-4573</td>
<td><a href="mailto:chardin@valueclick.com">chardin@valueclick.com</a></td>
</tr>
</tbody>
</table>
</div>
<font face="monospace"><br>
<br>
<br>
<br>
This email and any files included with it may contain privileged,<br>
proprietary and/or confidential information that is for the sole use<br>
of the intended recipient(s). Any disclosure, copying, distribution,<br>
posting, or use of the information contained in or attached to this<br>
email is prohibited unless permitted by the sender. If you have<br>
received this email in error, please immediately notify the sender<br>
via return email, telephone, or fax and destroy this original transmission<br>
and its included files without reading or saving it in any manner.<br>
Thank you.</font></body>
</html>