in reply to Formatting Text...Again

but where is the sample of your code? I seem to recall seing something like this file before and I know that code was suggested, so you should at least have the centering problem sorted out.

The new page (form feed) character is \f. So print "\f"; generates a new page on STDOUT.

Putting page numbers at the top or bottom of each page seems trivial to me. From the answers to your previous question you already know how to center stuff. You do know that print "Page: $pageNum\n" gets the contents of $pageNum interpolated into the string and thus printed don't you?

Tell us where you are actually having trouble. Show us the code that doesn't do what you want and tell us, or show us with some sample output, what you expect. BTW, don't show us two complete pages of output where there are only 6 interesting lines. Show us the 6 interesting lines with elipsis (...) to indicate omited stuff. That way we can see what you are interested in much more easily. If we can run your sample code and get your sample output then you have asked a question worth a B+. If you show us what you would like and explain where your problem is too you get an A+.


DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: Formatting Text...Again
by Anonymous Monk on May 22, 2006 at 02:22 UTC
    Ok, here's two pieces of code that i'm trying to use.

    This one is to try to center the headings and print the page numbers
    #!/usr/bin/perl 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 $width = 80; my $heading; print "Page: $pageNum\n"; #while (Project3) { if (/(SECTION)(\s)(\d+)(.*)(\3)(\.1\.)(.*)/) { $heading = "$1.$2.$3.$4"; format Ident = @||||||||||||||||||||||||||||||||||||||||||||||||||||| +|| "$heading" . } }

    This is what it returns:
    [evans:19:55:07 perl]$ ./project3-6.pl Global symbol "$pageNum" requires explicit package name at ./project3- +6.pl line 25. Missing right curly or square bracket at ./project3-6.pl line 40, at e +nd of line syntax error at ./project3-6.pl line 40, at EOF Execution of ./project3-6.pl aborted due to compilation errors.
    I know that I need to define the $pageNum but I don't know what to define it as. And I can't figure out the other errors. I am VERY NEW to perl, and to unix for that matter.

    This is the other code I used to try to center the headings:
    #!/usr/bin/perl 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 $width = 80; my $heading; for (@Project3) { if (/(SECTION)(\s)(\d+)(.*)(\3)(\.1\.)(.*)/) { $heading = $1.$2.$3.$4; print " " x (($width-length($heading))/2); } }


    It doesn't print anyting.

      If you don't understand simple scalar variables then you need to start with reading Perl Babysteps 1: Your First Simple Script. You are no where near ready to be parsing and reformating files! When you have read that turtorial and some of the others in the Getting Started with Perl section of tutorials, come back and we will help further.

      Not understanding fundamental stuff like scalar variables is a severe impediment to completing any Perl script! We can provide a solution script for your assignement, but that doesn't help you at all. What is incredible though is that you have been given such an assignment when you seem to be so ill equiped to complete it. Is this because the course is poorly structured, or is your teacher right out of touch with what is actually going on in class?


      DWIM is Perl's answer to Gödel
        A little of both I presume - it's allowed to be taken by anyone who wishes with instructor permission, but the instructor gives permission to everyone. He misrepresented the class and by the time I realized I was over my head it was to late to drop the class. (also, the class costs almost $3000 so taking an incomplete would be devastating to my finances). I realize that there's no way to complete the assignment in the time he's given me (a week and a half, it's due on the 23rd), but I want to do what I can and try to get a fairly decent grade in the class if possible.
      Sorry, I forgot to sign in - the "Anonymous Monk" above is me! Also, there's a slight correction. The second code above does print something, it prints:

      Use of uninitialized value in pattern match (m//) at ./project3-5.pl line 25, <INFO> line 7507.
      It prints this over and over again, at least 100 times before I killed it.
      You shouldn't put your format in a block (the 'if' statement), and you should not have leading whitespace (or anything else) before the actual format string, otherwise it will appear in the output.
      the 'dot'(.) which terminates the format MUST be at the beginning of a line, otherwise it will go to end-of-file looking for it.
      Perl is free-format almost everywhere except in format. ;-)