Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # now it's your turn - please replace the pseudo code comments ### with Perl 6 ...
- #| edit a text file at the first matching line
- multi sub MAIN ('edit', $filename, *@search-terms) {
- my $matching-line-number = 0;
- # add some code of your own here to ...
- ### slurp in the lines of the file (hint: how is the config file read?)
- my $contents = slurp $filename;
- ### join the search terms into a string
- my $terms = @search-terms.join(' ');
- ### make a pattern from the string
- ### find the first line in the file that matches the pattern
- loop (my $i = 0; $i < $contents.split("\n").elems; $i++) {
- if $contents.split("\n")[$i].contains($terms) {
- $matching-line-number = $i + 1;
- last;
- }
- }
- # open your editor at the first line that matches
- MAIN('edit', $filename, $matching-line-number);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement