Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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] = "www.perlmonks.org.txt"; 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
Re^2: Help with regular expression
by choroba (Abbot) 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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (19)
As of 2014-07-22 15:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (117 votes), past polls