[12391] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 5991 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 14 15:07:26 1999

Date: Mon, 14 Jun 99 12:00:28 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 14 Jun 1999     Volume: 8 Number: 5991

Today's topics:
    Re: @INC bizarreness <uri@sysarch.com>
    Re: a thread on threads <gbartels@xli.com>
    Re: can i variably name an array? <uri@sysarch.com>
    Re: Case select statements: are they in Perl? (Hasanuddin Tamir)
    Re: Case select statements: are they in Perl? <tchrist@mox.perl.com>
    Re: Dynamic Regular Expression (Hasanuddin Tamir)
    Re: Fix this uglyness (Hasanuddin Tamir)
    Re: Form Redirection (Ethan H. Poole)
    Re: holding shell output in perl (Steve .)
    Re: my() in a loop (Lee)
    Re: Perl "constructors" <jdporter@min.net>
        Perl tuning/speed question: all subsets of a set of len <Armin.Roehrl@epfl.ch>
        Python to perl convertor zephaar@my-deja.com
        Redirection but no 'Back' <mike@5starserv.com>
    Re: simple math question!  Why doesn't the * multiply t (Hasanuddin Tamir)
        taint checking setuid error message <john@nonet.com>
    Re: using perl scripts in VC++'s post-build step <dominikos@my-deja.com>
    Re: which .tar.gz file contains Net::Cmd.pm? (Brian Pontz)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 14 Jun 1999 14:29:01 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: @INC bizarreness
Message-Id: <x7so7uhc0i.fsf@home.sysarch.com>

>>>>> "j" == jwwilhit  <jwwilhit@srp.gov> writes:

  j> Why is it if I run /usr/sbin/perl from the command line and type the
  j> following command:

why is perl in sbin? that is usually for statically linked programs that
are needed to run when booting in a diagnostic mode?

  j> 	/usr/freeware/lib/perl5/5.00502/irix-n32
  j> 	/usr/freeware/lib/perl5/5.00502
  j> 	/usr/freeware/lib/perl5/site_perl/5.005/irix-n32
  j> 	/usr/freeware/lib/perl5/site_perl/5.005
  j> 	/usr/freeware/lib/perl5/sgi_perl/irix-n32
  j> 	/usr/freeware/lib/perl5/site_perl .

  j> 	Can't locate GD.pm in @INC (@INC contains:
  j> 	/usr/share/lib/perl5/irix-n32/5.00404
  j> 	/usr/share/lib/perl5
  j> 	/usr/share/lib/perl5/site_perl/irix-n32
  j> 	/usr/share/lib/perl5/site_perl
  j> 	/usr/share/lib/perl5/sgi_perl .) at ./usgsGrph.cgi line 11.
  j> 	BEGIN failed--compilation aborted at ./usgsGrph.cgi line 11.

  j> Maybe I'm just an idiot (and that is entirely possible!) but it looks to
  j> me like there is a discrepancy between the two @INC statements.  I've
  j> tried recompiling all of my add-on modules and reinstalling them, I've
  j> reinstalled perl...No luck.

you obviously have 2 different installed perl's there. carefully check
for perl on your path and the one used in the shebang line. 

run a plain perl -V and /usr/sbin/perl -V (and any other paths to perl)
and look at the results.

  j> Also...this script runs perfectly on a different machine that seems to
  j> be configured similarly to the machine I'm having problems on.

it must be different. it probably only have one perl installed.

uri


-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


------------------------------

Date: Mon, 14 Jun 1999 13:33:34 -0400
From: Greg Bartels <gbartels@xli.com>
Subject: Re: a thread on threads
Message-Id: <37653CEE.CA947B6@xli.com>

wow, talk about hitting a goldmine of information.

Tom Christiansen wrote:
> 
>      [courtesy cc of this posting mailed to cited author]
> 
> In comp.lang.perl.misc, Greg Bartels <gbartels@xli.com> writes:
> :Can anyone give me the lowdown on threading in perl?
> 
> :I'm working on a problem that seems might
> :be well easily solved by threads, if I
> :understand what threads will be able to do.
> 
> 

> The typical use of the word "thread" now has varied greatly from its
> original use, which was essentially synonymous with a fork()d process.
> (And these new light-weight processes aren't always particularly light in
> weight, either.)  I assume you are using "thread" in the vernacular,
> which most often seem to mean to create a new context where everything
> is shared just as in a fork, except this time, all data space will also
> be jointly accessible.

yes, completely shared data, only separate execution control.
 
> In short, with fork(), data space is protected unless you say otherwise
> (such as with IPC::Shareable) whereas with Thread::->new, it's an
> uncontrolled free-for-all.  I can certainly see why you might wish to
> have several active PCs running concurrently, but I am dubious that you
> have an application for which uncontrolled, unmediated sharing amongst
> these threads would be a natural solution not easily accomplishable
> using the protected threads you get when you fork.

the problem is at: 
http://www.cpan.org/modules/by-authors/id/G/GB/GBARTELS/
called: Hardware-Simulator*

the module simulates parallel hardware components in perl.
it does so by describing each component as a subroutine.
all the neccessary subroutines are scheduled to be executed 
at a given "simulation time". 

the module has a limitation: in hardware description languages,
you might have a subroutine that waits for a period of time
before continuing execution. my module cant do that because 
it schedules and executes every subroutine based off the 
assumption that they execute in zero simulation time (not 
processor time).

when the module is executing a subroutine and encounters a 
call to a "Delay(n)" call, it needs to stop executing the 
current subroutine, schedule the routine to restart at 'n'
seconds in the future, and then execute any remaining 
subroutines scheduled to be executed now.

the only way I can think of doing this is that every subroutine 
is executed in a separate thread. when a Delay(n) is encountered, 
that thread stops, and schedules itself to continue at a later 
time. All data is shared between threads, since in this 
application, they are, by design, guaranteed not to step on one 
another.

all I need, basically, is a means to stop and start execution of
a subroutine call. and this will be handled by the scheduler
whenever a Delay(n) is called. Delay(n) will cause its own thread 
to stop, and schedule the thread to restart at some point in the 
future, restarting whereever it left off.

if I solve this, I have every neccessary capability to perform
full fledged hardware simulation in Perl.  

Greg


------------------------------

Date: 14 Jun 1999 14:14:10 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: can i variably name an array?
Message-Id: <x7wvx6hcp9.fsf@home.sysarch.com>

>>>>> "FN" == Faisal Nasim <swiftkid@bigfoot.com> writes:

  FN> $array = "cool scalar";
  FN> @array = qw/my hot array/;

  FN> print $array;
  FN> print "\n";
  FN> print $array[0];

  FN> (In short, you can use same named scalar and array)

in short, what does this have to do with the original question?

  >> is it possible to give an array an interpolated name?
  >> 
  >> $array_name = "mikes_array";
  >> 
  >> now i want to use the scalar $array_name to create an array
  >> @mikes_array.

that is using symbolic references which is technically doable but
extremely frowned upon. in almost all cases, a true perl data structure
will do the job better.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


------------------------------

Date: 15 Jun 1999 07:40:18 GMT
From: hasant@trabas.co.id (Hasanuddin Tamir)
Subject: Re: Case select statements: are they in Perl?
Message-Id: <slrn7mae8d.5r1.hasant@borg.intern.trabas.co.id>

On Mon, 14 Jun 1999 06:27:01 GMT, R.Joseph <streaking_pyro@my-deja.com> wrote:
> In VB you have CASE, in C/C++ you have Switch(), in Perl you have ____
> (please fill in the blank).  Is there a case select statement in Perl,
> or am I looking forward to a wrechted life of writing "if" and "elsif"
> alot?  Any help is greatly apprecitaed!

Perl has CASE, SWITCH, MYCASE, YOURSWITCH, you name it.

manpage: perlsyn
section: Basic BLOCKs and Switch Statements

HTH,

-- 
-hasan-
uhm, no more sig(h)


------------------------------

Date: 14 Jun 1999 12:23:54 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Case select statements: are they in Perl?
Message-Id: <376548ba@cs.colorado.edu>

     [courtesy cc of this posting mailed to cited author]

In comp.lang.perl.misc, 
    R.Joseph <streaking_pyro@my-deja.com> writes:
:In VB you have CASE, in C/C++ you have Switch(), in Perl you have ____
:(please fill in the blank).  Is there a case select statement in Perl,
:or am I looking forward to a wrechted life of writing "if" and "elsif"
:alot?  Any help is greatly apprecitaed!

From: Tom Christiansen <tchrist@mox.perl.com>
Newsgroups: comp.lang.perl.misc
Subject: FMTEYEWTK on Switch Statements in Perl (was: No switch statement in Perl??)
References: <6sfb0m$m8e$1@nnrp1.dejanews.com>
Organization: Perl Consulting and Training

In comp.lang.perl.misc, spiegler@cs.uri.edu writes:
:I cannot find a switch statement in Perl. Is there one? 

man perlsyn or perlfaq7, or look at

http://www.perl.com/CPAN/doc/manual/html/pod/perlsyn.html#Basic_BLOCKs_and_Switch_Statemen
http://www.perl.com/CPAN/doc/manual/html/pod/perlfaq7.html#How_do_I_create_a_switch_or_case

:If not, do you know
:why it was not put into the language?

Because it seems unnecessary as is, and because no decision on something
more powerful has even been decided with.

:Also, does Perl provide any mechanism other than if-elsif-else to deal with
:this?

Many, but all can be placed into one of two classes, either multiple
sequential tests (`linear switches') or else a single that does a multiway
branch (`non-linear switches').  The first sort are all variations on
the same theme.  You can affect performance minusculely by putting the
more likely cases first.  You make a slight semantic distinction between
simple if()s and if/elsif()s chains.  And you can make appearance choices
related to how to the tests are represented syntactically.

The short answer is that the switch statement in Perl is spelled for().
Here's a simple demo:

CASE 1:

    for ($where) {
	/In Card Names/     && do { push @flags, '-e'; last; };
	/Anywhere/          && do { push @flags, '-h'; last; };
	/In Rulings/        && do {                    last; };
	die "unknown value for form variable where: `$where'";
    }

But there is no performance gain to be had over here over a more
traditional arrangement.  If you don't like that style, you can use this:

CASE 2:

    SWITCH: for ($where) {
	if (/In Card Names/) { 
	    push @flags, '-e'; 
	    last SWITCH; 
	}
	if (/Anywhere/) { 
	    push @flags, '-h'; 
	    last SWITCH; 
	}
	if (/In Rulings/) { 
	    last SWITCH; 
	}
	die "unknown value for form variable where: `$where'";
    }

or you can use this:

CASE 3:

    SWITCH: for ($where) {
	if (/In Card Names/) { 
	    push @flags, '-e'; 
	}
	elsif (/Anywhere/) { 
	    push @flags, '-h'; 
	}
	elsif (/In Rulings/) { 
	    ;   # nothing needed
	}
	else {
	    die "unknown value for form variable where: `$where'";
	}
    }


Or more concisely as this:

CASE 4:

    SWITCH: for ($where) {
		if    (/In Card Names/) { push @flags, '-e'; }
		elsif (/Anywhere/)      { push @flags, '-h'; }
		elsif (/In Rulings/)    {                    } # do nothing
		else                    { die "unknown whence: `$where'" }
	    }

There's really nothing to terrible with this, and no completely
convincing reason not to just write the elsif()s:

CASE 5:

    chomp($answer = <>);
    if    ("SEND"  =~ /^\Q$answer/i) { print "Action is send\n"  }
    elsif ("STOP"  =~ /^\Q$answer/i) { print "Action is stop\n"  }
    elsif ("ABORT" =~ /^\Q$answer/i) { print "Action is abort\n" }
    elsif ("LIST"  =~ /^\Q$answer/i) { print "Action is list\n"  }
    elsif ("EDIT"  =~ /^\Q$answer/i) { print "Action is edit\n"  }

Or as:

CASE 6:

    if    ($visibility == SCREEN_DISPLAY) {
		# do something
    } 
    elsif ($visibility == SCREEN_HIDDEN) {
		# do something
    } 
    elsif ($visibility == SCREEN_CODEGEN) {
		# do something
    } 
    else { 
		# do something drastic
    } 

Many similar, sequential-testing mechanisms are seen in Perl.
You can use "&& ||" combos, but then you have to be very
careful that the RHS of && is always a true value.

CASE 7:

   $dir = 'http://www.wins.uva.nl/~mes/jargon';
   for ($ENV{HTTP_USER_AGENT}) {
       $page  =    /Mac/            && 'm/Macintrash.html'
                || /Win(dows )?NT/  && 'e/evilandrude.html'
                || /Win|MSIE|WebTV/ && 'm/MicroslothWindows.html'
                || /Linux/          && 'l/Linux.html'
                || /HP-UX/          && 'h/HP-SUX.html'
                || /SunOS/          && 's/ScumOS.html'
                ||                     'a/AppendixB.html';
   }

This is actually better written with a bunch of ?: constructs instead
in most cases because the RHS of the && might false out on you
in the more general case:

CASE 8:

    $which_search = $opts{"t"} ?  'title'
		  : $opts{"s"} ?  'subject'
		  : $opts{"a"} ?  'author'
		  :               'title';

Or if you are assigning a list, you could do this:

CASE 9:

    ($msg, $defstyle) = do {
	$i == 1 ? ("First", "Color" )  :
	$i == 2 ? ("Then",  "Rarity")  :
		  ("Then",  "Name"  )
    };

Or even this, making more use of the do{}'s blockness:

CASE 10:

    ($FORMAT_NAME, $FORMAT_TOP_NAME) = do {
        if    ($long_form)      { qw( Long      Long_Top   ) }
        elsif ($just_inode)     { qw( Inodes    Inodes_Top ) }
        elsif ($sys5)           { qw( SysV      SysV_Top   ) }
        elsif ($bsd)            { qw( BSD       BSD_Top    ) }
        else                    { die " No format?"          } 
    };


Sometimes one has been known to use the do { } superfluously just to
make things look pretty.  Sometimes, aesthetics counts: The do there is
just so the Christmas tree has a star. :-)

CASE 11:

    for ($^O) {
        *struct_flock =                do                           {

                                /bsd/  &&  \&bsd_flock
                                       ||
                            /linux/    &&    \&linux_flock
                                       ||
                          /sunos/      &&      \&sunos_flock
                                       ||
                  die "unknown operating system $^O, bailing out";
        };
    }

Actually, this is an important point, easily overlooked.  Aesthetics
really does count -- a lot.  In virtually all these switch examples,
careful alignment of parallel constructs serves to clarify just
how the structure works.  Good programmers put in extra effort
to make their code easy to read.

Here's another do{} style switch, turned another way:

CASE 12:

   $amode = do {
       if     ($flag & O_RDONLY) { "r" }       # XXX: isn't this 0?
       elsif  ($flag & O_WRONLY) { ($flag & O_APPEND) ? "a" : "w" }
       elsif  ($flag & O_RDWR)   {
           if ($flag & O_CREAT)  { "w+" }
           else                  { ($flag & O_APPEND) ? "a+" : "r+" }
       }
   };

Here's an old example for argument processing:

CASE 13:

    while ($ARGV[0] =~ /^-(.+)/ && (shift, ($_ = $1), 1)) {
	next if /^$/;

	s/a// 	    && (++$autoload,    redo);
	s/p// 	    && (++$postcompile, redo);
	s/f// 	    && do {
			    $FILE = $_ || shift;
			    open(FILE) || die "can't open $FILE: $!";
			    while (<FILE>) {
				push(@required, split(' '));
			    }
			    redo;
		    };

	die "usage $0 [-pa] [-f module_list] [module] ...\n";
    }


And here's another, simpler one:

CASE 14:

    while ($ARGV[0] =~ /^-/) {      
	$ARGV[0] =~ /^-a/ && ($all++,shift,next);
	$ARGV[0] =~ /^-d/ && ($debug++,shift,next);
	$ARGV[0] =~ /^-n/ && ($idle = 0,shift,next);
	$ARGV[0] =~ /^-s/ && ($slumber++,shift,next);
	$ARGV[0] =~ /^-i/ && (shift,$idle=$ARGV[0],shift,next);
	last;
    }

And here's one more.  I used to do this a lot. :-)

CASE 15:

    OPT: while ($ARGV[0] =~ /^-(.*)/ && (shift, $_ = $1, 1)) {

	/^$/        && next OPT;

	/^\d+/      && do {
			$DEPTH = $_;
			next OPT;  
		    };

	s/q//       && do {
			$QUIET = 1;
			redo OPT;
		    }; 

	/d/         && do {
			$debug += s/d//g;
			redo OPT;
		    }; 

	&usage("Unknown option: -$_");
    } 


As you see in the last case, the test doesn't always have to be the
same kind.  There are definite advantages to this approach.  For example:

CASE 16:

    for ( $big->long->hairy->expression ) {
	/pat/i		&& do { ...... };
	$_ >  10	&& do { ...... };
	$_ == 13        && do { ...... };
	uc eq "FRED"    && do { ...... };
	$now > 2*$_     && do { ...... };
	# do default
    } 

In that case, we aren't in each case making the same sort of test (string,
numeric, pattern, etc).  Instead, we pick and choose as we go.  

But all the preceding versions share one critical trait: they all
perform a series of tests sequentially.  That's why we called them
`linear switches' above.  That means that they don't scale well to a
large number of cases.  Of course, this really never matters all that
much, since in the number of different cases we're talking about here
is virtually always too small to fret over.

But any good programmer, when confronted with extremely similar code,
has a nearly irrepressible urge to unify.  As Kernighan has said, one
should capture regularity with data, irregularity with code.  That 
means that seeing repeated instances of a nearly identical thing, 
like this:

    if ($who eq "Fred")   { ... }
    if ($who eq "Barney") { ... }
    if ($who eq "Wilma")  { ... }

makes any programmer worth his salt say, ``That's too much similarity
in code.  It should be in data!''  And indeed, it probably should be,
and like most interesting data structures in Perl, this should likely
be based on a hash.  (C and assembly programmers might think of this
as a jump table.) 

Here's what you could do instead:

CASE 17:

    %action = (
	"Fred"   =>  \&greet, 
	"Barney" =>  \&shuffle,
	"Wilma"  =>  \&chat,
	# add as you will
    );

    if ($verb = $action{$who}) {
	&$verb();
    } else {
	die "unknown character: $who";
    } 

Those of you corrupted into the infinite hunt for a one-liner
to everything might prefer this approach:

CASE 18:

    {
	"Fred"   =>  \&greet, 
	"Barney" =>  \&shuffle,
	"Wilma"  =>  \&chat,
    }->{$who}->();

Except that now you haven't managed to catch the null case.

CASE 19:

    ( {
	"Fred"   =>  \&greet, 
	"Barney" =>  \&shuffle,
	"Wilma"  =>  \&chat,
    }->{$who} || sub { die: "who's $who?" })->();

But that's getting a bit silly.  Better there to
do it in several steps.

These functions can even be defined right there as closures:

CASE 20:

    %actions = (
        "edit"  => \&invoke_editor,
        "send"  => \&deliver_message,
        "list"  => sub { system($PAGER, $file) },
        "abort" => sub {
                        print "See ya!\n";
                        exit;
                   },
        ""      => sub {
                        print "Unknown command: $cmd\n";
                        $errors++;
                   },
    );

    $href = abbrev(keys %actions);

    local $_;
    for (print "Action: "; <>; print "Action: ") {
        s/^\s+//;       # trim leading  white space
        s/\s+$//;       # trim trailing white space
        next unless $_;
        $actions->{ $href->{ lc($_) } }->();
    }

Imagine where you had a switch with 100 cases in a tight loop.  You'd
definitely want to hash up the cases for instant access rather than
making all the tests each time.  In fact, this would scale to any number
of cases (assuming that the hash keys weren't permutations of each other,
which pessimizes perl's hashing).

Here's an example of a non-linear switch with an in-line hash:

CASE 21:

    my $newop = {
	'==' 	=> 	'eq',
	'!=' 	=> 	'ne',
	'>=' 	=> 	'ge',
	'>'  	=> 	'gt',
	'<=' 	=> 	'le',
	'<'  	=> 	'lt',
	'=~' 	=> 	'=~',
	'!~' 	=> 	'!~',
    }->{$operator} || "MISSING OPERATOR";

It would be marginally better to assign that to a named hash once, as we
did in the previous case.  Those of you who have coded up finite state
machines may be familiar with one final approach:

CASE 22:

    while ($state = $action_table{$state}->()) {
	print "Moving on to state $state\n";
    } 

Here, each function state in the action table returns the next state to
transition to.  The table would hold as values the function to call at
each state, and those functions would return a string which is the next
state to go to.

So, anybody read this far? :-)

--tom
-- 
At MIT the server is the unit of invention.  --Rob Pike


------------------------------

Date: 15 Jun 1999 07:40:12 GMT
From: hasant@trabas.co.id (Hasanuddin Tamir)
Subject: Re: Dynamic Regular Expression
Message-Id: <slrn7madss.5r1.hasant@borg.intern.trabas.co.id>

On Sun, 13 Jun 1999 22:45:31 -0400,
Pamela Goldfarb <pamelag@interlog.com> wrote:
> A user will supply a search criteria:
> 
> word1 word2             - match if both word1 and word2 present
> word1 and word2     - same
> word1 or word2        - match if either present
> 
> I want to create a perl script that can parse the input string and then
> search a file based on the search
> criteria.
> 
> I know that I can build a string
> 
> $w="a|b";
> 
> and /$w/i will match $_ if it contains either a or b,

/i will match A, a, B, or b.

> but is there a way to do the same thing for "a" and "b"?
> 
> $w="a&b";
> 
> doesn't work.

   $w = "ab";
->
   $w = '\\bword1 word2\\b'; #\b is a word boundary

   perldoc perlre
   perldoc perlop


HTH,

-- 
-hasan-
uhm, no more sig(h)


------------------------------

Date: 15 Jun 1999 07:39:45 GMT
From: hasant@trabas.co.id (Hasanuddin Tamir)
Subject: Re: Fix this uglyness
Message-Id: <slrn7macd4.5r1.hasant@borg.intern.trabas.co.id>

On 13 Jun 1999 23:46:33 GMT, Alan <alanp@unixpower.org> wrote:
> I haven't the time to do it myself, so could someone please fix the systeming
> I used when I got tired:
> 
> system("cat /var/log/wtmp | uuencode wtmp.`date +%m-%d` | mail $WTMPBACK");
> system("mkdir /var/wtmp 2> /dev/null");
> system("mv /var/log/wtmp /var/wtmp/wtmp.`date +%m-%d`");
> system("touch /var/log/wtmp");
> 
> I just need a good way of doing that.

I know of one good way: check the return value/exit status.

HTH,

-- 
-hasan-
uhm, no more sig(h)


------------------------------

Date: Mon, 14 Jun 1999 13:57:51 -0400
From: ehpoole@ingress.com (Ethan H. Poole)
Subject: Re: Form Redirection
Message-Id: <tHker9ot#GA.194@rejz.ij.net>

[Posted and Emailed]  In article <37651A1C.B7701D62@gaylordusa.com>, 
davidf@gaylordusa.com says...
>
>Thanks, I like that javascript better than the form and it works with
>both browsers.  I added a </FORM> (whoops) but that didn't make a
>difference with IE.  It still didn't work.  Javascript works though and
>it's a little smoother.  Thanks for help.

JavaScript is a rather poor solution if you are looking for a solution that 
works with all browsers.  Many browsers do not support JavaScript.  Many 
browsers that do support JavaScript have JavaScript disabled because there 
are many poor JavaScript programmers out there who ruin an otherwise workable 
site if JavaScript is left enabled, and occassionally JavaScript itself still 
has some internal bugs that will crash a browser.

-- 
Ethan H. Poole              | Website Design and Hosting,
                            | CGI Programming (Perl & C)..
========Personal=========== | ============================
* ehpoole @ ingress . com * | --Interact2Day, Inc.--
                            | http://www.interact2day.com/



------------------------------

Date: Mon, 14 Jun 1999 18:19:51 GMT
From: syarbrou@nospam.enteract.com (Steve .)
Subject: Re: holding shell output in perl
Message-Id: <376647ae.14679019@news.enteract.com>

Thanks.  I've tried IPC::Open2 since I couldn't find anything in the
man pages that gave examples of Open3.  Doesn't seem to work though.
If I do a:

 ./mirror.sh /dir

it works fine.

If I do a:

 ./mirror.pl

it just returns and does nothing.  Code below.  If I replace
webmirror.sh /dir with something else like ls -l it seems to work
fine.  Any ideas what I'm missing?  Thanks.

--- code --- 

#!/usr/bin/perl

use FileHandle;
use IPC::Open2;

$pid = open2( \*Reader, \*Writer, "webmirror.sh /dir" );
Writer->autoflush(); 
print Writer "stuff\n";
$got = <Reader>;

--- end code ---


Steve

newsgroup responses preferred.  Remove nospam from email address if
responding thru email.

On 11 Jun 1999 14:37:53 +0100, Jonathan Stowe
<gellyfish@gellyfish.com> wrote:

>Steve . <syarbrou@nospam.enteract.com> wrote:
>> On 10 Jun 1999 22:22:17 -0000, Jonathan Stowe
>> <gellyfish@gellyfish.com> wrote:
>> 
>>>On Thu, 10 Jun 1999 18:49:18 GMT Steve . wrote:
>>>> I have a perl script that calls rdist to do a system copy.  RDIST
>>>> outputs things as it goes along to the screen.  I want that output to
>>>> be caught by the perl script before it hits the screen and modified
>>>> per my instructions.  How do you catch the output being displayed by a
>>>> system call?  Thanks.
>>>> 
>>>
>>>You should look for:
>>>
>>>  `STRING`
>>>
>>>or
>>>
>>>  qx/STRING/
>>>
>>>in the perlop manpage.
>>>
>
>> Thanks.  That sounds like a good possible solution.  However that
>> would require the user to wait till it was finished before showing the
>> output.  I was hoping, if possible, to modify and output the data the
>> system call is making as it happens.
>> 
>
>Then you probably want too look at using open() to read the output
>one line at a time:
>
>  perldoc -f open
>
>You will almost certainly want to check out the perlipc manpage as well.
>
>/J\



------------------------------

Date: Mon, 14 Jun 1999 13:12:47 -0500
From: rlb@intrinsix.ca (Lee)
Subject: Re: my() in a loop
Message-Id: <B38AB04F966897F6E@204.112.166.88>

In article <7k39m0$es$1@news1.bu.edu>,
John Siracusa <macintsh@cs.bu.edu> wrote:

>Consider these two code snippets:
>
>Example 1:
>
>    my($jedi, $color, $blades);
>
>    foreach $jedi (@jedi)
>    {
>      ($color, $blades) = get_stats($jedi);
>    }
>
>Example 2:
>
>    foreach my $jedi (@jedi)
>    {
>      my($color, $blades) = get_stats($jedi);
>    }
>
>For some reason, I have no qualms about doing "foreach my $var (...)",
>but balk at putting a my() inside the loop (as in example 2), preferring
>to declare those vars above the loop somewhere.  Benchmarking seems to
>reveal that predeclaring all the my() vars before going through the loop
>(as in the first example) is the fastest method, but the second example
>seems more "popular" in ther Perl community.
>
>So, where do you put your my()'s, and why?

I always do as in Example 1, because I'm too durn lazy to find out what the
repercussions of style-2 declarations may or may not be.

Lee




------------------------------

Date: Mon, 14 Jun 1999 17:13:17 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Perl "constructors"
Message-Id: <7k3d72$u1n$1@nnrp1.deja.com>

In article <7k29mh$hmv$1@nnrp1.deja.com>,
  armchair@my-deja.com wrote:
> No amount of blather about object code, real machines, and virtual
> machines can change the fact that we are talking about and
> comparing source code.

As I observed before, we are, it is quite apparent, talking about
two (or more) different things.  I was talking about language
design and implementation.  You are talking about irrelevant things.


> The equivalence of the if/while/for logic of C and C++ was mentioned
to
> show a common feature with that of Perl, and to aptly demonstrate that
> any comparison of C to assembler is absurd.

Even granting (which I am not) that Perl's if/while/for logic is
identical to C's, that says nothing about C's equivalence to asm.
Every line of C code you write has an equivalent corresponding
construction in asm.  C's intrinsic data types are all machine
data types.  Pointers in C are simply machine addresses.  Perl
doesn't know from machine data, opcodes, addresses, or anything
else about the machine.


> > Syntactic difference/equivalence is quite irrelevant.
>
> Only to fellows who repeatedly try and argue that assembler is
> equivalent to C.

Or rather, it's only relevant to fellows who lack the background
and/or cognitive abilities to recognize the equivalence of the two.


> And we are talking about syntactic equivalence/equality.

Well, some of us are.


> Allow me to give you credit for something.

What you do with your worthless credit is your own business.


> > Nope, I'm not out to show that "using C is equivalent to using asm".
> > I'm talking about the design of the languages themselves, primarily
> > the semantics.  Too much of the usability of a language is dependent
> > on other things, like the availability and quality of development
> > tools.
>
> Ah, finally an admission that C is not equivalent to assembler.

Not the admission you were hoping for.
Interesting (well, not really) that you first demand that C and asm
be syntactically similar for them to be "equivalent", and now you'll
accept that having unequal tool support is sufficient for them
to be "not equivalent".


> > I feel confident that you will not be convinced of the equivalence
of
> > the code, regardless of who or what does the translation.
>
> Since we are talking about source code, looking at anything else would
> be irrelevant. But you knew that.

If indeed we were talking about source code.
But we (at least some of us) are talking about language design,
semantics, and implementation.


> > > Show me how this C code is not
> > > more powerful than the equivalent assembler code by showing me the
> > > equivalent assembler code...
> >
> > Ridiculous.
>
> Certainly was...

Yes indeed.  It's ridiculous to suppose that some code in C is
more powerful, by any definition, than its asm equivalent.


> Before someone could right a C++ string class that "behaved like a
Perl
> string", you would have to come up with some differences in behaviour.

I don't think so.  I think you'd have to come up with a definition,
or a specification, for the behavior of the Perl string.
Frankly, writing a C++ string class that had the same behavior
shouldn't be particularly difficult.  If one wanted to do it, one
could probably lift the C code which implements strings in perl
with very little modification.


> > > > > Were [classes] implemented in complex ways?
> >
> > I have enough faith in Bjarne's abilities to assume that the
> > implementation of classes in C++ is no more complex that it has
> > to be.  And that, of course, is quite complex, by almost any
> > standard.
>
> Why don't you demonstrate how the creation of a class is so much more
> complex in C++ than it is in Perl. As always, good luck.

Again it's beginning to seem like we're talking about different
things.  I *thought* we were talking about how the language
implementation supports the creation of classes and objects; now
it seems like you want to talk about how a programmer writes
classes in the language.  I also was not aware that we were
comparing C++ to Perl wrt the complexity of classes, but rather,
that the addition of OO made C++  -- the implementation thereof --
so much more complex than C.  But if you want to compare C++ to
Perl, well, at least then we'd be on-topic for this ng.

Hmm. The simplest "class definition" in Perl consists of no code
at all.  This does not stop you from having instances of the class,
however.

	$foo = bless {}, 'Foo';  # make an object of class Foo.

Of course, this is rarely useful.  Here's how you might populate
the Foo class with a method:

	sub Foo::frobbitz { }

Now you can do something with the object:

	$foo->frobbitz();

Maybe Foo inherits from Bar:

	@Foo::ISA = qw( Bar );

If the Bar class has methods, call one of 'em:

	$foo->blandage();  # not found in Foo, found in Bar.

Hmm, maybe Foo needs to modify its inheritance tree at runtime:

	unshift @Foo::ISA, 'Quux';

Make undefined method calls do something useful:

	sub Foo::AUTOLOAD {
		my $self = shift;
		my $name = $Foo::AUTOLOAD;
		$name =~ s/.*:://;  # strip the qualification
		$self->{'contained_object'}->$name( @_ );
	}


> > > The number lines is certainly relevant. That is one of the
> > > metrics by
> > > which we would test to see if the source code of one language
> > > is like
> > > that of another.
> >
> > Sure, but the results of that test say nothing about the equivalence
> > of the two languages.
>
> As a matter of fact they say a lot.

No, they say very little indeed.


> > > implying through your inability to
> > > even give the requested sample code,
> >
> > Not unable, just unwilling.  I have real work to do.
>
> Unable. End of story.

Not unable, just unwilling.
Stories, like newsgroup threads, don't end just because someone
declares them ended.


> > ...C++ is far more complex than C.  Unfortunate but true.
>
> If you find anything unfortunate about C++ specific syntax, just write
C
> code.

It's unfortunate that the benefits of C++ come at such a high
cost in complexity.  This was, of course, one of the motivating
factors in the creation of Java.

--
John Porter
Put it on a plate, son.  You'll enjoy it more.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


------------------------------

Date: Mon, 14 Jun 1999 20:08:49 +0200
From: "Armin S. A. Roehrl" <Armin.Roehrl@epfl.ch>
Subject: Perl tuning/speed question: all subsets of a set of length k -- keeping  the inital order
Message-Id: <37654531.82D5878C@epfl.ch>

Dear Perl champs,

I got some problem, and I wonder how close to the speed of C  I can get
with the following problem. I appreciate all your input a lot.

Given an array @file, which looks sth. like
@file=("This", "is","a", "sample", "and", "nothing", "else")
On average @file has some 100 to 10 000 items.

k is an integer between 1 and 25.
I want all ordered subsets of @file, of length k.
(e.g. keep the original order of the words)
So if k=2, e.g. the result would ne
This is
This a
This sample
This and
This nothing
This else
is a
is sample
is and
 ... etc. ..
nothing else

Thanks a lot and looking foward to your suggestions.
    Armin






------------------------------

Date: Mon, 14 Jun 1999 16:53:43 GMT
From: zephaar@my-deja.com
Subject: Python to perl convertor
Message-Id: <7k3c2h$ti0$1@nnrp1.deja.com>

Has anyone developed a convertor for translating python scripts
into perl? I have a whole bunch (about 30) scripts of sizes ranging
from 100 to about 600 lines each and would like to convert them
into perl.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


------------------------------

Date: Mon, 14 Jun 1999 14:36:39 -0400
From: Mike <mike@5starserv.com>
Subject: Redirection but no 'Back'
Message-Id: <37654BB7.C47D0C8A@5starserv.com>

I am using the perl script redir.pl which I understand to be a pretty
common script in use.  I am experiencing a problem that I cannot figure
out.  The script executes fine and sends the user to another site.  If
the user clicks his/her 'back' button, they are not sent back to the
page with the script, they remain at the site to which they were
redirected.

Is this the way the script was made to work?  If not, have I configured
it incorrectly?
Could it be a problem with the page at the other site?

Any help would be appreciated.

Mike



------------------------------

Date: 15 Jun 1999 07:39:52 GMT
From: hasant@trabas.co.id (Hasanuddin Tamir)
Subject: Re: simple math question!  Why doesn't the * multiply two numbers?
Message-Id: <slrn7mad4v.5r1.hasant@borg.intern.trabas.co.id>

On Sun, 13 Jun 1999 21:43:53 -0400, Ryan T. Rhea <ryan420@earthling.net> wrote:
> I have written the following script in perl.  Everything works except
> the multiplication.  What's going on?
> 
> #!/usr/bin/perl
> #
> # simple command line calculator
> # Copyright 1999 by Ryan T. Rhea
> $num1 = @ARGV[0];
> $oper = @ARGV[1];
> $num2 = @ARGV[2];
> if ($oper eq "+")
> {
>         print $num1 + $num2; print "\n";
> }
> 
> if ($oper eq "-")
> {
>         print $num1 - $num2; print "\n";
> }
> 
> if ($oper eq "/")
> {
>         print $num1 / $num2; print "\n";
> }
> 
> if ($oper eq "*")
> {
>         print $num1 * $num2; print "\n";
> }
> 

Since others have spotted the problem, I merely inform
that you may want to read Randal's columns for how to do
this much better. The title is `Subroutine References'.

   http://w3.stonehenge.com/merlyn/UnixReview/

HTH,

-- 
-hasan-
uhm, no more sig(h)


------------------------------

Date: Mon, 14 Jun 1999 18:09:19 GMT
From: "John" <john@nonet.com>
Subject: taint checking setuid error message
Message-Id: <01beb691$03f2a7a0$cd261ca5@B19592-WS.kcc.com>

I'm running perl v4 (actually ingperl v4). I get the following message when
running the script as any user other than the owner of the script:

Can't run setuid script with taint checks.

I got this message even though I did not have the set user id bit set on
the script. Setting the bit had no effect, still get the error message. 

Any help would be appreciated!


------------------------------

Date: Mon, 14 Jun 1999 17:13:30 GMT
From: Dominik <dominikos@my-deja.com>
Subject: Re: using perl scripts in VC++'s post-build step
Message-Id: <7k3d7f$u1r$1@nnrp1.deja.com>

In article
<Pine.GSO.4.02A.9906122143350.6999-100000@user2.teleport.com>,
  Tom Phoenix <rootbeer@redcat.com> wrote:
> On Sat, 12 Jun 1999, Dominik wrote:
>
> > @files = < @ARGV >;
>
> > The name specified is not recognized as an
> > internal or external command, operable program or batch file.
> > internal error: glob failed at my.pl line 1.
>
> This last line is in perldiag; have you seen it? But the answer is
that
> you probably didn't mean to glob like you did. Did you simply want to
copy
> the array? Cheers!

but it works in shell, why wouldn't work from VC++?

- Dominik


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


------------------------------

Date: Mon, 14 Jun 1999 18:56:29 GMT
From: pontz@channel1.com (Brian Pontz)
Subject: Re: which .tar.gz file contains Net::Cmd.pm?
Message-Id: <37655008.14475215@news2.channel1.com>

Hello,
Try libnet-1.0606.tar.gz
You could of found this out at www.cpan.org and do a search.

Brian Pontz

On Fri, 11 Jun 1999 19:46:04 GMT, dwang999@my-deja.com wrote:

>Which .tar.gz file contains the Net::Cmd.pm module?
>
>
>Sent via Deja.com http://www.deja.com/
>Share what you know. Learn what you don't.



------------------------------

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V8 Issue 5991
**************************************

home help back first fref pref prev next nref lref last post