Front page | perl.beginners |
Postings from March 2002
Write statement ?
Thread Previous
From:
Grant $ Sandra Hansen
Date:
March 1, 2002 04:15
Subject:
Write statement ?
Message ID:
LMEGICLNNFHEEIDLCKJNAEAOCDAA.slhgkh5@attbi.com
The problem lies in the second loop. Each time through the loop I am
writing to a separate file, which appears to be working, the body of the
report is in each file. The header is what I am having problems with. I
want to change the page length so the header appears at the top of each file
instead of after every 60 lines. I calculate the length and add 5 and then
pass it to the format OUT_TOP using $total. The page length does change
because the header prints many many more times, but not like it is suppose
to. I was thinking maybe I need to write the header out separately, or
maybe I need to move the write statement outside of its current loop. I
will play with that this morning.
Also, at the top of each file I have a number where the
@
$= = $total is in my code. Any idea what that means?
thanks for your time and any help greatly appreciated.
#!/usr/bin/perl -w
use strict; #uses strict perl coding rule
use constant PATH => "/hansen/perl/mtm/";
use constant GROUPS => "group_files.txt";
use constant GROUPS1 => "groups.txt";
use constant ACCESS => "user_access_all.txt";
my ($user, $fname, $lname, $line, $count, $total);
#delcares private variables
open F_GROUPS, PATH.GROUPS or die "Can't open: $!";
while (<F_GROUPS>) {
chomp(my @field = split /:/); #Puts group_files.txt into
an array
open OUT, ">$field[1]" or die "Can't open: $!";
open F_ACCESS, PATH.ACCESS or die "Can't open: $!";
$count = 0;
while (<F_ACCESS>) {
chomp(my @line = split /:/); #Puts
user_access_all.txt into an
if (/^:$field[0]/) { #
++$count; #Calculates page length and adds 5
to accomodate header
$total = $count + 5;
}
$user = $line[1];
$fname = $line[2];
$lname = $line[3];
write OUT if (/^:$field[0]/); #Writes each line to it
pertinent file each time through the .
}print "$field[0] $total \n"; #for testing purposes
}
close OUT or die "Can't close: $!";
close F_ACCESS or die "Can't close: $!";
close F_GROUPS or die "Can't close: $!";
#qx(/usr/local/bin/mpack -s MTM $field[1] $field[2]);
#unlink glob "/usr/local/scripts/security/sybase/user/*.txt";
format OUT_TOP =
@
$= = $total
MTM Access By Dept
Security Group First Name Last Name
-------------- ---------- ----------
..
format OUT =
@<<<<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<
<<<<<
$user,
$fname, $lname
..
-----Original Message-----
From: Timothy Johnson [mailto:tjohnson@sandisk.com]
Sent: Thursday, February 28, 2002 10:43 PM
To: slhgkh5@attbi.com; 'Perl Beg '
Subject: RE: Write statement ?
any chance you could post part of your code?
-----Original Message-----
From: slhgkh5@attbi.com
To: Perl Beg
Sent: 2/28/02 8:23 PM
Subject: Write statement ?
Does the write statement call the format statement each
time it writes when used in a while loop or does it
only call it once and hold it in memory? What I am
trying to do is change the page length each time the
write statement writes to a file, but it does not
appear to be working quite right.
Any thoughts?
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
----------------------------------------------------------------------------
----
This email may contain confidential and privileged
material for the sole use of the intended recipient.
If you are not the intended recipient, please contact
the sender and delete all copies.
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
Thread Previous