sf wrote:
this is my problem: variable theParent never updates - it always stays
"1"

if ($ARGV[0] eq ""){

if ( @ARGV != 1 ) {


        print STDOUT "Enter the filename and path you wish to use:";
        $nameoffile=<STDIN>;

          chomp $nameoffile;

        }
}

You have a } there without a matching {.

$theHL = 1;
$theParent = "1";

open (FILENAME, "$nameoffile") or die "cant open file\n";
open (TOFILE,">builtFile.txt");

You should *always* verify that the file opened correctly. You should include the $! variable in the error message so you know *why* it failed.

#initialize variable and assure it is global to the entire program

#read through the original file
while ($line = <FILENAME>){

  my($theParent)="1";

my() *creates* a new variable $theParent each time the while loop iterates.


  #split the file by *'s and put each 'split' into a node of array
@array
  @array=split(/\*/,$line);

        if (@array[0] eq "HL") {
                if (@array[3] eq "20")  {

You are using an array slice when you should be using a scalar. If you had enabled warnings then perl would have informed you of this.

        if ($array[0] eq "HL") {
                if ($array[3] eq "20")  {


                  my($theParent) = $array[1];

my() *creates* a new variable $theParent that will only be visible inside the braces {}.

                  $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;
  }


John
--
Those people who think they know everything are a great
annoyance to those of us who do.        -- Isaac Asimov

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to