Hello,
I'm brand new to perl, and am learning to automate certain actions using it.
I feel my question is simple, but i'm having a difficult time finding answers in books and google, so i've joined this forum.
I have a large text file that looks like this:
MOLECULE:name_of_molecule.ZMAT ................................
.....
.........
.............
.................
.....................
END
MOLECULE:name_of_molecule2.ZMAT
.
.
.
END
.
.
.
Basically, there are 148 separate files I'm trying to grab from this.
Each file, i need the name to be - name_of_molcule.ZMAT -
But within each new file, I need from MOLECULE all the way to before END to be copied into that specific name_of_molecule.ZMAT.
All name_of_molecules are different, and all /MOLECULE
.*)END/ are different.
Here is what i've done with this so far:
#!/usr/bin/perl -w
open (GEOS, "G2_ZMATS") or die "Can't open GEOS: $!\n";
while (<GEOS>) {
chop;
if(/MOLECULE
(.*)\.ZMAT)./){
$name=$1;
$outfile="$name\n";
open (RESULTS, ">$outfile") or die "Can't open outfile: $!\n";
if(/(MOLECULE
.*)END)/s){
$geo=$1;
print RESULTS "$geo";
}
}
close (RESULTS);
}
close (GEOS);
this code does make 148 files that are named perfectly, but the files contain no information on the inside.
I appreciate any help on this matter, as I am a new chem grad student just learning how to eventually make life easier.
Thanks,
Tom
I'm brand new to perl, and am learning to automate certain actions using it.
I feel my question is simple, but i'm having a difficult time finding answers in books and google, so i've joined this forum.
I have a large text file that looks like this:
MOLECULE:name_of_molecule.ZMAT ................................
.....
.........
.............
.................
.....................
END
MOLECULE:name_of_molecule2.ZMAT
.
.
.
END
.
.
.
Basically, there are 148 separate files I'm trying to grab from this.
Each file, i need the name to be - name_of_molcule.ZMAT -
But within each new file, I need from MOLECULE all the way to before END to be copied into that specific name_of_molecule.ZMAT.
All name_of_molecules are different, and all /MOLECULE

Here is what i've done with this so far:
#!/usr/bin/perl -w
open (GEOS, "G2_ZMATS") or die "Can't open GEOS: $!\n";
while (<GEOS>) {
chop;
if(/MOLECULE

$name=$1;
$outfile="$name\n";
open (RESULTS, ">$outfile") or die "Can't open outfile: $!\n";
if(/(MOLECULE

$geo=$1;
print RESULTS "$geo";
}
}
close (RESULTS);
}
close (GEOS);
this code does make 148 files that are named perfectly, but the files contain no information on the inside.
I appreciate any help on this matter, as I am a new chem grad student just learning how to eventually make life easier.
Thanks,
Tom