Your skill will accomplishwhat the force of many cannot PerlMonks

### Re^4: How to create loop in perl dynamically

 on Sep 26, 2012 at 19:03 UTC ( #995854=note: print w/ replies, xml ) Need Help??

This is requirement.
1. I have data in DB
ex: of data in DB.
Student|Subject|Marks aaa|eur|100 aaa|usd|90 aaa|eur|101 aaa|usd|80 aaa|eur|90 --------- bbb|usd|80 bbb|usd|100
.......
So Mapping goes like below:
aaa->eur->100 aaa->eur->101 aaa->eur->90 aaa->usd->90 aaa->usd->80

Output will be : 1.If level=2
aaa,eur,sum(100,101,90) aaa,usd,sum(90,80)
so on..

2.If level is 3, we have more detailed level
aaa,eur,100,sum(gg) aaa,eur,100,sum(hh) aaa,eur,101,sum(gf) aaa,eur,101,sum(s) aaa,eur,90,sum(dd) aaa,eur,90,sum(sf) aaa,usd,90,sum(eq)
...
Here its the users choice if u want to print at 2 level or 3 level or more..
If level is 4 then we go into detailed level.

Hope this requirement helps
I want to dynamically store the values in arrays and iterate through these arrays and get this values.

Replies are listed 'Best First'.
Re^5: How to create loop in perl dynamically
by djerius (Beadle) on Sep 26, 2012 at 20:01 UTC
I think you're using the wrong data structure for your data; use hashes, not arrays.

Read your data in, split it into fields, then construct nested data structures to hold your data. The Perl Data Structures Cookbook (perldsc) has all of the information you need.

You can then either directly extract the information at the requested level or use Data::Path or Data::DPath.

Create A New User
Node Status?
node history
Node Type: note [id://995854]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2016-07-28 14:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
What is your favorite alternate name for a (specific) keyboard key?

Results (255 votes). Check out past polls.