Contents / Previous / Next


Perl Example Script

open(TTY, '/dev/tty'); <TTY> =~ /^y/i && foo(); # do foo if desired if (/Version: *([0-9.]*)/) { $version = $1; } next if m#^/usr/spool/uucp#; $arg = shift; # poor man's grep while (<>) { print if /$arg/o; } # compile only once if (($F1,$F2,$Etc) = ($foo =~ /^(\S+)\s+(\S+)\s*(.*)/))

This last example splits $foo into the first two words and the remainder of the line, and assigns those three fields to $F1 , $F2 and $Etc . The conditional is true if any variables were assigned, i.e. if the pattern matched.