- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Help needed in perl
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-21-2010 11:39 PM
тАО03-21-2010 11:39 PM
Kindly help me with what I need to do to dynamically create a file in the script and based on country UK, I need to dynamically create XXX_UK_DD_MM_YYYY_GnnnnVnn.DAT. I have multi dated files present in my inbound feed area.
I can do this in shell as well, but I believe processing of large feed file is quicker in perl than shell, kindly correct me if I am wrong.
Solved! Go to Solution.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2010 01:05 AM
тАО03-22-2010 01:05 AM
Re: Help needed in perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2010 04:26 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2010 06:14 AM
тАО03-22-2010 06:14 AM
Re: Help needed in perl
4000000001600XXXXXXXXXXX
If 600, then I would need to copy it to a file by name XXX_600_DD_MM_YYYY_GnnnnVnn.DAT.
Thanks,
Srikanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2010 06:34 AM
тАО03-22-2010 06:34 AM
Re: Help needed in perl
What do you have so far? Any open or close file statements? Any variable file names?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2010 06:39 AM
тАО03-22-2010 06:39 AM
Re: Help needed in perl
Currently I have the following script.
I would like to create new tgtfile control file based on current file of datafile.
#!/usr/bin/perl
my ($datafile, $tmp, $i, $line, $columns, $x, $y);
my (@col, @dataline, @cell, %col);
$datafile = $ARGV[0]; # pick up data file name from command line
$targetfile = $ARGV[1];
$tgtfile = $ARGV[2];
$cntfile = $ARGV[3];
open (DATAFILE, "<$datafile") or die "Failed to open $datafile for input";
open(TGT1,">$targetfile") or die $!;
open(TGT2,">$tgtfile") or die $!;
while($line =
{
chomp($line);
next unless($line =~ m/\S+/);
@array = split("",$line);
if(($array[11] == 2)&&($array[12] == 7))
{
$line = join("",@array);
print TGT1 $line ."\n";
$x++
}
else
{
$line = join("",@array);
print TGT2 $line ."\n";
$y++
}
}
printf ("%010d\n",$x);
printf ("%010d\n",$y);
close DATAFILE;
close TGT1;
close TGT2;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2010 08:39 AM
тАО03-22-2010 08:39 AM
Re: Help needed in perl
You miss these:
use strict;
use warnings;
>my ($datafile, $tmp, $i, $line, $columns, $x, $y);
declare the variables where you use and initialize them. Not as a bunch of unrelated variables at the top of your script.
>my (@col, @dataline, @cell, %col);
You don't use these. anywhere.
>
>$datafile = $ARGV[0]; # pick up data file name from command line
>$targetfile = $ARGV[1];
>$tgtfile = $ARGV[2];
>$cntfile = $ARGV[3];
my ($datafile, $targetfile, $tgtfile, $cntfilr) = @ARGV;
>open (DATAFILE, "<$datafile") or die "Failed to open $datafile for input";
open my $dfh, "<", $datafile or die "$datafile: $!";
>open(TGT1,">$targetfile") or die $!;
open my $tfh1, ">", $targetfile or die "$tgtfile: $!";
>open(TGT2,">$tgtfile") or die $!;
open my $tfh2, ">", $tgtfile or die "$tgtfile: $!";
>while($line =
>{
while (<$dfh>) {
>chomp($line);
chomp;
>next unless($line =~ m/\S+/);
\S+ is stupid if a single \S is enough to get it pass
m/\S/ or next;
>@array = split("",$line);
>if(($array[11] == 2)&&($array[12] == 7))
>{
I /think you do NOT want to do it like that.
Assuming there is some structure in the lines, you either want to use substr ($_, 11, 2) or (probably better) some sort of
my ($x, $y, $code, ...) = unpack "A5 A6 A2 ...", $_;
if ($code == 27) {
see 'man perlpacktut' for some more in-depth explanation.
>$line = join("",@array);
Why reassemble the line while you never modified it?
>print TGT1 $line ."\n";
print $tfh1 $_;
$x++;
}
>$x++
>}
>else
>{
>$line = join("",@array);
>print TGT2 $line ."\n";
>$y++
>}
else {
print $tfh2 $_;
$y++;
}
}
>printf ("%010d\n",$x);
>printf ("%010d\n",$y);
printf "%010d\n%010d\n", $x, $y;
>close DATAFILE;
>close TGT1;
>close TGT2;
close $dfh or die "$datafile: $!";
close $tfh1 or die "$targetfile: $!";
close $tfh2 or die "$tgtfile: $!";
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2010 08:57 AM
тАО03-22-2010 08:57 AM
Re: Help needed in perl
If I understand correctly, I think this fits your needs:
# cat ./myassembly
#!/usr/bin/perl
use strict;
use warnings;
my $outfh;
my $count = 0;
while (<>) {
my ( $left, $right ) = $ARGV =~ m{(^..._)(.+)};
chomp;
my $match = substr( $_, 10, 3 ); #...zero-relative...
if ( $match eq '600' ) {
if ( $count <= 0 ) {
my $newname = $left . $match . '_' . $right;
open( $outfh, '>>', $newname )
or die "Can't open '$newname': $!\n";
$count++;
}
print $outfh "$_\n";
}
}
continue {
close $outfh if eof;
$count = 0;
}
1;
...You can pass multiple filenames on the command line for processing, too:
# ./myassembly XXX_DD_MM_YYYY_GnnnnVnn.DAT YYY_DD_MM_YYYY_GnnnnVnn.DAT ...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2010 08:58 AM
тАО03-22-2010 08:58 AM