To common methods.
Group and peek at previous:
my @country_states;
for (@logfiles) {
my $country_state = $_; # Avoid clobbering @logfiles
$country_state =~ s/.txt//;
$country_state =~ s/_/ /g;
push @country_states, $country_state;
}
@country_states = sort @country_states;
my $last_country;
for my $country_state (@country_states) {
my ($country, $state) = split(/-/, $country_state, 2);
if (!defined($last_country) || $last_country ne $country) {
$last_country = $country;
print(uc($country), "\n");
}
print($state, "\n");
}
Group into a multi-dimensional structure:
my %states_by_country;
for (@logfiles) {
my $country_state = $_; # Avoid clobbering @logfiles
$country_state =~ s/.txt//;
$country_state =~ s/_/ /g;
my ($country, $state) = split(/-/, $country_state, 2);
push @{ $states_by_country{$country} }, $state;
}
for my $country (sort keys %states_by_country) {
print(uc($country), "\n");
my $states = $states_by_country{$country};
for my $state (sort @$states) {
print($state, "\n");
}
}
-
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.