#!/usr/bin/perl -w # Perl: example on how to read lines from standard input # # Comments containing "Perl:" are obvious to a Perl programmer # and would not normally appear in a production Perl program. # # - Ian! D. Allen idallen@idallen.ca # Perl: only print the prompt if STDIN is a terminal (not a file) # Perl: "warn" prints on standard error (useful for errors and prompts) # warn "Enter message, end with EOF (usually CTRL-D):\n" if -t STDIN; # Perl: the <...> operator stores each line read internally in variable $_ # while(){ chomp; # Perl: remove trailing newline from $_ my $len = length; # Perl: calculate length of $_ print "You entered ($len): '$_'\n"; } print "Read $. lines.\n"; # Perl: $. is the current line number