Hi folks
I am a noob at Perl, but I want to write a script that will convert x,y,z cartesian coordinates from atomic units to angstroms, the conversion factor is %convfact in the script (see below). First, here is one line of the array holding the coordinates. I want to return the line as it is - the character at $column[0] unchanged, and the three coordinates each multiplied by %convfact. I've tried everything (like $column[1]*%convfact - but that is illegal, it seems). Any help welcome, I'm desperate now !!!
Line of input file:
C1 -8.52485691 6.79961254 4.40504608
Script:
use warnings;
use strict;
my $convfact = 0.529177239;
print $convfact;
my @records;
open FILE, "C0out.xyz" or die $!;
#we will read the file line by line
while(<FILE>)
{
# read each line in $_
# chomp the trailing newline from $_
chomp;
my @columns = split ", ", $_;
push @records, \@columns;
}
# print the array
foreach my $record(@records) {
foreach my $column(@{$record}) {
# test the last column
if(\$column == \$$record[-1]) {
print $column;
}
else {
print $column;
}
}
print "\n";
}
I am a noob at Perl, but I want to write a script that will convert x,y,z cartesian coordinates from atomic units to angstroms, the conversion factor is %convfact in the script (see below). First, here is one line of the array holding the coordinates. I want to return the line as it is - the character at $column[0] unchanged, and the three coordinates each multiplied by %convfact. I've tried everything (like $column[1]*%convfact - but that is illegal, it seems). Any help welcome, I'm desperate now !!!
Line of input file:
C1 -8.52485691 6.79961254 4.40504608
Script:
use warnings;
use strict;
my $convfact = 0.529177239;
print $convfact;
my @records;
open FILE, "C0out.xyz" or die $!;
#we will read the file line by line
while(<FILE>)
{
# read each line in $_
# chomp the trailing newline from $_
chomp;
my @columns = split ", ", $_;
push @records, \@columns;
}
# print the array
foreach my $record(@records) {
foreach my $column(@{$record}) {
# test the last column
if(\$column == \$$record[-1]) {
print $column;
}
else {
print $column;
}
}
print "\n";
}