This may seem trivial, but I believe how we organize programs is directly influenced by how we think. Perhaps learning to better organize code will lead to better organized, more efficient thinking.

PERL:
  1. #!/usr/local/bin/perl -w
  2. use strict;
  3. open (FH,"/usr/local/bin/perld/derektapes") or die "cannot open FH: $!\n";
  4. my $w_param="-w ";
  5. my $tick="'";
  6. my $b_param="barcode=";
  7. my $or_string=" or ";
  8. chomp ( my @a = <FH>);
  9.  
  10. #       $a[$i]=$_;
  11. #       $i++;
  12. #       print map {$_, "\n"} @a;
  13.  
  14.         print $w_param$tick;
  15.         while (@a) {
  16.         my @output = ();
  17.                 for ( 1..4 ) {
  18.                         push @output, $b_param . shift @a;
  19.                         last unless @a;
  20.                 }
  21.         print join ($or_string, @output),"\n";
  22.         }
  23. print $tick;

The author uses an 8 space indent. Here is the same code without the comments with a 4 space indent. I changed the indent to match my own settings. YMMV.

PERL:
  1. #!/usr/local/bin/perl -w
  2. use strict;
  3. open (FH,"/usr/local/bin/perld/derektapes")
  4.                 or die "cannot open FH: $!\n";
  5. my $w_param="-w ";
  6. my $tick="'";
  7. my $b_param="barcode=";
  8. my $or_string=" or ";
  9. chomp ( my @a = <FH>);
  10.  
  11.     print $w_param$tick;
  12.     while (@a) {
  13.     my @output = ();
  14.         for ( 1..4 ) {
  15.             push @output, $b_param . shift @a;
  16.             last unless @a;
  17.         }
  18.     print join ($or_string, @output),"\n";
  19.     }
  20. print $tick;

Let's look at the code in sections. I'll use comments first.

PERL:
  1. # open file
  2. open (FH,"/usr/local/bin/perld/derektapes") or die "cannot open FH: $!\n";
  3.  
  4. # declare some variables
  5. my $w_param="-w ";
  6. my $tick="'";
  7. my $b_param="barcode=";
  8. my $or_string=" or ";
  9.  
  10. # slurp file into array
  11. chomp ( my @a = <FH>);
  12.  
  13.     # print two variables (unchanged
  14.     # since decalaration above)
  15.     print $w_param$tick;
  16.  
  17.     # loop through @a
  18.     while (@a) {
  19.  
  20.     # create 4 column row for report
  21.     my @output = ();
  22.         for ( 1..4 ) {
  23.             push @output, $b_param . shift @a;
  24.             last unless @a;
  25.         }
  26.        
  27.     # print this row
  28.     print join ($or_string, @output),"\n";
  29.     }
  30.  
  31. # print $tick
  32. print $tick;
  33.  
  34. # exit program and implicitly close file
  35.  
  36. __END__

And now the comments only.

PERL:
  1. 1. Open file
  2.  
  3. 2. Declare some variables
  4.     a. $w_param,
  5.     b. $tick,
  6.     c. $b_param, and
  7.     d. $or_string.
  8.  
  9. 3. Slurp file into array - @a
  10.  
  11. 4. Print $w_param and $tick
  12.  
  13. 5. Loop through @a
  14.  
  15.     a. Create 4 column row
  16.     b. Print row
  17.     c. Contune loop
  18.  
  19. 6. Print $tick
  20.  
  21. 7. Exit program and close file

Question: Why open the file (step 1), then slurp it in at step 3 and close is at step 7?

It might make more sense to open, read it, and close it in 3 consecutive steps.

PERL:
  1. 1. Open file.
  2. 3. Slurp file into array - @a
  3. 3. Close file.
  4.  
  5. 4. Declare some variables
  6.     a. $w_param,
  7.     b. $tick,
  8.     c. $b_param, and
  9.     d. $or_string.
  10.  
  11. 5. Print $w_param and $tick
  12.  
  13. 6. Loop through @a
  14.  
  15.     a. Create 4 column row
  16.     b. Print row
  17.     c. Contune loop
  18.  
  19. 7. Print $tick

Now we'll put the code back in.

PERL:
  1. open (FH,"/usr/local/bin/perld/derektapes") or die "cannot open FH: $!\n";
  2.  
  3. # slurp file into array
  4. chomp ( my @a = <FH>);
  5.  
  6. # close file
  7. close FH;
  8.  
  9. # declare some variables
  10. my $w_param="-w ";
  11. my $tick="'";
  12. my $b_param="barcode=";
  13. my $or_string=" or ";
  14.  
  15. print $w_param$tick;
  16.  
  17. # loop through @a
  18. while (@a) {
  19.  
  20.     # create 4 column row for report
  21.     my @output = ();
  22.         for ( 1..4 ) {
  23.             push @output, $b_param . shift @a;
  24.             last unless @a;
  25.         }
  26.  
  27.     # print this row
  28.     print join ($or_string, @output),"\n";
  29. }
  30.  
  31. # print $tick
  32. print $tick;

'open' might be better written following a standard format.

PERL:
  1. my $file = '/usr/local/bin/perld/derektapes';
  2. open FH, $file or die qq(Cannot open "$file": $!);
  3.     chomp ( my @a = <FH>);
  4. close FH;

Declarations look better when lined up.

PERL:
  1. my $w_param     = '-w ';
  2. my $tick        = "'";
  3. my $b_param     = 'barcode=';
  4. my $or_string   = ' or ';

White space should be used to aid readability.

PERL:
  1. print $w_param$tick;
  2.  
  3. while ( @a ) {
  4.     my @output;
  5.     for ( 1 .. 4 ) {
  6.         push @output, $b_param . shift @a;
  7.         last unless @a;
  8.     }
  9.     print join( $or_string, @output ), "\n";
  10. }
  11.  
  12. print $tick;