The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/usr/local/bin/perl -I./blib/arch -I./blib/lib -I/usr/local/lib/perl5/next/5.003 -I/usr/local/lib/perl5 -I./test  -I./blib/arch/auto/PDL/Meschach

#!/usr/local/bin/perl
# -I./blib/arch/auto/PDL/Core -I./blib/arch/auto/PDL/Io -I./blib/lib

# Simple shell for PDL 


# unshift @INC, "/etienne/prog/perl/modules/PDL1.02/blib",				
#  "/etienne/prog/perl/modules/PDL1.02/blib/arch/auto/PDL/Core", 					
#	"/etienne/prog/perl/modules/PDL1.02/blib/arch/auto/PDL/Io",
#	"/etienne/prog/perl/modules/PDL1.02/PDL/Meschach",
#	"/etienne/prog/perl/modules/PDL1.02/PDL/Meschach/blib/arch/auto/Meschach",
#	"/etienne/prog/perl/modules/PDL1.02/blib/lib"	
#;  
print <<'EOD';

perlDL shell v1.00 by Karl Glazebrook [kgb@aaoepp.aao.gov.au] 1 Oct 1996

EOD

$PERLDL_ESCAPE = '#'; # Default shell escape

$Modules = "";

if ($ARGV[0] eq "-oo") {
   shift @ARGV; $OO++;
   print "Starting Object-Oriented perlDL\n";
}

if ($OO) {
   eval "use PDL::OO"; 
}else{
   eval "use PDL";
}
  
if ($@ eq "") {
   $PDL_OK = 1;
   print "Loaded PDL v$PDL::VERSION   \n";
}else{
   $PDL_OK = 0;
	 print "$@\n";
   warn "WARNING: PDL module not found only plain perl available\n";
}


eval "use PDL::Meschach qw( :All )";
if($@ ne ""){
	print "Meschach NOT AVAILABLE : \n$@\n";
} else { print "Meschach found\n";}


eval "use Term::ReadLine"; 
$readlines = ($@ eq "");
print "ReadLines enabled" if $readlines;

print "\n";

$prompt = "perldl> ";

$term = new Term::ReadLine 'perlDL', \*STDIN, \*STDOUT if $readlines;

$,=" "; # Default

$PDL::verbose = 1; # Make PDL functions waffle

# Global and local startup

for ($ENV{'HOME'}."/.perldlrc", 'local.perldlrc') {
    next unless -e $_;
    print "Reading $_ ...\n";
    require $_ ;
}


if ( ( -e '.perldl_hist' ) && ( open HIST, "<.perldl_hist" ) ) {
	$sep = $,; $,="\n"; 
	my @allhist = <HIST>;
	close HIST;
	$, = $sep;
	map s/\n//g , @allhist ;
	$term->addhistory(@allhist);
}


$SIG{'INT'} = sub {print "Ctrl-C detected\n"; goto restart}; # Ctrl-C handler
  
$|=1;
while(1) {

restart:

     $sep = $,; $,=""; # Save

     if ($readlines) {
         $_ = $term->readline($prompt);
     }else{
         print $prompt; $_ = <>;
     }
     $,=$sep; #Restore 

     next if /^\s*$/; # Blank line - do nothing

     if (substr($_,0,1) eq substr($PERLDL_ESCAPE,0,1)) { 
        system(substr($_,1)); # Shell escape
        next;
     }else{
        if ($PDL_OK) {
            $code = eval <<"EOD";  # Create code ref
sub {
   $_;
}
EOD
       PDL::Core::myeval( $code ); # Do command with $@ keeping
			  }else{
					eval $_;
        }
			}
     if ($@) {
         $mess = $@; 

         # Remove surplus parts

#         $mess =~ s/^\s*\(in cleanup\)\s+//;   # 'cleanup ...' from Usage:...
#         $mess =~ s/\n\s*\(in cleanup\).*$//;  # 'cleanup...'s at end
#         $mess =~ s/\s+at \(eval \d+\) line \d+\.?$//; # at eval ?? line ??.

         warn $mess;  # Report error
     }else{
         print "\n";
     }
}


# Short hand for print
sub p {
    print(@_);
}

sub q { exit(); }
# sub x { exit(); }


sub END {


																# Save History in .perldl_hist
	my @a= $term->GetHistory();
	@a= @a[($#a-50)..($#a-1)];
	if( open HIST, ">.perldl_hist" ) { 
		print HIST join("\n",@a);
		close HIST;
	} else {
		print " Unable to open \".perldl_hist\"\n";
	}

}