#!/usr/local/bin/perl ## ## printenvx -- demo CGI program which just prints its environment ## uses CGI.pm. See also printenv for a basic version use strict; use warnings; use CGI; my $cgi = CGI->new; print $cgi->header; print $cgi->start_html('The Environment'); # CGI.pm uses Tr for table row to stop perl getting confused # with tr///. print $cgi->table( $cgi->caption('The Environment'), $cgi->thead( $cgi->Tr( $cgi->th(['Name', 'Value']) ) ), $cgi->tbody( $cgi->Tr( environment_table($cgi)) ) ); print $cgi->p($cgi->a( {-href => '/lt431/printenvx.txt'}, 'Source Code')); print $cgi->end_html; sub environment_table { my $cgi = shift; my @rows = (); for my $var (sort keys %ENV) { my $val = $ENV{$var}; $val =~ s|\n|\\n|g; $val =~ s|"|"|g; push @rows, $cgi->td([$var, $val]); } return [@rows]; }