If you don't mind loosing the numbers at the end of some of the fields (or at least storing them elsewhere) you could just use a split
use strict;
my $str = <<TXT;
Total index B50001
Crude processing (capacity) B5610C
Primary & semifinished processing (capacity) B562A3C
Finished processing (capacity) B5640C
Manufacturing ("SIC") B00004
Manufacturing (NAICS) GMF
Durable manufacturing (NAICS) GMFD
Wood product G321
+ 321
Nonmetallic mineral product G327
+ 327
Primary metal G331
+ 331
Iron and steel products G3311A2
+ 3311,2
Fabricated metal product G332
+ 332
Machinery G333
+ 333
TXT
my(%hash, %numbers);
for(split "\n" => $str) {
my @fields = reverse split;
$numbers{$fields[1]} = shift @fields
if $fields[0] =~ /\d(?:,\d+)?/;
$hash{$fields[0]} = join ' ' => reverse @fields[1 .. $#fields];
}
my $code = 'GMF';
print "$code: $hash{$code}.\n";
__output__
GMF: Manufacturing (NAICS).
So that should give you the hash you want.
HTH
_________ broquaint
-
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.
|