Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, i've got a bit of a problem here that i need your advice on how to go about it.

I have to create a script, that when operated on specific text files, will be able to read diagrams like those below. It should determine which are left connectors and which are right connectors and associate abbreviated names to the respective connectors, e.g. L1, L2, R2, R5, obviously depending on which side the connector is and how many there are.

[ ABC12 ]----------38.00M----------[ DEF23 ] |---16M------[ DEF23 ] [ ABC12 ]---------- |---16M------[ DEF34 ] [ ABC12 ]-------- | [ ABC23 ]--------|---42m---[ DEF23 ] | [ ABC34 ]--------

The structure is as it appears...bracket, tab, connector id, space, bracket, dashes, length, dashes, bracket, space, connector id, tab, bracket.

It should be able to recognise any number of connectors on each side (1 on left 6 on right, 2 on left 4 on right etc).
Note that there is only one diagram in each text file that is read in.
The length/name of the connector ids, number of dashes denoting the cable & the cable length isn't consistent in any way. The only thing that is consistent is the brackets surrounding the connector ids.

Im having trouble making a program recognise which is on the left and which is on the right. If it were 1 to 1, 1 to 3 etc it would be easy as i would assume for each line, the first '[' it sees belongs to a left connector and the second '[' to a right connector, but you have some lines that only have the right connector on.

Any help/pointers/advice etc anyone can offer is very appreciated. Cheers, Steve

Edit by tye, escape [

Replies are listed 'Best First'.
Re: electronic diagram recognisation
by BrowserUk (Patriarch) on Oct 16, 2003 at 21:12 UTC

    You don't say how you want to use the information parsed, so it difficult to know how best to structure it. Parallel arrays is almost certainly not the best way, but it was simple for a test.

    I've scrunched all the data into a single 'file', and used 'paragraph mode' for simplicity.

    Output

    P:\test>junk2 ABC12 (38.00M) connect to DEF23 (38.00M) ABC12 (-) connect to DEF23 DEF34 (16M 16M) ABC12 ABC23 ABC34 (- - -) connect to DEF23 (42m)

    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    Hooray!

Re: electronic diagram recognisation
by sauoq (Abbot) on Oct 16, 2003 at 20:20 UTC

    If you only have one diagram per file and the only things that matter are the "connector id" and the side it is on, this should be very easy. Left hand side connectors are all matched by /^\s*\[([^]]+)\]/ and those on the right are matched by /\[([^]]+)\]\s*$/. Just check each line for both.

    Untested:

    while (<>) { /^\s*\[([^]]+)\]/ and push @left, $1; /\[([^]]+)\]\s*$/ and push @right, $1; } print "Left : $_\n" for @left; print "Right : $_\n" for @right;

    If you need to actually trace the lines, the problem is more difficult.

    -sauoq
    "My two cents aren't worth a dime.";
    
Re: electronic diagram recognisation
by sweetblood (Prior) on Oct 16, 2003 at 19:37 UTC
    Have you got any code to show what you've done? It would be most helpful.