------------------------
20080331EJUSD00 0003372500000010750000000000000000000000
20080331 SUSD0000 87673600001148531000000000000000000000
20080331XZUSD00000 0000000000000000000000000000000000000
200 0331XZUSD0000000000000000000000000000000000000000000
20 0331XZUSD0000000000000000000000000000000000000000000
Script name: try-unpack.pl
#!/usr/bin/perl
use warnings;
use strict;
my $xf = './test-file.txt';
open FH, $xf or die " Can not open the file : $! \n";
while(
{
chomp $_;
my ($a, $b, $c, $d) =unpack("A4 A4 A4 A8", $_);
print $a . "\t" . $b . "\t" . $c . "\t" . $d . "\n";
}
Output:
bash-2.05$ ./try-unpack.pl
2008 0331 EJUS D00 0003
2008 0331 SUS D0000 87
2008 0331 XZUS D00000 0
200 0331 XZUS D0000000
20 0331 XZUS D0000000
====================================================================
Script Name: try-pack.pl
#!/usr/bin/perl
use warnings;
use strict;
my $xline;
die " Not enough user specified inputs : $! \n" unless @ARGV == 4;
$xline = pack("A5 A4 A3 A2", $ARGV[0], $ARGV[1], $ARGV[2], $ARGV[3]);
print $xline . "\n";
$xline = pack("a5 a4 a3 a2", $ARGV[0], $ARGV[1], $ARGV[2], $ARGV[3]);
print $xline . "\n";
Output:
bash-2.05$ ./try-pack.pl KUMAR PRA RA BROTHER
KUMARPRA RA BR
KUMARPRARABR
No comments:
Post a Comment