So to combine what the monks above have said, if you wanted an array of all the coursenames from each line, an array of buildings etc., an appoach might be
while (<>) {
my ($coursename, $building, $room, $day, $time, $name) =
split /, /, $line;
push @coursename, $coursename;
push @building, $building;
push @room, $room;
push @day, $day;
push @time, $time;
push @name, $name;
}
This still has some repetition (the 6 pushes) but this is inevitable because of your decision to hold the pieces of data in separate arrays. An array of hashes might be nicer, assuming that each building, room etc. belong with the coursename that is on the same line:
my @course_info;
while (<>) {
my ($coursename, $building, $room, $day, $time, $name) =
split /, /, $line;
push @course_info, {
coursename => $coursename,
building => $building,
room => $room,
day => $day,
time => $time,
name => $name,
};
}
or if the order of the courses is not important, the course names are unique and you want to access the data by course name, a hash of hashes:
my %course_info;
while (<>) {
my ($coursename, $building, $room, $day, $time, $name) =
split /, /, $line;
$course_info{$coursename} = {
building => $building,
room => $room,
day => $day,
time => $time,
name => $name,
};
}
|