[11926] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5526 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 30 08:07:34 1999

Date: Fri, 30 Apr 99 05:00:19 -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           Fri, 30 Apr 1999     Volume: 8 Number: 5526

Today's topics:
    Re: Calling functions iteratively <tchrist@mox.perl.com>
    Re: Checkbox is not working. (David Cantrell)
    Re: Checkbox is not working. <tchrist@mox.perl.com>
    Re: Example Server Code <bdp@mutagenic.org>
    Re: How to change effective GID <tchrist@mox.perl.com>
    Re: how to use require? <tchrist@mox.perl.com>
        Instance Data / Instance Variables gzm@gmx.de
    Re: Instance Data / Instance Variables <tchrist@mox.perl.com>
    Re: is there a switch statement in perl <tchrist@mox.perl.com>
        Moving the Perl distribution - global @INC problem srmorgan@my-dejanews.com
    Re: Passing Params <tchrist@mox.perl.com>
    Re: Perl calling exe program problem!!!!!!!!!!!!!! <tim@timbury.com>
    Re: Perl calling exe program problem!!!!!!!!!!!!!! <gellyfish@gellyfish.com>
        Perl on a 386 with 2 MB RAM??? <166959rl@student.eur.nl>
    Re: Regexp help needed <gellyfish@gellyfish.com>
    Re: Regexp help needed (Bart Lateur)
        Regexp or subst <rhardicr@hotmail.com>
    Re: Regexp or subst (Bart Lateur)
    Re: Speeding up text search of flatfile database? <tchrist@mox.perl.com>
    Re: unlink - why doesn't it work <tchrist@mox.perl.com>
    Re: unlink - why doesn't it work <tchrist@mox.perl.com>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: 30 Apr 1999 05:05:23 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Calling functions iteratively
Message-Id: <37298e73@cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, ada@fc.hp.com (Andrew Allen) writes:
:$#$_ returns the index of the
:last element of the list reference contained in $_. 

There is no such thing as a list reference.

--tom
-- 
    Just don't compare it with a real language, or you'll be unhappy...  :-)
            --Larry Wall in <1992May12.190238.5667@netlabs.com>


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

Date: Fri, 30 Apr 1999 10:11:24 GMT
From: NukeEmUp@ThePentagon.com (David Cantrell)
Subject: Re: Checkbox is not working.
Message-Id: <37298179.1386267066@news.insnet.net>

On Thu, 29 Apr 1999 23:44:23 GMT, jeffrey_f@my-dejanews.com
enlightened us thusly:

>I have a script which saves data..and keeps it in hidden fields.  Basically,
>you press next, and puts data into hidden fields.
>
>The problem is it only saves the last checkbox (last field in the HTML).   I
>can figure out why!!   Happens with any checkboxes...name doesnt matter, value
>doesnt...weird.
>
>Thanks Alot.

Thanks for what?  listening?  You haven't even asked a question!

Not to mention that the question you forgot to ask would have been
off-topic, as perl has no concept of 'checkboxes' or 'hidden fields'
whatever they may be.

[Copying newsgroup posts to me by mail is considered rude]

-- 
David Cantrell, part-time Unix/perl/SQL/java techie
                full-time chef/musician/homebrewer
                http://www.ThePentagon.com/NukeEmUp


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

Date: 30 Apr 1999 05:40:51 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Checkbox is not working.
Message-Id: <372996c3@cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    jeffrey_f@my-dejanews.com writes:
:I have a script which saves data..and keeps it in hidden fields.  Basically,
:you press next, and puts data into hidden fields.
:
:The problem is it only saves the last checkbox (last field in the HTML).   I
:can figure out why!!   Happens with any checkboxes...name doesnt matter, value
:doesnt...weird.

You've posted to the wrong newsgroup.  Try something more appropriate,
like alt.sex.checkboxes.

--tom
-- 
    Perl programming is an *empirical* science!  
	    --Larry Wall in <10226@jpl-devvax.JPL.NASA.GOV>


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

Date: Fri, 30 Apr 1999 04:46:49 -0600
From: Brian Peisley <bdp@mutagenic.org>
Subject: Re: Example Server Code
Message-Id: <37298A19.B4ED84C4@mutagenic.org>

Jonathan Stowe wrote:
> 
-snip
> 
> my $server = IO::Socket::INET->new ( LocalPort => 1112,
>                                      Type      => SOCK_STREAM,
>                                      Reuse     => 1,
>                                      Listen    => SOMAXCONN )
>                                 || die "Couldnt open socket $@\n";
                                                              ^^

Why do you use $@ here instead of $! ?. Please don't mistake this for anything
other than a question, I'm still reading docs so odds are I haven't got there
yet but what I did find in perlvar says it is the error message from the last
eval(), Is there an eval hiding in here somewhere?

Thanks,

Brian Peisley
bdp@mutagenic.org


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

Date: 30 Apr 1999 05:20:26 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: How to change effective GID
Message-Id: <372991fa@cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    Carrie Coy <carriec@doc.state.vt.us> writes:
:How do I change the effective GID of a user in a perl script?

Well, you could yun it setgid or setuid root (EEP), then fix it.

:The user belongs to several groups. This script creates a file which  I
:want to be owned by one of the user's supplemental groups.

Just set it after you create it.  This is the standard way.  Don't
assume that files are created based on the current gid.  That's the 
brain-dead sysV way.  Set it afterwards if you want to be portable
and convenient.

    chown -1, $desired_gid, @file_list;

--tom
-- 
    "The road to hell is paved with melting snowballs."
		--Larry Wall in  <1992Jul2.222039.26476@netlabs.com>


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

Date: 30 Apr 1999 05:32:05 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: how to use require?
Message-Id: <372994b5@cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, jingjinz@uci.edu writes:
:Hi, I try to do this simple thing.  I typed up this predefined html
:header and footer so every time when I want to draw a web page it'll
:save me a little trouble.  I put the subroutines header and footer in a
:file called html.pl
:and try to use it by typing "   require "html.pl"   "  and the error I
:get is
:
:"html.pl did not return a true value at test.pl line 2."

And what did use diagnostics -- or more directly, the perldiag manpage --
say about this?

    =item %s did not return a true value

    (F) A required (or used) file must return a true value to indicate
    that it compiled correctly and ran its initialization code correctly.
    It's traditional to end such a file with a "1;", though any true
    value would do.  See L<perlfunc/require>.

Shall I quote perlfunc/require to you as well? :-(

--tom
-- 
    I think it's a new feature.  Don't tell anyone it was an accident.  :-)
            --Larry Wall on s/foo/bar/eieio in <10911@jpl-devvax.JPL.NASA.GOV>


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

Date: Fri, 30 Apr 1999 10:31:33 GMT
From: gzm@gmx.de
Subject: Instance Data / Instance Variables
Message-Id: <7gc0q5$dpg$1@nnrp1.dejanews.com>

Hi Newsgroup,

I want to use instance variables for my perl objects but I don't know how to
declare and use them correctly.

In different books I found things like

$self->{NAME};

for creating instance variables. They always use $self, sometimes it's
$self = {};
and sometimes
$self = shift;

Now I have these questions:
- What exactly does $self={} or $self=shift mean in a new() method and in a
  other method.
- What exactly does "shift" and {} do?
- How do I have to declare instance variables and how do I use them from other
  methods within the object they belong to?

Georg

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 30 Apr 1999 05:59:08 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Instance Data / Instance Variables
Message-Id: <37299b0c@cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    gzm@gmx.de writes:
:- What exactly does $self={} or $self=shift mean in a new() method and in a
:  other method.

Did you read the perltoot and perlobj manpages?  Do you understand
the difference between a class method and an instance method?

:- What exactly does "shift" and {} do?

Did you read the perlfunc and perlref manpages?  Do you understand
the default argument?  Do you understand references to anonymous
hashes being used as records?

:- How do I have to declare instance variables and how do I use them from other
:  methods within the object they belong to?

You don't "declare" "instance variables".

I suggest reading the documentation referenced about, and if that
fails, please look into the examples from Chapter 13 from the Perl Cookbok.
You can fetch that code here:

    ftp://ftp.oreilly.com/published/oreilly/perl/cookbook/

--tom
-- 
Unix is like a toll road on which you have to stop every 50 feet to
pay another nickel.  But hey!  You only feel 5 cents poorer each time.
	--Larry Wall in <1992Aug13.192357.15731@netlabs.com>


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

Date: 30 Apr 1999 05:38:39 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: is there a switch statement in perl
Message-Id: <3729963f@cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    "Mario Anthony Thomas" <mario@alamar.net> writes:
:Is there a switch or case statement in perl or do I need to use blocks of if
:elsif else?

You didn't read the perlfaq7 manpage:

    % man perlfaq7
    ...
    How do I create a switch or case statement?

You didn't read the perlsyn manpage:
    % man perlsyn
    ...
    Basic BLOCKs and Switch Statements


You didn't search Deja News.

And you didn't read FMTEYEWTK on Switches.

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??)
Summary: 
Cc: spiegler@cs.uri.edu
References: <6sfb0m$m8e$1@nnrp1.dejanews.com>
Reply-To: tchrist@mox.perl.com (Tom Christiansen)
Followup-To: 
Distribution: 
Organization: Perl Consulting and Training
Keywords: 
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit

 [courtesy cc of this posting sent to cited author via email]

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
-- 
                /* And you'll never guess what the dog had */
                /*   in its mouth... */
        --Larry Wall in stab.c from the v4.0 perl source code


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

Date: Fri, 30 Apr 1999 10:46:13 GMT
From: srmorgan@my-dejanews.com
Subject: Moving the Perl distribution - global @INC problem
Message-Id: <7gc1lk$edb$1@nnrp1.dejanews.com>

We have multiple installations of perl at my workplace and I need to create
another one which will be owned by my group. Due to 'regression testing'
requirements I am not allowed to install a new one from source to the new
location, and we tried copying the perl executable and library directory to
the new location so that the relative paths (unix) are the same.

However, this does not work, perl still looks for the modules in the old
library location. Could anyone tell me if the main @INC locations are
compiled into perl when it is built, or if there is any way of changing this
globally without using -I in all programs? The relevant section from perlvar
(quoted below) mentions a "default Perl library", can anyone help with this
problem?

Thanks,

Steve Morgan

-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

     @INC    The array @INC contains the list of places to look
             for Perl scripts to be evaluated by the do EXPR,
             require, or use constructs.  It initially consists
             of the arguments to any -I command line switches,
             followed by the default Perl library, probably
             "/usr/local/lib/perl", followed by ".", to represent
             the current directory.  If you need to modify this
             at runtime, you should use the use lib pragma in
             order to also get the machine-dependent library
             properly loaded:

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 30 Apr 1999 05:24:16 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Passing Params
Message-Id: <372992e0@cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, Bob Walton <walton@frontiernet.net> writes:
:appear in environment variable QUERY_STRING (in %ENV{QUERY_STRING} in perl),
:for(sort keys %ENV){print "$_=%ENV{$_}\n";}

Um, no.  You mean $ENV{QUERY_STRING}.  You can't subscript a %Whatever.
And you probably don't want to play with your query string on your own.

--tom
-- 
    I already have too much problem with people thinking the efficiency of
    a perl construct is related to its length.  On the other hand, I'm
    perfectly capable of changing my mind next week...  :-) --lwall


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

Date: Fri, 30 Apr 1999 06:21:53 -0400
From: "Tim" <tim@timbury.com>
Subject: Re: Perl calling exe program problem!!!!!!!!!!!!!!
Message-Id: <925467695.983.60@news.remarQ.com>

Here is a piece of an excellent post, RE: Telnetting from UNIX to NT, made
by Bob Walton:

"One other thing you could do (which I have done) is to install a web server
on
your NT box.  Then you can put up an HTML form with an accompanying perl CGI
script.  The form has text boxes for the directory in which to run a DOS
command,
the DOS command itself, and a password; and a "run DOS command" submit
button.
The response from the CGI script is whatever the DOS command outputted.
This
works only for commands with text-only output, but lets one do quite a bit
of
stuff.  Web server software for NT is readily available and of reasonable
quality, unlike telnet servers.  With this, your Unix box could use a perl
script
with LWP::Simple to transmit the DOS command to your NT box.  Estimated
coding on
your part is about 100 lines."

Is you're exe a text-only program (like dir) or a windows gui thing?


    #VIKRAM BALKRISHNAN NATARAJAN# wrote in message ...
    Hi
      This time there is a slightly different problem...
     I am able to run simple perl scripts on my server when i call it form
the client....say just return a simple web page...

      now in my perl script i want to call an exe program(vfp)
      when i run the perl script from the server using command window the
script is able to execute the exe program...
      however if i use a browser to call the perl script which in turn calls
the exe program the execution does not take place .....

       anybody can help??
       is there some problem in the path?? but then  why does it work from
the command window and not from the client browser when i am able to run
other simple perl scripts from the client browser???

       thanks
    vikram






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

Date: 30 Apr 1999 11:19:02 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Perl calling exe program problem!!!!!!!!!!!!!!
Message-Id: <37298396@newsread3.dircon.co.uk>

#VIKRAM BALKRISHNAN NATARAJAN# <U903506@ntu.edu.sg> wrote:
> Hi
>   This time there is a slightly different problem...
>  I am able to run simple perl scripts on my server when i call it form
> the client....say just return a simple web page...
>   now in my perl script i want to call an exe program(vfp)
>   when i run the perl script from the server using command window the
> script is able to execute the exe program...
>   however if i use a browser to call the perl script which in turn calls
> the exe program the execution does not take place .....
>    anybody can help??
>    is there some problem in the path?? but then  why does it work from
> the command window and not from the client browser when i am able to run
> other simple perl scripts from the client browser???
>    thanks 

You have to bear in mind that a a program that is executed by an HTTP
server as part of the CGI is executed in a different environment than
that of a program that is executed at the command line.  

That the program runs at the command line and not when run by the HTTP
server is a sure sign that what you are looking at is not a Perl problem
at all but a question about the configuration of some server.

Probably the best thing to do is to talk to some local NT export who will
be able to explain to you the difference in the execution envirnonment.

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>



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

Date: Fri, 30 Apr 1999 12:09:49 +0200
From: "Ronald van der Lingen" <166959rl@student.eur.nl>
Subject: Perl on a 386 with 2 MB RAM???
Message-Id: <7gbvs0$u3$1@news.casema.net>

hello I want to install a perl interpreter on a 386 laptop with 2 MB RAM. Is
there a port that I can use on this system?

Ronald




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

Date: 30 Apr 1999 10:53:10 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Regexp help needed
Message-Id: <37297d86@newsread3.dircon.co.uk>

vincent <vroquencourt@businessobjects.com> wrote:
> Sean wrote:
> 
>> Hi,
>>         I've got a real quick question.  What is the correct regular expression
>> for matching ever character from the beginning of a string up to a
>> comma?  I'm using  /^.*,/ right now which matches the entire line which
>> is not what I want.  Any help is greatly appreciated.  ThanX!!!
>>
> 
> Use a greedy expression :     /^.*?,/
> 

I think you mean 'non-greedy'.

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>



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

Date: Fri, 30 Apr 1999 10:05:20 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Regexp help needed
Message-Id: <372d800f.12792801@news.skynet.be>

vincent wrote:

>         I've got a real quick question.  What is the correct regular expression
>> for matching ever character from the beginning of a string up to a
>> comma?  I'm using  /^.*,/ right now which matches the entire line which
>> is not what I want.  Any help is greatly appreciated.  ThanX!!!
>
>Use a greedy expression :     /^.*?,/

That is NON-greedy. "Greedy" is the default (without the question mark).

Alternatively, try

	/^[^,]*,/

which may or may not be faster.

	Bart.


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

Date: Fri, 30 Apr 1999 11:49:17 +0100
From: Richard H <rhardicr@hotmail.com>
Subject: Regexp or subst
Message-Id: <37298AAD.3F5D0298@hotmail.com>

Hi,
I think i should be using s but not sure how for the following:

I have a line $msg (from a Mainframe - i didnt choose the $)
and i have an array of variables (@errors) and desired result
is  'fies foes and fum repeats ble at ';
How do i substitute 'respectively' occurrence 1 of $$$ with $errors[0]
occ 2 of $$$ with $errors[1] and so on, 

my $msg = '$$$$ $$$$$$ and $$$ repeats $$$$ $$$$ $$ $$$$';             
my @errors = ("fies", "foes", "fum", "ble", "at", "", "", "");          
I can do them all with:
            
$msg =~ s/(\$+)+/$errors[0]/g;     

How can i index  $errors in the subst or do this better???

Thanks
Richard H


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

Date: Fri, 30 Apr 1999 11:21:07 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Regexp or subst
Message-Id: <3729910e.1942807@news.skynet.be>

Richard H wrote:

>my $msg = '$$$$ $$$$$$ and $$$ repeats $$$$ $$$$ $$ $$$$';             
>my @errors = ("fies", "foes", "fum", "ble", "at", "", "", "");          
>I can do them all with:
>            
>$msg =~ s/(\$+)+/$errors[0]/g;     

I don't think you wanted that second "+".
>
>How can i index  $errors in the subst or do this better???

Urm... something like:

	my $i=0;
	$msg =~ s/\$+/$errors[$i++]/ge;

Alternatively, you may try

	$msg =~ s/\$+/%s/g;
	$msg = sprintf($msg,@errors);

	Bart.


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

Date: 30 Apr 1999 05:09:25 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Speeding up text search of flatfile database?
Message-Id: <37298f65@cs.colorado.edu>

In comp.lang.perl.misc, 
    invalid-see-sig@nope.joefarmer.com (Brett Tabke) writes:
:I run a modest site directory (9000 sites).  I use a flat file database to
:store site info and an occasional full site spider/indexing.  As the db has
:grown, search response times have naturally also grown.  I have mysql
:online but that is unsatisfactory for a text search system (too much post
:processing makes it slower than a pure perl flatfile).

:	foreach (@rejects)	{  # check for "not" or -words in query string
:		if (($ss =~ /$_/i) && ($_ !~ /[A-Z]/))	{

Your performance bug is that you are interpolating variables into patterns.

As an address-munger, that's all the help you deserve.  Well, more,
actually.

--tom
-- 
"Many a good hanging prevents a bad marriage."
				- William Shakespeare


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

Date: 30 Apr 1999 05:34:48 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: unlink - why doesn't it work
Message-Id: <37299558@cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    "Mario Anthony Thomas" <mario@alamar.net> writes:
:I've noticed that the unlink function sometimes fails to delete a particular
:file - even when I know its trying to delete the correct file.
:
:Why does unlink fail? 

You're supposed to guess.  Use a crystal ball.

Sigh.  What do you think that on failure it sets $! to the errno for?
Just so you can ask us to use telepathy?

:Are there a list of reasons why it doesn't work
:sometimes?

Of course.  Did you forget to read the manpage?  Why?

    $ man 2 unlink
    ...

ERRORS
     The unlink() succeeds unless:

     [ENOTDIR]     A component of the path prefix is not a directory.

     [ENAMETOOLONG]
                   A component of a pathname exceeded {NAME_MAX} characters,
                   or an entire path name exceeded {PATH_MAX} characters.

     [ENOENT]      The named file does not exist.

     [EACCES]      Search permission is denied for a component of the path
                   prefix.

     [EACCES]      Write permission is denied on the directory containing the
                   link to be removed.

     [ELOOP]       Too many symbolic links were encountered in translating the
                   pathname.

     [EPERM]       The named file is a directory and the effective user ID of
                   the process is not the super-user.  of the process is not
                   the super-user, or the file system containing the file does
                   not permit the use of unlink() on a directory.

     [EPERM]       The directory containing the file is marked sticky, and
                   neither the containing directory nor the file to be removed
                   are owned by the effective user ID.

     [EBUSY]       The entry to be unlinked is the mount point for a mounted
                   file system.

     [EIO]         An I/O error occurred while deleting the directory entry or
                   deallocating the inode.

     [EROFS]       The named file resides on a read-only file system.

     [EFAULT]      Path points outside the process's allocated address space.

-- 
"Incrementing C by 1 is not enough to make a good object-oriented language."
(M. Sakkinen, in "On the Darker Side of C++", ECOOP'88)


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

Date: 30 Apr 1999 05:36:12 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: unlink - why doesn't it work
Message-Id: <372995ac@cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    "John" <moe@blackhole.vision.net.au> writes:
:Check the file permissions of the file and see if that's the problem?!

Wrong.  The permissions of the file are unrelated to one's ability
to delete it, except under rare circumstances.  I'm afraid you need
to retake Intro to Filesystems 101.

--tom
-- 
 Bus error - passengers dumped


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

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 5526
**************************************

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