On Mon, 16 Sep 2002, Nandita Mullapudi wrote:
> I have a parsed output in a single file, that looks like this
>
> Pf_sumthing.bln
>
> blah
> blah
>
> Pf_sumthingelse.bln
>
> blah
> blah
>
> and so on,
> I want to parse this file such that i create 80 or as many little files,
> each has the filename as its respective Pf_something and content has the
> blah blah.
>
> can anybody point me in the right way? this is what i've been trying to do
> -use split (/Pf.*\w/) and try to separate the contents..but i'm not
> getting there..
The split is one line of your code, what about the rest? You are splitting
on 'Pf' followed by 0 or more non-newlines and a word character at the
end. Not quite sure what you are trying to do.
This is one way to do it
#!/usr/local/bin/perl -w
use strict;
use FileHandle; # perldoc FileHandle
my $your_input_file = shift # Assuming the file to parse is a command line arg
my ($inputfh, $newfh);
$inputfh = new FileHandle $your_input_file,"r" or
die "Failed to open $your_input_file: $!\n";
while (<$inputfh>) {
if (/^(Pf_.*)\.bln$/) {
chomp;
undef ($newfh);
$newfh = new FileHandle $1, "a" or
die "Failed to open $1: $!\n";
} elsif (defined ($newfh)) {
print $newfh $_;
}
}
undef ($newfh);
undef ($inputfh);
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]