I am not passing any argunments to my subroutines yet the global variable is not being passed/read/or written...cannot get it to print out. As you can see I am trying a few different things to get the data to print out but alas it does not. No matter what I try to do I cannot get the following line to print out its argument.
print "MY LINE IN: $my_line_in\n\n";
Your wizdom is greatly appreciated.
#!/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 = <INFILE> ){ 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 subrout +ine 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);
and the data file looks like
#### SECTION A1 (DO NOT REMOVE THIS LINE) ## Data in section A1 Data in section A1 #### SECTION D1 (DO NOT REMOVE THIS LINE) ## Data in section D1 Data in section D1 #### SECTION D2 (DO NOT REMOVE THIS LINE) ## Data in section D2 Data in section D2
The following is what is print out:
[root@localhost admin_scripts]# ./processData.pl In while loop POINT 1: #### SECTION A1 (DO NOT REMOVE THIS LINE) In while loop POINT 2: #### SECTION A1 (DO NOT REMOVE THIS LINE) In while loop POINT 3: #### SECTION A1 (DO NOT REMOVE THIS LINE) In #### SECTION A1 MY LINE IN: In while loop POINT 1: ## In while loop POINT 2: ## In while loop POINT 6: ## In #### SECTION A1 MY LINE IN: In while loop POINT 1: Data in section A1 In while loop POINT 2: Data in section A1 In while loop POINT 6: Data in section A1 In #### SECTION A1 MY LINE IN: In while loop POINT 1: Data in section A1 In while loop POINT 2: Data in section A1 In while loop POINT 6: Data in section A1 In #### SECTION A1 MY LINE IN: In while loop POINT 1: #### SECTION D1 (DO NOT REMOVE THIS LINE) In while loop POINT 2: #### SECTION D1 (DO NOT REMOVE THIS LINE) In while loop POINT 4: #### SECTION D1 (DO NOT REMOVE THIS LINE) In #### SECTION D1 MY LINE IN: In while loop POINT 1: ## In while loop POINT 2: ## In while loop POINT 7: ## In #### SECTION D1 MY LINE IN: In while loop POINT 1: Data in section D1 In while loop POINT 2: Data in section D1 In while loop POINT 7: Data in section D1 In #### SECTION D1 MY LINE IN: In while loop POINT 1: Data in section D1 In while loop POINT 2: Data in section D1 In while loop POINT 7: Data in section D1 In #### SECTION D1 MY LINE IN: In while loop POINT 1: #### SECTION D2 (DO NOT REMOVE THIS LINE) In while loop POINT 2: #### SECTION D2 (DO NOT REMOVE THIS LINE) In while loop POINT 5: #### SECTION D2 (DO NOT REMOVE THIS LINE) In #### SECTION D2 MY LINE IN: In while loop POINT 1: ## In while loop POINT 2: ## In while loop POINT 8: ## In #### SECTION D2 MY LINE IN: In while loop POINT 1: Data in section D2 In while loop POINT 2: Data in section D2 In while loop POINT 8: Data in section D2 In #### SECTION D2 MY LINE IN: In while loop POINT 1: Data in section D2 In while loop POINT 2: Data in section D2 In while loop POINT 8: Data in section D2 In #### SECTION D2 MY LINE IN:

In reply to Subroutine argument list by Editorial_Response

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.