Pam Derks wrote:
>
> Hi all,
Hello,
> am struggling with this, and it must be the something simple but for
> the life of me I don't see it.
>
> Am trying to build a hash table with:
> instructor name and their biography
>
> I've tried just about everything, but I can't get the values to show...
> where am I going wrong?
After looking at your data, it looks like you should set the input
record separator variable ($/) to input a whole record at a time. Use
either paragraph mode ($/ = '') if all your records are separated by
blank lines or if all the records end with 'XX' then use that ($/ =
"\nXX\n").
#!/usr/bin/perl -w
use strict;
$/ = "\nXX\n";
open BIOS, 'instructor.txt' or die "no instructor file: $!";
my %hash;
while ( <BIOS> ) {
# remove "\nXX\n" from end of record
chomp;
# remove leading and trailing whitespace
s/\A\s+//;
s/\s+\z//;
# skip invalid records
next unless /\n/;
my ( $name, $words ) = split /\s*\n\s*/, $_, 2;
$hash{ $name } = $words;
}
close BIOS;
for ( keys %hash ) {
print "HN: $_\n";
}
for ( values %hash ) {
print "HV: $_\n";
}
__END__
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]