Its exactly what I was looking for. Although I understand the piece where you concatenate the string "COMMENT ;" to the existing lines after filtering unwanted lines, what is the logic that you are using to filter the lines that start with PKZIP,Copyright and Viewing?
The other question that I have is that how can I use a variable that holds the name of the logfile instead of hardcoding the line
open FILE, ">>file.txt" or die "cannot open file for writing";
There's no trick. Just find the line that contains "Length" and process those thereafter, so a sed run will do the same trick.
But a warning though. The routine will not notice if the command fails for whatever reason. Maybe you will want to check $? (if pkzipc obeys so) for return value, e.g.
$out = `pkzipc test.zip`;
if ($? >> 8) {
# error (assume non-zero return status is error)
}
As a sidenote, did you try the Archive::Zip module (of course you will need to download and install it)? It seems to let you retrieve such information programmatically:
Thanks cbikong. I was actually referring to my question of trying to use the variable name instead of the hardcode log file name in the line of code
open FILE, ">>file.txt" or die "cannot open file for writing";
Thanks for the Archive::Zip module for perl compression-decompression. However, like I have mentioned before, I would have to create my own perl environment in order to get this installed and have it working.
Moreover, there is logic in the original program to perform a pkzipc only when the contents of the zip file is greater than zero.
Here is the partial output that I get of the .ctr file
COMMENT ; Text from this message will appear in the control file as instructions to the re
COMMENT ; Length Size Ratio Name
COMMENT ; ------ ---- ----- ----
COMMENT ; 1002KB 226KB 77.5% DIR1/M0511514944.exp
COMMENT ; 474KB 91KB 80.8% DIR2/47105SNAAA120-C1__LEVERASSYHANDBRAKE__LD521117.exp
COMMENT ; 476KB 91KB 80.9% DIR2/47105SNAAA830-C1__LEVERASSYHANDBRAKE__LD521117.exp
COMMENT ; 113KB 92KB 18.5% OTHER_FILES/44732S0K_A003____C4426278.exp
COMMENT ; ------ ------ ----- ----
COMMENT ; 2065KB 500KB 75.8% 4
However I do get the following messages during execution.
Use of uninitialized value in pattern match (m//) at test.pl line 415, <IN> line 2.
Use of uninitialized value in pattern match (m//) at test.pl line 415, <IN> line 2.
Line 415 happens to be
if ($Fld1 =~ /^\s*Length/) { $start = 1; }
Any ideas as to how to overcome this message. Thanks. Jerardfjay
How do I trim/truncate the value of the field $Fld9 to lets say 10 characters wide. I need to only use the first left justified 10 characters. If there is more than 80 characters that are assigned to this field from the $line.
I have tried the following and it doesnt seem to make a difference.
However if the $Fld9 is being assigned a value more than 10 characters wide,
The sprintf statement does not seem to truncate the value while printing the line.
do I have to use another command for this or can is there an alternate formatting option that I can use to truncate field values while printing using sprintf in PERL.