Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Added programs from the second article.
- Loading branch information
Showing
12 changed files
with
265 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/perl | ||
use strict; | ||
use warnings; | ||
use CGI ':standard'; | ||
|
||
my $file = param('filename'); | ||
|
||
print header(-type => 'text/plain'); | ||
|
||
open my $fh, '<', $file or die "Can't open $file: $!\n"; | ||
|
||
while (<$fh>) { | ||
print; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/perl | ||
use strict; | ||
use warnings; | ||
use CGI ':standard'; | ||
|
||
my $dir = '/path/to/data/files/'; | ||
my $file = $dir . param('filename'); | ||
|
||
print header(-type => 'text/plain'); | ||
|
||
open my $fh, '<', $file or die "Can't open $file: $!\n"; | ||
|
||
while (<$fh>) { | ||
print; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/perl | ||
use strict; | ||
use warnings; | ||
use CGI ':standard'; | ||
|
||
my $user = param('user'); | ||
my $who = `finger $user`; | ||
|
||
print header(-type => 'text/plain'); | ||
|
||
print "Here are the results for user $user\n\n"; | ||
|
||
print $who; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/perl -T | ||
use strict; | ||
use warnings; | ||
use CGI ':standard'; | ||
|
||
$ENV{PATH} = '/bin:/usr/bin:/usr/local/bin'; | ||
|
||
my $user = param('user'); | ||
|
||
if ($user =~ /^(\w+)$/) { | ||
$user = $1; | ||
} else { | ||
die "Invalid user: $user\n"; | ||
} | ||
|
||
my $who = `finger $user`; | ||
|
||
print header(-type => 'text/plain'); | ||
|
||
print "Here are the results for user $user\n\n"; | ||
|
||
print $who; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/perl -T | ||
use strict; | ||
use warnings; | ||
use CGI ':standard'; | ||
|
||
my $dir = '/path/to/data/files/'; | ||
my $file = param('filename'); | ||
|
||
if ($file =~ /^(\w[\w\.]*)$/) { | ||
$file = $1; | ||
} else { | ||
die "Bad filename: $file\n"; | ||
} | ||
|
||
print header(-type => 'text/plain'); | ||
|
||
open my $fh, '<', $file or die "Can't open $file: $!\n"; | ||
|
||
while (<$fh>) { | ||
print; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!usr/bin/perl -T | ||
|
||
use strict; | ||
use warnings; | ||
use CGI ':standard'; | ||
|
||
my $name = param('name'); | ||
my $age = param('age'); | ||
my $gender = param('gender'); | ||
my @hobbies = param('hobby'); | ||
|
||
my $list; | ||
|
||
if (@hobbies) { | ||
$list = join ', ', @hobbies; | ||
} else { | ||
$list = 'None'; | ||
} | ||
|
||
$name =~ s/</</g; | ||
$age =~ s/</</g; | ||
$gender =~ s/</</g; | ||
$list =~ s/</</g; | ||
|
||
print header, | ||
start_html(-title=>$name), | ||
h1("Welcome $name"), | ||
p('Here are your details:'), | ||
table(Tr(td('Name:'), | ||
td($name)), | ||
Tr(td('Age:'), | ||
td($age)), | ||
Tr(td('Gender:'), | ||
td($gender)), | ||
Tr(td('Hobbies:'), | ||
td($list))), | ||
end_html; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/plackup | ||
use strict; | ||
use warnings; | ||
use Plack::Request; | ||
|
||
my $app = sub { | ||
my $req = Plack::Request->new(shift); | ||
my $file = $req->parameters->{filename}; | ||
|
||
open my $fh, '<', $file or die "Can't open $file: $!\n"; | ||
|
||
return [ 200, [ 'Content-type' => 'text/plain' ], | ||
[ <$fh> ] ]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/plackup | ||
use strict; | ||
use warnings; | ||
use Plack::Request; | ||
|
||
my $dir = '/path/to/data/files/'; | ||
|
||
my $app = sub { | ||
my $req = Plack::Request->new(shift); | ||
my $file = $dir . $req->parameters->{filename}; | ||
|
||
open my $fh, '<', $file or die "Can't open $file: $!\n"; | ||
|
||
return [ 200, [ 'Content-type' => 'text/plain' ], | ||
[ <$fh> ] ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/plackup | ||
use strict; | ||
use warnings; | ||
use Plack::Request; | ||
|
||
my $app = sub { | ||
|
||
my $req = Plack::Request->new(shift); | ||
my $user = $req->parameters->{user}; | ||
my $who = `finger $user`; | ||
|
||
return [ 200, [ 'Content-type' => 'text/plain' ], | ||
[ "Here are the results for user $user\n\n", | ||
$who ] ]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/plackup | ||
use strict; | ||
use warnings; | ||
use Plack::Request; | ||
|
||
$ENV{PATH} = '/bin:/usr/bin:/usr/local/bin'; | ||
|
||
my $app = sub { | ||
my $req = Plack::Request->new(shift); | ||
my $user = $req->parameters->{user}; | ||
|
||
if ($user =~ /^(\w+)$/) { | ||
$user = $1; | ||
} else { | ||
die "Invalid user: $user\n"; | ||
} | ||
|
||
my $who = `finger $user`; | ||
|
||
return [ 200, [ 'Content-type' => 'text/plain' ], | ||
[ "Here are the results for user $user\n\n", | ||
$who ] ]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/plackup | ||
use strict; | ||
use warnings; | ||
use Plack::Request; | ||
|
||
my $dir = '/path/to/data/files/'; | ||
|
||
my $app = sub { | ||
my $req = Plack::Request(shift); | ||
my $file = $req->parameters->{filename}; | ||
|
||
if ($file =~ /^(\w[\w\.]*)$/) { | ||
$file = $1; | ||
} else { | ||
die "Bad filename: $file\n"; | ||
} | ||
|
||
open my $fh, '<', $file or die "Can't open $file: $!\n"; | ||
|
||
return [ 200, [ 'Content-type' => 'text/plain' ], | ||
[ <$fh> ] ]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/plackup | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Plack::Request; | ||
use HTML::Tiny; | ||
|
||
my $app = sub { | ||
my $req = Plack::Request->new(shift); | ||
|
||
my $name = $req->parameters->{name}; | ||
my $age = $req->parameters->{age}; | ||
my $gender = $req->parameters->{gender}; | ||
my @hobbies = $req->parameters->get_all('hobby'); | ||
|
||
my $list; | ||
|
||
if (@hobbies) { | ||
$list = join ', ', @hobbies; | ||
} else { | ||
$list = 'None'; | ||
} | ||
|
||
s/</</ for ($name, $age, $gender, $list); | ||
|
||
my $h = HTML::Tiny->new; | ||
my $body = $h->html([ | ||
$h->head($h->title($name)), | ||
$h->body([ | ||
$h->h1("Welcome $name"), | ||
$h->p('Here are your details:'), | ||
$h->table([ | ||
$h->tr([ | ||
$h->td('Name:'), | ||
$h->td($name), | ||
], [ | ||
$h->td('Age:'), | ||
$h->td($age), | ||
], [ | ||
$h->td('Gender:'), | ||
$h->td($gender), | ||
], [ | ||
$h->td('Hobbies:'), | ||
$h->td($list), | ||
]), | ||
]), | ||
]), | ||
]); | ||
|
||
return [ 200, [ 'Content-type' => 'text/html' ], [ $body ] ]; | ||
}; | ||
|