Regular Expressions   «Prev  Next»

Perl m// operator - Exercise

Objective: Write a program that prints out all of the tags in an HTML file.

Background on HTML

Just in case you are unfamiliar with HTML, tags in an HTML file are enclosed in brackets: < and >. The program you will write should print just the name of the tag (the first word within the brackets), one per line of output. Keep in mind that a tag can span lines of text.

Alternate Exercise

An alternate exercise is to write a program that prints the names of all the services defined in your /etc/services file. (The /etc/services file is used to associate the names and port numbers of Internet services. On Windows NT systems, the file is in C:\winnt\system32\drivers\etc\services.)
If you are running Windows 95 or the Mac OS, you can cut and paste the text from the service file below into a document and use that to run your script. Or, you can find your services file at one of these locations:

C:\windows\services
C:\windows\system\services
C:\winnt\system32\drivers\etc\services

#ident  "@(#)services   1.13    95/07/28 SMI"   /* SVr4.0 1.8   */

#
# Network services, Internet style
#
tcpmux          1/tcp
echo            7/tcp
echo            7/udp
discard         9/tcp          sink null
discard         9/udp          sink null
systat         11/tcp          users
daytime        13/tcp
daytime        13/udp
netstat        15/tcp
chargen        19/tcp          ttytst source
chargen        19/udp          ttytst source
ftp-data       20/tcp
ftp            21/tcp
telnet         23/tcp
smtp           25/tcp          mail
time           37/tcp          timserver
time           37/udp          timserver
name           42/udp          nameserver
whois          43/tcp          nicname   # usually to sri-nic
domain         53/udp
domain         53/tcp
hostnames     101/tcp         hostname   # usually to sri-nic
sunrpc        111/udp         rpcbind
sunrpc        111/tcp         rpcbind

Submit your exercise

Paste your program code in the text area below. Make sure you include mention of which exercise your submission is in response to.
Click the Submit button when you are finished.