18.4. Exercise

See Appendix A for the answer.

  1. Convert the following shell script into a Perl program:

    cat /etc/passwd |
    awk -F: '{print $1, $6}' |
    while read user home
    do
      newsrc="$home/.newsrc"
      if [ -r $newsrc ]
      then
        if grep -s '^comp\.lang\.perl\.announce:' $newsrc
        then
          echo -n "$user is a good person, ";
          echo "and reads comp.lang.perl.announce!"
        fi
      fi
    done

Get Learning Perl, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.