File: Screen.pm

package info (click to toggle)
pdl 2.005-4
  • links: PTS
  • area: main
  • in suites: potato
  • size: 4,200 kB
  • ctags: 3,301
  • sloc: perl: 14,876; ansic: 7,223; fortran: 3,417; makefile: 54; sh: 16
file content (60 lines) | stat: -rw-r--r-- 1,236 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Perform pdl demos on terminals

package PDL::Demos::Routines;

# Copyright (C) 1998 Tuomas J. Lukka.
# All rights reserved, except redistribution
# with PDL under the PDL License permitted.

use Carp;
use PDL;

@ISA="Exporter";
@EXPORT = qw/comment act actnw output/;

$SIG{__DIE__} = sub {die Carp::longmess(@_);};

sub home() {
	if(-e '/usr/bin/tput') {
		system 'tput clear';
	}
}

sub comment($) {
	home();
	print "----\n";
	print $_[0];
	print "---- (press enter)";
	<>
}

sub act($) {
	home();
	my $script = $_[0];
	$script =~ s/^(\s*)output/$1print/mg;
	print "---- Code:";
	print $script;
	print "---- Output:\n";
	my $pack = (caller)[0];
#	eval "package $pack; use PDL; $_[0]";
	eval "package $pack; use PDL; $_[0]";
	print "---- (press enter)";
	print "----\nOOPS!!! Something went wrong, please make a bug report!: $@\n----\n" if $@;
	<>
}

sub actnw($) {
	home();
	my $script = $_[0];
	$script =~ s/^(\s*)output/$1print/mg;
	print "---- Code:";
	print $script;
	print "---- Output:\n";
	my $pack = (caller)[0];
#	eval "package $pack; use PDL; $_[0]";
	eval "package $pack; use PDL; $_[0]";
	print "----\n";
	print "----\nOOPS!!! Something went wrong, please make a bug report!: $@\n----\n" if $@;
}

sub output {print @_}