Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

just a touch 1

Status
Not open for further replies.

Alfio75

Programmer
Oct 25, 2005
25
MX
Hello there trojan.
I'm trying to get a line in this format:

#include "background.inc"

#declare atomos=
union{

sphere{< -3.5400 , 2.8462 , 0.0708 >Re}

So i change this line and i get blank lines in the files.
What's wrong with that?

as well I need to put another lines on the top of each file.


print FH "sphere={<", join(",", split),"Re}",">\n";

This is my file.

Would be great to calculate something inside this script.
Sorry guys I'm a Fortran programmer and i met that perl it's a great choose to do this job.

#!/usr/bin/perl -w
#Este script separa en bloques la informacion de las posiciones atomicas obtenidas
#Al usar fil2xyz, es decir usa un archivo que contiene posiciones atomicas en bloques.

#use strict;
print "El archivo de posiciones debe estar en el directorio actual\n";
system pwd;
print "\n";
print "Dame el nombre del archivo de entrada:\n";
$infile = <STDIN>;
chomp $infile;
# checamos si el archivo existe
until (-f $infile) { # -f significa checar si hay un archivo con este nombre
print "Ese archivo no existe\n";
$infile = <STDIN>;
chomp $infile;
}
# Se crea el directorio para los archivos de salida
print "\n";
print "Nombre del directorio que contendra los archivos xyz?\n";

$output_directory = <STDIN>;
chomp $output_directory;
# Verifico que no exista ese nombre de directorio.

while (-d $output_directory) { #
print "Ya existe ese directorio, intenta otro nombre\n";
$output_directory = <STDIN>;
chomp $output_directory;
}
# Si no existe ese directorio, entonces procede a crearse
mkdir ($output_directory, 0777) || die "No se puede crear $output_directory";
opendir (OUTPUTDIR, $output_directory) || die "No se puede abrir $output_directory";
# parametros
print "\n";


###################################################################
# principal
###################################################################

#Creo archivos de acuerdo al numero de pasos que tengo.

open (INFILE, $infile);

my $number = 1;
open FH, ">$output_directory/$number.dat" or die "No puedo abrir [$number.dat]";
#print FH " #include "background.inc"\n";
#print FH "#declare atomos=\n";
#print FH "union {\n";


#abro el archivo como escritura.
while(<INFILE>) {
chomp;
if(/\s*$/) {
# \s indica espacio, caracter en blanco,tab o newline
close FH;
$number++;
open FH, ">$output_directory/$number.dat" or die "No se puede abrir [$number.dat]";
next;
}
print FH "sphere={<", join(",", split),"Re}",">\n";
}
close FH;

close FH;
close INFILE;
print "***** Se acabo el proceso*****\n";
print "$number Archivos creados\n";

 
if you try to explain a little better what is it that you want and change the spanish to english, we might be able to help.


``The wise man doesn't give the right answers,
he poses the right questions.''
TIMTOWTDI
 
Also, use the
Code:
[/code ] tags (no spaces) to preserve code formatting.  If it's easier to read, it's easier to help ;-)

[code]
open FH, "<file.txt";
while (<FH>) {
  @array=split//, $_;
  foreach (@array) {
    print "$_\n";
  }
}

Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Sorry Alfio,
Been very busy.
I'll try to get to you as soon as I can if no-one else helps you enough in the mean time.


Trojan.
 
Hello.
I answered a part of my confusion. I got another question to u.
I'm trying to print double quotes . So how can I print to my file this kind of phrase?

#include "background.inc"

i tried

print FH "#include" qq("background.inc"\n)

I meant i want to print double quotes .

Thanks in advance
Alfio
 
print FH "#include \"background.inc\"\n";

Escape the double quotes with a backslash. Or use single quotes.

print FH '#include "background.inc"';
print FH "\n";


----

In need of programming book recommendations.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top