Ok, I posted on here a few days ago concerning a homework assignment. Thanks a lot to everyone who's helped!

So now I'm moving forward and I need to center the section headings in this .txt file i've got. Here's part of the text that needs to be formatted:

====================================================================== +======= SECTION 35 - BUILDING VIM FROM SOURCE 35.1. How do I build Vim from the sources on a Unix system? For a Unix system, follow these steps to build Vim from the sources: - Download the source and run-time filles archive (vim-##.tar.bz2) fro +m the ftp://ftp.vim.org/pub/vim/unix directory. - Extract the archive using the bzip2 and tar utilities using the com +mand: $ bunzip2 -c <filename> | tar -xf -


Now, to do the other parts of the project I needed to read it into an array and then chop the \n characters so it's one long string now.

There are a total of 37 Sections and every section heading has the row of = = = = = = before it. So, to center the section headings I did the following RE:

#!/usr/bin/perl # # Reformat the project3Data.txt file to make more accesible use strict; use warnings; my $file = '/u/home/jhart2/perl/project3Data.txt'; # Name the fil +e open(INFO, $file); # Open the file for input my @Project3 = <INFO>; # Read it into an array my $NoOfCharsPerLine = 80; my $NoOfLinesPerPage = 100; my $RightMargin = 7; my $header = 3; my $footer = 5; my @argument; my $width = 80; my $heading; chop(@Project3); # Remove \n characters my $string = "@Project3"; # Define the string my @chapters = split (/===+/, $string); # Split the string while (<INFO>) { if (/(SECTION)(\s)(\d+)(.*)(\3)(\.1\.)(.*)/) { $heading = $1.$2.$3.$4; print "$heading" x (($width-length($heading))/2); + # Center the heading } } close(INFO); # Close the file


...and here's the problem, it doesn't print anything. I know it has to be something simple, but I can't find it. Any suggestions? Thanks!

In reply to Printing Help by lollipop7081

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.