Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As long as you are certain that there are <em>never</em> any commas in the data you should be OK using <code>split</code>. But even so it would be wise to limit the split to two fields, so that you get everything up to the first comma and everything after it</p> <p>There are a few issues with your code. First of all I hope you are putting <code>use strict</code> and <code>use warnings</code> at the top of all your Perl programs. That simple measure will catch many trivial problems that you could otherwise overlook, and so it is especially important before you ask for help with your code</p> <p>It isn't commonly known, but putting a newline <code>"\n"</code> at the end of your <code>die</code> string prevent Perl from giving file and line number details in the output of where the error occurred. While this may be what you want, it is usually more helpful to be given the extra information </p> <p>Your variable names are verly unhelpful, and by convention Perl variables consist of lower-case alphanumerics and underscores. Names like <code>@XYX</code> and <code>$W</code> don't help me understand your code at all!</p> <p>Rather than splitting to an array, it looks like you would be better off putting the two fields into two scalar variables to avoid all that indexing. And I am not sure what you intend by <code>@XYX = (["$data[1]","$data[1]"],)</code>. First of all do you really mean to use <code>$data[1]</code> twice? Secondly, your should <em>never</em> put scalar variables inside double quotes, as it does something very specific, and unless you know what that is you should avoid it. Finally, did you mean to <code>push</code> an anonymous array onto <code>@XYX</code> each time around the loop? Otherwise the contents of the array will be overwritten each time a line is read from the file, and the earlier data will be lost</p> <p>This program uses a regular expression to extract <code>$level_num</code> from the first field. All it does it find the first sequence of digits in the string, which can then be compared to the minimum required level <code>$min_level</code> to decide whether a line from the log is relevant</p> <pre><code>use strict; use warnings; my $file = 'xyz.csv'; my $min_level = 3; my @list; open my $fh, '&lt;', $file or die "Could not open '$file' $!"; while (my $line = &lt;$fh&gt;) { chomp $line; my ($level, $error) = split ',', $line, 2; my ($level_num) = $level =~ /(\d+)/; next unless $level_num &gt;= $min_level; push @list, [ $level, $error ]; } </code></pre>
    singulars
    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. 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.
    3. 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