#!/usr/bin/perl # variable data to be input by the admin # $my_line_in=""; # contains the name of the section we are currently processing $processing_section; # open file to read the data open (INFILE, "readData.txt") or die("Cannot open the input file. $!"); sub processSectionA1 { # Process data within the header # #### SECTION A1 (DO NOT REMOVE THIS LINE) # Process data print "In #### SECTION A1\n"; print "MY LINE IN: $my_line_in\n\n"; return; } sub processSectionD1 { # Process data within the header # #### SECTION D1 (DO NOT REMOVE THIS LINE) # Process data print "In #### SECTION D1\n"; print "MY LINE IN: $my_line_in\n\n"; return; } sub processSectionD2 { # Process data within the header # #### SECTION D2 (DO NOT REMOVE THIS LINE) # Process data print "In #### SECTION D2\n"; print "MY LINE IN: $my_line_in\n\n"; return; } LINE: while ( my $my_line_in = ){ chomp $my_line_in; # ignore blank lines next LINE if ($my_line_in =~ m/^$/); # debug print "In while loop POINT 1: $my_line_in\n"; # ignore comment lines with one hash tag # next LINE if ($my_line_in =~ m/^#{1,3}/); # debug print "In while loop POINT 2: $my_line_in\n"; if ($my_line_in =~ m/^#### SECTION A1.*/){ # debug print "In while loop POINT 3: $my_line_in\n"; $processing_section = "A1"; &processSectionA1; } elsif ($my_line_in =~ /^#### SECTION D1.*/){ # debug print "In while loop POINT 4: $my_line_in\n"; $processing_section = "D1"; processSectionD1(); } elsif ($my_line_in =~ /^#### SECTION D2.*/){ # debug print "In while loop POINT 5: $my_line_in\n"; $processing_section = "D2"; processSectionD2(); } else { # process hold value by processing last called subroutine if ($processing_section =~ /A1/){ # debug print "In while loop POINT 6: $my_line_in\n"; processSectionA1(); }elsif ($processing_section =~ /D1/){ # debug print "In while loop POINT 7: $my_line_in\n"; processSectionD1(); }elsif ($processing_section =~ /D2/){ # debug print "In while loop POINT 8: $my_line_in\n"; processSectionD2(); } } } close (INFILE);