Hello, pyari_billi and welcome to the monastery.

The warning is alerting you to the fact that by the time your code gets to line 19 there is no value in $n[$j] because the only thing you have put in @n is 0. You must store a value in a variable (scalar/array/hash) before you can extract it.

But I want to set the size of @n dynamically depending on the size of the data file.

You can either do that as you go along (arrays can be expanded or shrunk dynamically in perl) or you can perform 2 passes of the file. The former is usually preferable. Something like:

foreach my $j ($col_start .. $#column) { $n[$j] //= 1; # Choose whatever suitable value you want here - it +could even be an expression $x[$n[$j]][$j] = $column[$j]; # ... etc.

The value you choose to set will depend on your algorithm, of course. Perhaps you want to use $.? Anyway, I hope this makes the problem more clear to you.


🦛


In reply to Re: Calculate jackknife error from of each column of a multi-column file by hippo
in thread Calculate jackknife error from of each column of a multi-column file by pyari_billi

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.