Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Help with regular expression

by heatblazer (Scribe)
on Oct 11, 2012 at 07:56 UTC ( #998386=note: print w/ replies, xml ) Need Help??

in reply to Help with regular expression

Hello, I have a similar soluttion mentioned here by simply substitutin all brackets with a whitespace then split everything by whitespaces.

#!/usr/bin/perl -w use strict; $ARGV[0] = ""; open FH, $ARGV[0] or die "Can`t open it: $!\n"; my @parsed = grep { s/[()]/ /igsx } <FH>; close FH; foreach (@parsed) { print $_, "\n"; } #some testing outputs my @vars=(); foreach (@parsed) { push @vars, split(" ", $_); } foreach (@vars) { print $_, "\n"; }

It just parsed them with the corresponding vars, but you may need more and more parsing for youur desires.

Tree structure will be a good solution for that task.

Comment on Re: Help with regular expression
Download Code
Replies are listed 'Best First'.
Re^2: Help with regular expression
by choroba (Canon) on Oct 11, 2012 at 08:19 UTC
    You lose the structure. Also, it does not work for values containig whitespace, as in HLD.
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Point taken. I am still a learner and I try to catch up with you guys, I`ve just beat Lama book and I am going to Alpaca, so I didn`t know how to make C`s arrays of arrays or hashes with arrays, so building a real tree wasn`t possible for me yet. However one of the users offered a stack, something I did not come up with, and quite easy one in Perl... More practice I guess.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://998386]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (10)
As of 2015-12-01 21:20 GMT
Find Nodes?
    Voting Booth?

    My keyboard shows this many letters:

    Results (27 votes), past polls