Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What is your program supposed to be doing? Your current program is looking for the lines that have <code>matched pattern</code> and storing <strong><em>THOSE VERY LINEs</em></strong> into three different arrays. All other lines are ignored.</p> <p>You show some sort of example output, but there's no real relationship between your output and input.</p> <p>First, learn about <a href="http://perldoc.perl.org/perlreftut.html" rel="nofollow">references</a>, so you don't need five different arrays. In my example, I use an array of arrays to store all of your separate files. If each file represents something else, you could use an array of hashes or a hash of arrays or a hash of hashes of arrays to represent this data in a unified structure. (Don't get me started on how you really should learn object oriented Perl. Get the hang of references first).</p> <p>Also get a book on modern Perl and learn the new Perl syntax. It looks like your Perl reference is for Perl 4.0. Perl 5.0 has been out since 1994. There's a big difference between Perl 4 and Perl 5 in the way syntax is done. </p> <pre><code>use strict; use warnings; # Prints out your data strtucture use Data::Dumper; my $array_num; my @array_of_arrays; use constant { PATTERN =&gt; qr/matched pattern/, }; while (my $line = &lt;DATA&gt;) { chomp $line; next if $line =~ /^\s*$/; #Skip blank lines if ($line =~ PATTERN) { if (not defined $array_num) { $array_num = 0; } else { $array_num++; } next; } push @{ $array_of_arrays[$array_num] }, $line; } print Dumper (\@array_of_arrays) . "\n"; __DATA__ matched pattern 1 line1:10 line2:20 line3:30 next matched pattern 2 line1:5 line2:10 line3:15 next matched pattern 3 lineA:A lineB:B lineC:C </code></pre> <p>OUTPUT. Each set of lines are in a different array:</p> <pre><code>$VAR1 = [ [ 'line1:10', 'line2:20', 'line3:30' ], [ 'line1:5', 'line2:10', 'line3:15' ], [ 'lineA:A', 'lineB:B', 'lineC:C' ] ]; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload