Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by sundialsvc4 (Abbot)
on Feb 05, 2013 at 14:18 UTC ( [id://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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2024-04-26 06:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found