[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 + :
#!/usr/bin/perl use POSIX; use strict; use warnings; use YAML; #readLine is a temp variable to hold the current line of the file. my $readLine = ""; #queue is a string that holds all the data in <INFILE>. my $queue; #array will hold the data from $queue. my @array; #Variable holds the number of locked sessions found by counting lines + with dashes, i.e.--> "--------" my $numLocked = 0; #################### Temporary input test files acting as the real LIS +T.QUEUE #################### #input_1 --- has 1 locked session and 1 user waiting. #open (FILEIN1, "< /home/mmartin/Documents/Prelude_Kill-Sessions/scrip +t_input_1.txt") or exit 2; #input_2 --- has 1 locked session and 3 users waiting. #open (FILEIN2, "< /home/mmartin/Documents/Prelude_Kill-Sessions/scrip +t_input_2.txt") or exit 2; #input_3 --- has 3 locked sessions and at least one user waiting. open (FILEIN3, "< /home/mmartin/Documents/Prelude_Kill-Sessions/script +_input_3.txt") or exit 2; #input_4 --- has 0 locks --> EMPTY Queue #open (FILEIN4, "< /home/mmartin/Documents/Prelude_Kill-Sessions/scrip +t_input_4.txt") or exit 2; ###################################################################### +############################ #Read in file and append each line to a string call $string. my $x = 0; #temp variables to hold counts. my $i = 0; while (<FILEIN3>) { $readLine = $_; if ($x >= 10) { $queue .= $readLine; $i++; } $x++; } close(FILEIN3); #SUB clipEnd () --- loops through array and deletes uneeded lines from + the end of the # array of the specified length and offset. sub clipEnd { for (my $y = length($queue); $y > 0; $y--) { if (substr($queue, $y, 1) =~ ':' || substr($queue, $y, 1) =~ ' + ' || substr($queue, $y, 1) =~ /\n/) { substr($queue, $y, 1, ""); } elsif (substr($queue, $y, 1) =~ /[A-Za-z0-9]/) { last; } } } #SUB buildArray () --- builds an array using the value of $queue, and +removes empty lines, # uneeded lines, and extra whitespace. sub buildArray { #Split $string on the newline char and assign to $array. @array = split /\n/, $queue; #Run sub routine addLock(). addLock(); #Splice out the header lines throughout the array. for (my $y = 0; $y <= $#array; $y++) { if (defined $array[$y]) { if ($array[$y] =~ /^FILENAME/) { splice (@array, $y, 1); } } } #Splice out lines that contain all dashes. i.e. "---" for (my $y = 0; $y <= $#array; $y++) { if (defined $array[$y]) { if ($array[$y] =~ /^-+/) { splice (@array, $y, 1); } } } #Splice out empty lines. for (my $y = 0; $y <= $#array; $y++) { if (defined $array[$y]) { if ($array[$y] =~ /^\s{4,}/) { splice (@array, $y, 1); } } } } #SUB mapElements() --- takes the array of data and maps each element o +f a # single array element to a key. sub mapElements { @array = map { my ($file, $recordID, $M, $owner, $pid, $userID, $t +ty, $time, $month, $day, $locker) = split; { file => $file, recordID => $recordID, M => $M, owner => $owner, pid => $pid, usedID => $userID, tty => $tty, time => $time, month => $month, day => $day, locker => $locker } } @array; print Dump \@array; } #SUB addLock() --- this sub loops through the array, and if it is the +user who locked # the file then add an Identifier "L" to the end of the elem +ent. If # no then add a "W" for user waiting. sub addLock { #Remove trailing whitespace from the end of each array element. for (my $x = 0; $x <= $#array; $x++) { if ($array[$x] =~ / +$/) { chop $array[$x]; } } #Add keyword "Locked" to an element where the user has a locked se +ssion. for (my $x = 0; $x <= $#array; $x++) { if ($array[$x+1] =~ /^--+/) { $array[$x] .= " Locked"; } } #Add keyword "Waiting" to an element where the user is waiting on +a locked session. for (my $x = 0; $x <= $#array; $x++) { if ($array[$x] !~ /Locked$/) { $array[$x] .= " Waiting"; } } } # SUB trimWhitespace() --- This sub will loop through the array and se +arch for spots that have # more than one 'whitespaces' and replace them with only + one space. sub trimWhitespace { for (my $x = 0; $x <= $#array; $x++) { if ($array[$x] =~ /\s{2,}/) { $array[$x] =~ s/\s+/ /g; } } } #Execute sub routine "clipEnd()". clipEnd; #Execute sub routine "buildArray()". buildArray; #Execute sub routine "trimWhitespace()". trimWhitespace; #Print the array to a file. open (FILEOUT, "> /home/mmartin/Documents/Prelude_Kill-Sessions/MYoutp +ut2.txt") or exit 2; for (my $x = 0; $x <= $#array; $x++) { print FILEOUT "$array[$x]\n"; } close (FILEOUT); #Print the whole array to screen print "\n\n=========================== Array ========================= +===\n"; for (my $x = 0; $x <= $#array; $x++) { print "$array[$x]\n"; } print "==============================================================\ +n\n"; #Call SUB Routine mapElements(), which will also dump the data in the +array out to the screen. mapElements;
In reply to How to reference to array keys? by mmartin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |