Hi, I have a problem: I am reading file version.txt and adding some format to it row by row. version.txt could look like
Matt 100 John 150 Laura 150
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....
format_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'; }
BR Hewarn

In reply to Lost arrays by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.