Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
The problem I have, is that when I am calling in main program --system 'perl test'-- file, which looks like this belowe, my format_style function works OK. But when I tried to add the code part to main program and call the function in there instead of system call, I am loosing information about arrays "names" and "vers" in the second while statement. Why is that....Matt 100 John 150 Laura 150
BR Hewarnformat_style(); # FUNCTION FORMAT_STYLE----------------------------------------------- +------ # Final stage where text is replaced to correct format sub format_style { # Function calls to create desc.txt open (VER,"version.txt"); while (defined ($rows = <VER>)) { chop($rows); ($rows1,$rows2)=split(/\ /,$rows); $names[$i]=$rows1; $vers[$i]= $rows2; $i++; } close VER; $i=0; $ch1=":"; $ch2=" "; open (ROWS, "desc5.txt") || die "File not found"; while (defined ($rivi = <ROWS>)) { chomp $rivi; if($rivi =~ /^$names[$i]/) { chomp $rivi; # IN THIS PART I DONT HAVE ARRAYS ANYMORE AVAILABLE # Counting length of words my $L1=length($names[$i]); my $L2=length($vers[$i]); #print "Length for $names[$i] =$L1, and for $vers[$i]=$L2\n" +; my $pad1=(27-($L1)); my $pad2= (6-($L2)); my $pad1_1=(" " x $pad1); my $pad2_2=(" " x $pad2); #chop $vers[$i]; $rivi="\n$names[$i]$pad1_1$ch1$ch2$vers[$i]$pad2_2$ch1\n"; open (E,">>style1.txt"); print E $rivi; close E; $i++; } elsif ($rivi) { chomp $rivi; my $pad3=(" " x 36); open (E,">>style1.txt"); print E "$pad3$rivi\n"; close E; } + } close ROWS; system 'cp style1.txt desc5.txt'; system 'rm style1.txt'; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Lost arrays
by robartes (Priest) on Dec 02, 2002 at 13:19 UTC | |
by BrowserUk (Patriarch) on Dec 02, 2002 at 13:33 UTC | |
|
Re: Lost arrays
by rdfield (Priest) on Dec 02, 2002 at 12:38 UTC |