Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The problem is complex, but it's not unsolvable. It seems to me that course will always contain a space between the alpha code and the numeric code and that the prof names will also always contain a space. But then you're pretty much screwed if somebody has a two-part last name like "VAN DYKE".</p> <p>A regex would describe this record:</p> <pre><code>my $record_exp = qr{ ^ \s* (\d{4}/\d{2}) # yyyy/mm date \s+ (\d+) # any number of digits \s+ (\S+ \s \S+) # non-space cluster, single space, non-space cluster \s+ # sames as last, possibly not there, separating spaces are included # in the conditional, because we have to make sure it will start # right at the next rule. (?:(\S+ \s \S+)\s+)? # a cluster of alpha, single space, cluster of digits (\p{Alpha}+ \s \d+) \s+ # any number of spaces (\S+) # any number of non-space \s+ # ditto.. (\S+) \s+ (\S+) }x; </code></pre> <p>Which makes the loop a lot easier: </p> <pre><code>while ( &lt;$input&gt; ) { my @fields = m{$record_exp}; # ... list of semantic actions here... } </code></pre> <p>But you could also store it into structures, knowing that the only variable part of the data is the profs: </p> <pre><code>use strict; use warnings; my @records; &lt;$input&gt;; # bleed the first line while ( &lt;$input&gt; ) { my @fields = split; # split on white-space my $record = { date =&gt; shift @fields }; $record-&gt;{session} = shift @fields; $record-&gt;{profs} = [ join( ' ', splice( @fields, 0, 2 )) ]; while ( @fields &gt; 5 ) { push @{ $record-&gt;{profs} }, join( ' ', splice( @fields, 0, 2 )); } $record-&gt;{course} = splice( @fields, 0, 2 ); @$record{ qw&lt;sec grade count&gt; } = @fields; push @records, $record; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload