0

I am trying to parse a file that looks like this :

TIME: 07/24/13 15:30:04
ASPATH: 172193 19601 14835 19074 19420 4704 8266 9486 8580

I already starting working on the parser, but since i am new to perl, i can't figure out how i may parse a particular line that troubles me which is,

 ASPATH: 172193 19601 14835 4758 15731 3341 

These are graph nodes, meaning links 172193-->19601--->14835 and so on. I don't want to store this Data in my database as it is, rather, i want to break it and insert each node in the database(because of relation with the database of node which this table will link to) with an index representing the path. So for example,

node       index
172193       1
19601        2
14835        3

and so on.....

So the index is meant to make me know the connection between the nodes. So if i start to process the next record, it will start from index 1 again.

This is what i already have not including all attributes (especially ASPATH) yet which troubles me.

        } elsif (/^ASPATH/) {
            ##HERE IS WHERE I AM LOST AS EXPLAINED** 
        }

1 Answer 1

2
        }elsif (/^ASPATH/) {
            my @nodes = split /\s/;
            shift @nodes;   # discard ASPATH

            my $index = 0;
            foreach my $node (@nodes) {
                $index++;

                # process ($node, $index) here
            }
        }
Sign up to request clarification or add additional context in comments.

2 Comments

@choroba: You can use ' ' as an argument there also to split on whitespace. But yes, '\s' is incorrect. Thanks for the edit. FWIW, this error is rampant in the original question as well.
In fact, you can use split with no arguments in this case :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.