<?xml version="1.0" encoding="windows-1252"?>
<node id="1018462" title="Re^3: Perl Sorting Help" created="2013-02-12 18:06:55" updated="2013-02-12 18:06:55">
<type id="11">
note</type>
<author id="971084">
frozenwithjoy</author>
<data>
<field name="doctext">
Hey [zee3b], I figured I'd respond to your PM here so I'd have more room.

&lt;blockquote&gt;&lt;i&gt;Hey, thanks a lot for the help. That really worked and was exactly what I was looking for. When you get a few mins, can you please explain how the code works for my understanding. Thanks! &lt;/i&gt;&lt;/blockquote&gt;

&lt;c&gt;
# Read through file/data one line at a time.
while (&lt;DATA&gt;) {

    # Remove newline from end of line (actually not necessary for your input).
    chomp;

    # If a line ends with '{', use a regular expression (REGEX) to capture
    # the relevant portion by having that portion surrounded by parentheses.
    # Push the captured string (contained within the variable '$1', since it
    # is the first captured string) onto the end of the array '@current command'.
    # This REGEX matches:
        # the beginning of the line: ^
        # 0 or more spaces: \s*
        # 1 or more of anything (captured because it is in parentheses): (.+)
        # 1 space followed by 1 {: \s{
        # the end of the line: $
    push @current_command, $1 if /^\s*(.+)\s{$/;

    # If a line ends with ';', use a REGEX to capture the relevant portion,
    # then print out the contents of the array followed by the string you
    # just captured and assigned to '$last_term'.
    if (/^\s*(.+);$/) {
        my $last_term = $1;
        say "set @current_command $last_term";
    }

    # If a line ends with '}', that means we are moving up a level, so you
    # remove the last element of the array '@current_command'.
    pop @current_command if /}$/;
}
&lt;/c&gt;</field>
<field name="root_node">
1018430</field>
<field name="parent_node">
1018449</field>
</data>
</node>
