Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Help with regular expression

by heatblazer (Scribe)
on Oct 11, 2012 at 07:56 UTC ( [id://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.

Replies are listed 'Best First'.
Re^2: Help with regular expression
by choroba (Cardinal) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://998386]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2024-06-22 10:26 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.