G'day Aldebaran,
" can't figure out why the shebang and comments endure: ... How is my regex not sieving out the comments?"
Your regex, /^#*$/, is anchored at the start (^) and end ($). Consider:
$ perl -E ' my $x = "#shebang\n\nstatement1\n#comment\nstatement2"; my @lines = split /\n/, $x; say "All lines:"; say for @lines; say "-" x 40; say "Your regex:"; say for grep ! /^#*$/, @lines; say "-" x 40; say "Better regex:"; say for grep ! /^#/, @lines; say "-" x 40; ' All lines: #shebang statement1 #comment statement2 ---------------------------------------- Your regex: #shebang statement1 #comment statement2 ---------------------------------------- Better regex: statement1 statement2 ----------------------------------------
Note how your regex is removing blank lines. Did you want that?
Addendum: If the answer to that last question is yes, you can use /^(?:#|$)/.
— Ken
In reply to Re^3: wrapping bash and astronomy
by kcott
in thread wrapping bash and astronomy
by Aldebaran
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |