$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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |