$var1 ={apple-A =>[30,40,50,60]}

Note that hash keys containing a dash must be quoted - so for a hash key of "apple-A", the output you've shown isn't valid Perl, and so as I said, Data::Dumper isn't the right tool for this job. If you want to get the output exactly as you showed here, then you'll have to build the strings yourself (keeping in mind that code you write yourself won't support any advanced escaping or quoting). You're already doing this in the code in your original post, only a few minor changes are needed - if you're having trouble figuring that out, then have a look at the documentation of sprintf to figure out the changes to your printf statement. If you need a different format than what you showed here, then please show exactly what you need.

because i have to achieve the average of it as well

Perl will transparently convert between strings and numbers, so to do the average as in your other thread Retrieve average, you actually don't need to worry about numbers being stored as strings.


In reply to Re^7: Adding text file data to hashes and array by haukex
in thread Adding text file data to hashes and array by Tigor

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.