Hello fellow Perl users... having some trouble here. Say for example, I have a text file containing two short stories. Above each short story there is a title formatted like: "<Baking Cookies>". I want to use each story title as a hash key, and the remaining text (story) as the value so when it reaches the next story title it will assign a new key. I have some code for this but it's not working properly. Suggestions are much appreciated... Please excuse my lack of experience. Thanks!
open FILE, "$dir/$file" or die ("Invalid file!\n"); my @stories = <FILE>; my $title = ''; my %stories_hash = (); foreach my $line (my @stories){ if($line =~ /<(.*)>/){ $title = $1; } else { $stories_hash{$title} .= $line; } }
In reply to Parsing a text file by DARK SCIENTIST
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |