in reply to Re: insert data into data structure
in thread insert data into data structure

I really would like to show you some code but there is no good code to show and the one i had i just deleted it. This is more or less the code i had before falling asleep in the chair yesterday:
for my $line (@data)
{
    if($line =~ /^\.+\$/)
    {
        $nameTmp = $line;
        push @listSection, $nameTmp, \@arrTmp;
    }
    elsif($line =~ /(.+)=(.+)|#(.*)/)
    {
        %hashTmp =
        (
        key => "$1",
        value => "$2",
        comment => "$3",
        );
        push @arrTmp, \%hashTmp;
    }
}
print "\n";
print Dumper(@listSection);

Replies are listed 'Best First'.
Re^3: insert data into data structure
by Ea (Chaplain) on Nov 30, 2015 at 11:15 UTC
    This if($line =~ /^\.+\$/) probably doesn't do what you want. To my eyes, it only matches a line that begins .+$, but backslash $ doesn't seem to do anything other than mess up the match. You might try the Regular Expression test page. If that first line doesn't match, you never get anything in @listSection, so there's nothing to Dump.

    Sometimes I can think of 6 impossible LDAP attributes before breakfast.

    http://act.yapc.eu/lpw2015/ It's that time of year again!

      sorry, i wrote it fast, the right regex is  ($line =~ /^\[.+\]$/) i didn't put the tag of code.

        Your example data doesn't show the square brackets. Can you give a better example of what your data looks like?

        Based on your description, a hash of hashes sounds like what you want, since the key to picking out the data you want is a string like "Paragraph5". If the search string is a hash key, getting the related values is simple and very fast.

        Dum Spiro Spero
        ... i didn't put the tag of code.

        Because you posted this as a registered user, you can go back and edit the post to add code tags. Please see How do I change/delete my post?.


        Give a man a fish:  <%-{-{-{-<

      sorry, i wrote it fast, the right regex is =~ /^\.+\$/