Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: Perl Sorting Help

by frozenwithjoy (Curate)
on Feb 12, 2013 at 23:06 UTC ( #1018462=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Perl Sorting Help
in thread needed help

Hey zee3b, I figured I'd respond to your PM here so I'd have more room.

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!
# Read through file/data one line at a time. while (<DATA>) { # Remove newline from end of line (actually not necessary for your + input). chomp; # If a line ends with '{', use a regular expression (REGEX) to cap +ture # the relevant portion by having that portion surrounded by parent +heses. # Push the captured string (contained within the variable '$1', si +nce it # is the first captured string) onto the end of the array '@curren +t 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 por +tion, # 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 /}$/; }


Comment on Re^3: Perl Sorting Help
Download Code
Replies are listed 'Best First'.
Re^4: Perl Sorting Help
by zee3b (Novice) on Feb 13, 2013 at 04:05 UTC

    Thanks a lot frozenwithjoy. That really cleared a lot of my confusions. It's the regular expressions I need to learn.

    7stud, thanks for the advice. I bought the Learning Perl book and will definitely follow your advice, finish the book and move onto the intermediate level one.

Re^4: Perl Sorting Help
by Anonymous Monk on Feb 13, 2013 at 03:50 UTC
    Thanks a lot frozenwithjoy. That really cleared a lot of my confusions. It's the regular expressions I need to learn. 7stud, thanks for the advice. I bought the Learning Perl book and will definitely follow your advice, finish the book and move onto the intermediate level one.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (10)
As of 2015-07-28 11:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (254 votes), past polls