Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Interpretation of my output

by musa (Initiate)
on Nov 06, 2008 at 09:39 UTC ( [id://721927]=perlquestion: print w/replies, xml ) Need Help??

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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Interpretation of my output
by GrandFather (Saint) on Nov 06, 2008 at 09:56 UTC

    Where did the script come from? Wherever you found it I would avoid. There are a few problems with it that indicate that it is old or written by someone who doesn't know Perl very well.

    For a start you should generally use chomp instead of chop.

    ([A-Z])([A-Z]) is better written ([A-Z]{2}).

    The print should be a single line using string interpolation: print "$tree\n";

    The substitution should use $1 instead of \1.

    You should always use strictures (use strict; use warnings;).

    Update: too enthusiastic finding improvements


    Perl reduces RSI - it saves typing
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Interpretation of my output
by wol (Hermit) on Nov 06, 2008 at 10:51 UTC
    I'm not sure what output you're hoping for, but there's certainly something odd in the regexp, and I don't think that the code you've posted here produces the output you've posted here. Certainly isn't the case when I try it.

    Did you want the final line of output to be this:

    (ABE)
    If so, you'll need to insert some []s to indicate that A-Z is one of a range of characters and remove some ?s to insist on brackets in the bits of your input you want to substitute. However, I can't commit myself to a final answer until I'm more cetain of what you're after :-)

    --
    .sig : File not found.

      (A(((BC)D)(EF))) (A(((BC)D)(EF))) (A((BD)(EF))) (A((BD)(EF))) (A(B(EF))) (A(B(EF))) (A(BE)) (A(BE)) (AB) (AB) A
      Could be the progression you require, otherwise as stated above you end up with (ABE).

      If that is what you require, then this could be what you need, if not, it's a starting point ;)

      s/\(([^)])[^)]\)/$1/
      If so, you'll need to insert some []s to indicate that A-Z is one of a range of characters

      I personally believe that (s)he has inserted those []'s, except that not having put code inside <code> tags as (s)he should have they rendered like hyperlinks due to the shortcuts available as part of the markup here at the monastery, à la A-Z. (ATM, that is: at a later time, someone reading this thread may hopefully find the root node duly edited...) To see the code closer to the way the OP really meant it you could try the xml view of the node.

      --
      If you can't understand the incipit, then please check the IPB Campaign.
Re: Interpretation of my output
by brsaravan (Scribe) on Nov 06, 2008 at 10:29 UTC
    You meant to say, you want to write a regular expression to get this output "(A(BD)(EF)) (AB(EF)) A(EF)) AE) A" using this input "(A((BC)D)(EF))"?. If no, please rephrase your sentense.
    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://721927]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-23 19:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found