#!/usr/local/bin/perl -w =head1 NAME pl_example -- very simple perl example script =head1 DESCRIPTION Perl knows about embedded documentation. It begins with =head1, =head2 or =pod start of line until EOF or =cut is found. Convert embeded docs with pod2text pl_example > pl_example.1 pod2html pl_example > pl_example.txt pod2man pl_example > pl_example.html =cut my @array; my $scalar; my %hash; ## ## Multi line print: one with ", the other with ' ## print "Hallo $ENV{USER}, nice to meet you. It is " . localtime() . "\n"; print 'Hallo $ENV{USER}, nice to meet you. It is ' . localtime() . "\n"; =pod Here again a peace of docu. =cut ## ## Assign command line arguments ## my $prg = $0; my ($foo, $bar, $baz) = @ARGV; # or $foo = $ARGV[0]; $bar = $ARGV[1]; $baz = $ARGV[2]; my $num_args = @ARGV; ## ## If/then/elsif/fi ## if ( @ARGV == 1 ) { print "one arg given\n"; } elsif ( @ARGV > 2 ) { print "more than two arg\n"; } else { print "Zero or two args given (well, they are ", scalar @ARGV, ")\n " } ## ## Loop over (e.g., list of files, ranges) ## for my $f (`ls -1 /ftp/rosat/archive/100000/*[7-9][24]p`) { print "found $f"; } for my $val ( "ab0" ... "ac5" ) { print "$val "; } print "\n"; for my $val (qw/a c e g/) { print "$val "; } print "\n"; for (my $val = 1; $val < 10; $val++) { print "$val "; } print "\n"; ## ## Function definition ## sub show_function_args { my ($arg1, $arg2) = @_; print "1='$arg1'\n"; print "2='$arg2'\n... or\n"; return "here I am"; } show_function_args("one", "two - zwei"); print "__END__ :)\n"; exit 0;