- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Perl Help needed
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
тАО06-08-2004 08:02 AM
тАО06-08-2004 08:02 AM
$onefile = shift or die " please provide filename in timestamp.filename format";
($uniq,$type)=split(/\./,$onefile);
$testfile = "testfile";
open (OLD,"<$onefile") or die " Could not open file: $onefile";
while (
if (/^SWBAMSTW/) {
$count++;
$name = $uniq."-".$count.".".$type;
print "Prod: New split name $name\n";
open (NEW,">$name") or die "Prod: can not create $name";
$pname = "NEW";
}
if (/^SWBAMSFR/) {
$count++;
$name1 = $uniq."-".$count.".".$testfile;
print "Test : New split name $name1\n";
open (NEW1,">$name1") or die "Test: can not create $name1";
$pname = "NEW1";
}
die "no initial seperator found" unless ($count);
print $pname;
print "loop\n";
}
Solved! Go to Solution.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-08-2004 08:26 AM
тАО06-08-2004 08:26 AM
Solution--8<---
my $onefile = shift or die " please provide filename in timestamp.filename format";
my ($uniq, $type) = split m/\./, $onefile, 2;
my $testfile = "testfile";
open my $old, "<$onefile" or die " Could not
my ($count, $outfile) = (0);
open file: $onefile";
while (<$old>) {
if (/^SWBAMSTW/) {
$count++;
$name = "$uniq-$count.$type";
print STDERR "Prod: New split name $name\n";
$outfile and close $outfile;
open $outfile, ">$name" or die "Prod: can not create $name";
}
if (/^SWBAMSFR/) {
$count++;
my $name = "$uniq-$count.$testfile";
print STDERR "Test: New split name $name1\n";
$outfile and close $outfile;
open $outfile, ">$name1" or die "Test: can not create $name";
}
$count or die "no initial seperator found";
print $outfile;
print STDERR "loop\n";
}
-->8---
HTH Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-08-2004 08:32 AM
тАО06-08-2004 08:32 AM
Re: Perl Help needed
two file handles
open (NEW1,">$name") or die "Prod: can not create $name";
open (NEW2,">$fname") or die "Prod: can not create $fname";
You have two file handles open and then you write conditionally to whichever file you need.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-08-2004 08:41 AM
тАО06-08-2004 08:41 AM
Re: Perl Help needed
use strict;
use warnings;
and for the real unwary
use diagnostics;
this does the same as
# splain "error message"
Enjoy, Have FUN! H.Merijn [ who doen't know what a maven is :) ]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-08-2004 08:50 AM
тАО06-08-2004 08:50 AM
Re: Perl Help needed
I still don't understand the more than 1 file handle issue. I provide test input file. Pls advise. Thanks.
Log of a run:
Prod: New split name proto-1.txt
loop
loop
loop
loop
loop
loop
loop
loop
loop
loop
loop
Test: New split name
Test: can not create proto-2.testfile at split2.pl line 20, <$old> line 12.
GLOB(0x225114)GLOB(0x225114)GLOB(0x225114)GLOB(0x225114)GLOB(0x225114)GLOB(0x225
114)GLOB(0x225114)GLOB(0x225114)GLOB(0x225114)GLOB(0x225114)GLOB(0x225114)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-08-2004 10:53 AM
тАО06-08-2004 10:53 AM
Re: Perl Help needed
if (/^SWBAMSFR/) {
$count++;
my $name = "$uniq-$count.$testfile";
print STDERR "Test: New split name $name1\n";
$outfile and close $outfile;
open $outfile, ">$name1" or die "Test: can not create $name";
}
change $name1 to $name, and you should be fine.
Now insert those two 'use' statements in front of the script, and it would have clearly stated the error, I'm sure
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-09-2004 01:04 AM
тАО06-09-2004 01:04 AM
Re: Perl Help needed
$pname=*NEW ;
and
$pname=*NEW1 ;
(But what you are doing must work except if you are using strict-refs)
Now, if you want to print something to a
file "print" must understand that you want that.
Use
print $pname $_ ;
With these minor changes I ran your script against your testfile, which downloaded as
112028.txt and obtained
112028-1.testfile (855 bytes)
112028-2.txt (2181 bytes)
112028-3.testfile (352 bytes)
112028-4.txt (472 bytes)
I suggest a visit to
http://www.perldoc.com/perl5.8.4/pod/perlfaq5.html