There's no need to change directories, though you can do it with the chdir command.
Here's some code that will do what you want:
#!/usr/bin/perl use warnings; use strict; # # Open file for reading (explicit), die on error # open SERVICES, '<', '/etc/services' or die "cannot open /etc/services: $!"; # # Read thru each line (put into $_), and print the captured # comment text if the line has a comment (anything after a # # to the end of line). Note that this doesn't include the # hash (pound, octothorpe, et al.); move it inside the parens # for that behavior. # while (<SERVICES>) { print "$1\n" if /#(.*)$/ } # Close filehandle close SERVICES;
Update Note in comment about not printing the hash mark.
In reply to Re: Change directories, Print just the comments
by The Mad Hatter
in thread Change directories, Print just the comments
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |