Hello emadmahou,

I’m not at all clear on what you are trying to do. It would be a great help if you could give (small!) sample files, one each for $inputFile and “test.xlsx”, together with the output (in “$inputFile.seed.txt”) you want to generate.

Here are some preliminary observations:

  1. The variable %DivisionHash is declared but never used.
  2. Since neither the name of the Excel file nor its contents change during the loop, there is no need to re-parse it on every loop iteration. Parse it once, before the loop, and access the parse information in the loop as needed.
  3. Since your values are strings, you should compare then using eq, not ==: if ($DivisionHash eq $value). (ww stole my thunder on this one!)
  4. The commented-out sections of your code seem to be leftover from an earlier design. By all means keep them for reference (in a separate file, say), but it will help you to “see” your code more clearly if you remove them from the current script.
  5. Likewise, there are places where the comments don’t match the code:
    # Get cell value from excel sheet1 row 1 column 2 for my $worksheet ( $workbook->worksheets() ) {
    and unexplained magic numbers:
    my $cell = $worksheet->get_cell(1,9);
    Cleaning up the code, and documenting what it currently does, will help you to clarify its structure and logic.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re: loop through xlsx and get specific column cell values by Athanasius
in thread loop through xlsx and get specific column cell values by emadmahou

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.