in reply to Re^4: How to reference to array keys?
in thread How to reference to array keys?
This code dumps the basic data in a 1st report.
The 2nd report shows the the folks who own a file and the other guys who want it. The report specifically excludes those who own it and want it themselves.
So the data structure is easier to understand, but the price is that it is a bit more convoluted to fiddle with.
I'm sure that the other kind Monks and I will be willing to help as you have other questions.
#!/usr/bin/perl use strict; use warnings; use Data::Dump qw(pp); #Data::Dumper is also great! $|=1; #turn off STDOUT buffering my @records; my $OwnerOrWaiting=""; while (<DATA>) { next if /^\s*$/; # skip whitespace lines s/\s+$//; # delete all trailing whitespace # this does a chomp() and a bit more.. if (/^FILENAME/) # FILENAME line defines what col #4 means { $OwnerOrWaiting = (split)[3]; } if (m/^\//) # A data line starts with '/' # I don't like "leaning toothpick" but # ok if your text editor displays wrong # colors with the other syntax - no biggie { push @records, "$OwnerOrWaiting $_"; #add status to line } } sub get_fields { my $line = shift; my %fields; @fields{qw(OWNER-WAIT FILENAME RECORD_ID M USER UNBR UNO TTY TIME D +ATE)} = split(' ', $line, 10); return %fields; } print "Dumping raw records....\n"; foreach my $line (@records) { my ($colnumber1, @rest) = split(' ',$line); printf "%-8s @rest\n", $colnumber1; } # lets print lines where we have an OWNER and at least one # other person WAITING who is not the OWNER print "\n\n"; my $current_owner=""; my $first_record=0; my @lines_in_record=(); my %temp; foreach my $line (@records) { %temp = get_fields($line); #make hash of field names if ( $temp{'OWNER-WAIT'} eq 'OWNER') # OWNER LINE { process_owner_record(); } else # WAITING LINE { push @lines_in_record, $line; } } process_owner_record(); sub process_owner_record { if (!$current_owner) { $current_owner = $temp{USER}; return; } my $new_owner = $temp{'USER'}; foreach (@lines_in_record) { my %this_record= get_fields($_); print "owner=$current_owner $_\n" if $current_owner ne $this_record{USER}; } @lines_in_record = (); $current_owner = $new_owner; } =prints Dumping raw records.... OWNER /prod-data/J 00151120273 X jmorg 3584038 247 ts/49 13:38:12 J +ul 20 WAITING /prod-data/J 00151120273 X jmorg 2015244 134 s/109 13:48:32 J +ul 20 WAITING /prod-data/J 00151120273 X gdavi 1359996 62 ts/20 13:54:22 Ju +l 20 OWNER /prod-data/J 001!L!311895 X jmorg 2015244 134 s/109 13:48:32 +Jul 20 WAITING /prod-data/J 001!L!311895 X jmorg 5713932 191 ts/46 14:01:42 +Jul 20 OWNER /prod-datahi 001!10274882 X rfuse 3354796 61 ts/43 13:39:02 J +ul 20 WAITING /prod-datahi 001!10274882 X jmorg 3584038 247 ts/49 13:39:22 +Jul 20 owner=jmorg WAITING /prod-data/J 00151120273 X gdavi 1359996 62 + ts/20 13:54:22 Jul 20 owner=rfuse WAITING /prod-datahi 001!10274882 X jmorg 3584038 24 +7 ts/49 13:39:22 Jul 20 =cut
=data_segment __DATA__ [H[2JUniData Release 7.2 Build: (3786) (c) Copyright Rocket Software, Inc. 1988-2009. All rights reserved. Current UniData home is /usr/udthome/. Current working directory is /usr/local/rfs/udt. :TERM ,0 :UDT.OPTIONS 20 ON :LOGTO /ud/JWP :LIST.QUEUE FILENAME RECORD_ID M OWNER UNBR UNO TTY TIME DA +TE /prod-data/J 00151120273 X jmorg 3584038 247 ts/49 13:38:12 Ju +l 20 ---------------------------------------------------------------------- +---- FILENAME RECORD_ID M WAITING UNBR UNO TTY TIME DA +TE /prod-data/J 00151120273 X jmorg 2015244 134 s/109 13:48:32 Ju +l 20 /prod-data/J 00151120273 X gdavi 1359996 62 ts/20 13:54:22 Ju +l 20 + FILENAME RECORD_ID M OWNER UNBR UNO TTY TIME DA +TE /prod-data/J 001!L!311895 X jmorg 2015244 134 s/109 13:48:32 Ju +l 20 ---------------------------------------------------------------------- +---- FILENAME RECORD_ID M WAITING UNBR UNO TTY TIME DA +TE /prod-data/J 001!L!311895 X jmorg 5713932 191 ts/46 14:01:42 Ju +l 20 + FILENAME RECORD_ID M OWNER UNBR UNO TTY TIME DA +TE /prod-datahi 001!10274882 X rfuse 3354796 61 ts/43 13:39:02 Ju +l 20 ---------------------------------------------------------------------- +---- FILENAME RECORD_ID M WAITING UNBR UNO TTY TIME DA +TE /prod-datahi 001!10274882 X jmorg 3584038 247 ts/49 13:39:22 Ju +l 20 =cut
|
|---|