Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: File Find/Replace with the replacement coming from part of earlier matched string

by sundialsvc4 (Monsignor)
on Feb 05, 2013 at 14:18 UTC ( #1017182=note: print w/ replies, xml ) Need Help??


in reply to File Find/Replace with the replacement coming from part of earlier matched string

This is an absolutely classic case for a “finite-state machine (FSM)” algorithm.   (I’ll leave that for you to Google WikiPedia.)   There are four different “kinds” of input-lines:

  1. PCName: $1
  2. Command$1: $2
  3. blank line
  4. end-of-file
... and a suitable but arbitrary number of “states.”

The logic of an FSM is very powerful because it moves from one “state” to another based on the current input (one of the four types listed above) and the current state.   At each state, it can call a particular subroutine or piece of logic.   This approach is also very flexible, easily modified, and it’s also clear because the logic of deciding what kind of input you have is clearly separated from the state-driven logic that does something about it.


Comment on Re: File Find/Replace with the replacement coming from part of earlier matched string

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2014-07-13 18:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (251 votes), past polls