TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [TCLUG:2586] perl question



I'm pretty unclear on the syntax for sub routines (and perl in general).
What I'm trying to do is have the perl script run (with the foreach)
 
$new .= '"';
$new .= $test;
$new .= '" ' }; 

if this $test doesn't start with a - (not A) or if it starts with a - (A)
but isn't after taking out the R's equal to "-" (not B). I only take out
the r's if $test starts with a "-". 

I'm getting:

syntax error at bin/test line 10, near ") ||"
syntax error at bin/test line 22, near "`mv $new $DELETEDIR`}"   

when I run the scipt.

> Something like this
> 
> if (!A || (A && (&B()))) {    # that last ampersand means 'call
> subroutine'
> 	C
> }
> 
> sub B {
> 	stuff;
> 	more stuff;
> 	return (whatever == good);
> }
> --

Ben Luey
lueyb@carleton.edu
ICQ: 19144397

We live in the Computer Age, and you need to get with the program.  You 
are standing in the airport terminal of life, and the jet plane of the 21st 
century isabout to take off.  You must make a choice: Do you remain in the 
terminal, eating the stale vending-machine food of outmoded thinking?  Or do 
you get on the plane and soar into the stratosphere of computerization, swept
along by the jet stream of evolving technology, enjoying the in-flight snack 
of virtually unlimited information access, secure in the knowledge that if you
encounter the turbulence of rapid change, you are holding, in this book, the 
barf bag of expert guidance?  -- Dave Barry

#!/usr/bin/perl
@pwinfo = getpwuid($<);
$DELETEDIR = "$pwinfo[7]/.Trash";
if (@ARGV[0] eq  "") {
print "Syntax:\ndel [files and directories to delete]\n"}
else {
foreach $test (@ARGV) {
        if ($test eq  "--recursive") {}
	else {
	if ($test !=~ "^-.*") || ($test =~ "^-.*" && (&B($test) !eq "-" )) {
	$new .= '"';
	$new .= $test;
	$new .= '" ' };
	};
	
	sub B { 
	$_ =~ s/[rR]//g};
	
        };
if (!-e "$DELETEDIR") {
`mkdir $DELETEDIR`};
`mv $new $DELETEDIR`}