On Wed, Dec 1, 2010 at 10:24 AM, Dennis Jakobi <roec...@googlemail.com>wrote:
> Hi there, > > I have the following problem: > > I want to read a logfile in which every line follows this rule: > <value1>:<value2>:<value3>... > > But the number of values differs. Sometimes a line has 2 values (the > minimum) and sometimes 3 or more values. Now I want to push these > values into a hash that follows that form: > $hash->{value1}->{value2}... > > This is what I have so far: > > sub readLog { > my $self = shift; > my $logfile = getFilename(); > > open LOG, "<$logfile"; > > foreach my $line (<LOG>) { > my @values = split /\:/, $line; > ... # at this point I don't know what to do :( > } > } > > Greetings > Dennis > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > > Hi Dennis I know a weird question that you likely already thought about but still why are you not using a combination of array and hash? $hash->{value1} = [ value2, value3, value4, ... ] It would save you a lot of headaches in looping over all values that are on that one line because how are you going to easily handle a situation where you have a hash of hashes with an undefined depth without having to jump to a lot of difficult hoops to make it work properly? Regards, Rob