Output:#!/usr/bin/perl -w use strict; my (%options,$curroption); while(<DATA>) { # read from __DATA__ filehandle below chomp; # get rid of trailing newlines next if /^\s*#/; # skip if it the first nonspace char is '#'. # set the curroption if the first item in the line is in all caps $curroption = $1 if s/^([A-Z]+) //; # make $currroption a hash key whose value is an array ref containin +g # the various options we found. push(@{$options{$curroption}},$_) for (split(/,\s*/)); } # print the datastructure which is a HoA (Hash of Arrays); for my $option (keys %options) { my @vals = @{$options{$option}}; print "$option -- ", join (',',@vals), "\n"; } __DATA__ # comment # comment ON Mon, Tues, Fri, Sat # comment other stuff
ON -- Mon,Tues,Fri,Sat,other stuff
-Blake
In reply to Re: How do you read the next line in a file while in a loop?
by blakem
in thread How do you read the next line in a file while in a loop?
by GroundZero
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |