sf wrote:
this is my problem: variable theParent never updates - it always stays
"1"
You have bigger problems than that; for instance your program misses:
use strict;
use warnings;
if ($ARGV[0] eq ""){
print STDOUT "Enter the filename and path you wish to use:";
$nameoffile=<STDIN>;
}
}
Faulty logic. You can just say:
print STDOUT "Enter the filename and path you wish to use:";
$nameoffile=<STDIN>;
$theHL = 1;
$theParent = "1";
open (FILENAME, "$nameoffile") or die "cant open file\n";
open (TOFILE,">builtFile.txt");
#initialize variable and assure it is global to the entire program
#read through the original file
while ($line = <FILENAME>){
my($theParent)="1";
Since that variable is lexically scoped, it's quite another variable
than the global $theParent above. Furthermore, since you apparently do
not want the variable to be reset at each iteration of the while loop,
you'd better drop that statement.
#split the file by *'s and put each 'split' into a node of array @array
@array=split(/\*/,$line);
if (@array[0] eq "HL") {
@array[0] better written as $array[0] etc. (which Perl would have told
you if warnings had been enabled).
if (@array[3] eq "20") {
my($theParent) = $array[1];
Again quite another variable than the first global $theParent. Drop the
my().
$line = "@array[0]*$theh...@array[3]*@array[4]";
$theHL = $theHL + 1;
}
}
if (@array[0] eq "HL") {
if (@array[3] eq "22") {
$line = "@array[0]*$thehl*$thepare...@array[3]*@array[4]";
$theHL = $theHL + 1;
}
}
$line =~ s/$/~/;
if ($line ne "~\n") {
print TOFILE $line;
}
Missing right curly to end the while loop.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/