[13551] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 961 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 1 05:07:12 1999

Date: Fri, 1 Oct 1999 02:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <938768709-v9-i961@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 1 Oct 1999     Volume: 9 Number: 961

Today's topics:
        Can perl create an excel file (HillFam2)
    Re: Can perl create an excel file (Martien Verbruggen)
    Re: Can perl create an excel file c_j_marshall@my-deja.com
    Re: Can perl create an excel file (AcCeSsDeNiEd)
    Re: Can perl create an excel file jmn.ac.delete@abanet.it
    Re: Catching errors in anouther name space. <rootbeer@redcat.com>
    Re: Catching errors in anouther name space. <admin@gatewaysolutions.net>
    Re: CONTEST: Range Searching <jeff@yoak.com>
    Re: embedding java in cgi to preload .wav files sophieloo@my-deja.com
        GDBM access behave differently  when called from CGI <l.laperrousaz@net-clic.net>
        how can i time out a process? <taras@telecom.lek.ru>
        multi dimensional array's <sorry@geen.nl>
    Re: perl & javascript!? <rootbeer@redcat.com>
    Re: perl & javascript!? (Martien Verbruggen)
        Perl Debugger <heiden@fkfs.uni-stuttgart.de>
    Re: Recurring segmentation fault c_j_marshall@my-deja.com
    Re: remove spaces (Martien Verbruggen)
    Re: Reversing records in a fixed length file. (Larry Rosler)
    Re: Sorting weird numeric data <uri@sysarch.com>
        Ton NOT Tom? was(Re: Bye Tom? (WAS: Re: injecting "my"  (I.J. Garlick)
        Understanding exec() (Bill Moseley)
    Re: Understanding exec() (Martien Verbruggen)
    Re: Understanding exec() (John Stanley)
    Re: Understanding exec() (John Stanley)
    Re: Understanding exec() (Martien Verbruggen)
    Re: using tr? <sorry@geen.nl>
        Validating email addresses. (Abigail)
        Win32, Is there a way to associate the PID and it's ima <davidmck@earthlink.net>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 01 Oct 1999 05:12:48 GMT
From: hillfam2@aol.com (HillFam2)
Subject: Can perl create an excel file
Message-Id: <19991001011248.24361.00000368@ng-fb1.aol.com>

Can I create an excel file from perl


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

Date: Fri, 01 Oct 1999 05:49:05 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Can perl create an excel file
Message-Id: <lXXI3.170$Fy1.6868@nsw.nnrp.telstra.net>

On 01 Oct 1999 05:12:48 GMT,
	HillFam2 <hillfam2@aol.com> wrote:
[How did this get past my Score file? need to twiddle it a bit]
> Can I create an excel file from perl

Yes.

If you know the format of the excel file, just write it out. Use open,
sysopen, print, write, pack, close, binmode, whatever you need.

If you feel very OLE-ish, look into one of the Win32:: modules. I
believe ActiveState has some info on those on their website.

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | Failure is not an option. It comes
Commercial Dynamics Pty. Ltd.       | bundled with your Microsoft product.
NSW, Australia                      | 


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

Date: Fri, 01 Oct 1999 06:34:33 GMT
From: c_j_marshall@my-deja.com
Subject: Re: Can perl create an excel file
Message-Id: <7t1klp$c9r$1@nnrp1.deja.com>

In article <19991001011248.24361.00000368@ng-fb1.aol.com>,
  hillfam2@aol.com (HillFam2) wrote:
> Can I create an excel file from perl
>

Well you can certainly create a file with the extension ".xls".
You can also delimit that file however you want and put whatever newline
characters you may need for excel/windows at the end of each line.

I suppose the question is - what do you want the excel file to look like
? If you are after an easy to upload comma delimited matrix of numbers
in a file called fred.xls then a firm "Yes" perl can do that.

If you want perl to build you pie charts etc in excel format - well you
may have a little work to do on that one.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 01 Oct 1999 06:58:26 GMT
From: dillon_rm@magix.com.sg (AcCeSsDeNiEd)
Subject: Re: Can perl create an excel file
Message-Id: <37f458b5.2374369@news.magix.com.sg>

Go check out the Win32::ODBC or DBD::ODBC modules

You need to make use of the ODBC (Open Database Conectivity) in Win32.


On 01 Oct 1999 05:12:48 GMT, hillfam2@aol.com (HillFam2) wrote:

>Can I create an excel file from perl

To e-mail me, remove "_rm"


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

Date: 1 Oct 99 08:31:26 GMT
From: jmn.ac.delete@abanet.it
Subject: Re: Can perl create an excel file
Message-Id: <37f4715e.0@etsv0008>


hillfam2@aol.com (HillFam2) wrote:
>Can I create an excel file from perl

Excel will read Comma or Tab separated text files that you can
create in Perl. 

If you want to write a binary file then you will need the Excel
SDK for information on the BIFF file format. 

Have a look in microsoft.public.excel.sdk but there are no easy
answers.

The internals of an Excel file soon get tedious for anything
more than writing raw data.

If you wish to write formatted data the COM approach suggested
by other posters is probably best.

John.


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

Date: Thu, 30 Sep 1999 22:47:02 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Catching errors in anouther name space.
Message-Id: <Pine.GSO.4.10.9909302246070.17231-100000@user2.teleport.com>

On Thu, 30 Sep 1999, Scott Beck wrote:

> Did you look at the code Tom?

I saw what you posted. I didn't see what you didn't post. 

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/




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

Date: Fri, 1 Oct 1999 01:10:18 -0500
From: "Scott Beck" <admin@gatewaysolutions.net>
Subject: Re: Catching errors in anouther name space.
Message-Id: <rv8lfbr33i535@corp.supernews.com>

Tom Phoenix <rootbeer@redcat.com> wrote in message
news:Pine.GSO.4.10.9909302246070.17231-100000@user2.teleport.com...
> On Thu, 30 Sep 1999, Scott Beck wrote:
>
> > Did you look at the code Tom?
>
> I saw what you posted. I didn't see what you didn't post.

What didn't I post?
That is the whole thing. The three subs at the bottom are mysql_tools.pl.
Maybe that caused confusion. I apologize for that.

Thanks
Scott



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

Date: Fri, 01 Oct 1999 00:16:26 -0700
From: Jeff Yoak <jeff@yoak.com>
Subject: Re: CONTEST: Range Searching
Message-Id: <y1z0N95jpluoD=6Gd7R8g5oqPl6O@4ax.com>


On 16 Sep 1999 08:52:46 -0700, Tom Christiansen <tchrist@mox.perl.com>
wrote:

>    3) Write a "patba" program that prints out up to
>       X lines before the match and Y lines after the match.
>
>	    patba [-A X] [-B T] pattern [files ...]
>


#!/usr/bin/perl -w

use strict;
use Getopt::Std;

use vars qw/$opt_A $opt_B/;
getopts('B:A:');
my $pat = shift;

my $range = $opt_A + $opt_B ;
my @stuff;

my $short;
for(my $i = 0; $i<=$range; $i++){
	if(my $data = <>){
		push @stuff, $data;
	} else {
		$short=1;
		last;
	}
}
for(my $i = 0; ($i<$opt_A && $i<=$#stuff); $i++){
	my $upper = $#stuff < $i+$opt_B ? $#stuff : $i+$opt_B;
	print @stuff[0..$upper] if $stuff[$i] =~ /$pat/;
}
if($short){
	for(my $i = $opt_A; $i<=$#stuff; $i++){
		print @stuff[$i-$opt_A..$#stuff] if $stuff[$i] =~
/$pat/;
	}
	exit;
}
while(<>){
	print @stuff if $stuff[$opt_A] =~ /$pat/;
	push @stuff, $_;
	shift @stuff;
}
for(my $i = $opt_A; ($i<=$range && $i<=$#stuff); $i++){
	my $upper = $#stuff < $range ? $#stuff : $range;
	print @stuff[$i-$opt_A..$upper] if $stuff[$i] =~ /$pat/;
}


__END__


My thought was to go from here to something that doesn't have to do
all that shifting and pushing and just keep track of the most recently
added list item with modula division and use a lot more slices.  That
might make it a bit faster.  I'm also a little curious about handling
the actual pattern.  I admit I've only tested mine of simple text
matches and haven't really thought through what would happen if you
tried something more complex.  I noticed some people manipulated the
pattern that came in, but I couldn't see the reason for the things
done.

Thanks for the problem, Tom.

Cheers,
Jeff


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

Date: Fri, 01 Oct 1999 06:37:32 GMT
From: sophieloo@my-deja.com
Subject: Re: embedding java in cgi to preload .wav files
Message-Id: <7t1krb$cj1$1@nnrp1.deja.com>

David,
Thankyou for your reply. I'll try thre cgi forum.
Elaine


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 1 Oct 1999 10:56:16 +0200
From: "Laurent.Laperrousaz" <l.laperrousaz@net-clic.net>
Subject: GDBM access behave differently  when called from CGI
Message-Id: <7t1t8t$j2i$1@jaydee.iway.fr>

I have a script that write to a GDBM file which works ok when started on a
command line but fails to work when launched by Apache. What is wrong ?

here are the few lines of  the script:

#!/usr/bin/perl
use Fcntl;
use GDBM_File;
use Carp;
($file) = $ARGV[0];
($key) = $ARGV[1];
($val) = $ARGV[2];
# ($self)= GDBM_File::TIEHASH (GDBM_File, $ARGV[0],GDBM_WRCREAT,640,
"fatal_func =croak");
($self)= GDBM_File::TIEHASH (GDBM_File, $ARGV[0],GDBM_WRCREAT,640);
GDBM_File::STORE $self, $ARGV[1], $ARGV[2];
untie ($class);
exit;

The script is called with 3 args : filename, key, value

the message i get in the Apache error_log is:
"db is not of type GDBM_File at ./addgdbm.pl line 10"

I can precise that I don't have problems writing in the directory (i changed
the code to writing to a raw file and it works)!
While writing seems impossible, reading is ok... I don't understand what
happens since reads are OK.

Anybody can help?

Thanks, Laurent





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

Date: Fri, 1 Oct 1999 12:19:22 +0400
From: "Taras V. Plakhotnichenko" <taras@telecom.lek.ru>
Subject: how can i time out a process?
Message-Id: <Pine.BSF.4.10.9910011211480.35782-100000@telecom.lek.ru>


How can i do the following:

Automatic exit from current parent process if the forked child is dead.
If the child is still alive - automatic exit from the current process and
killing the child after a certain amount of time.




-- 


Best regards,
Taras



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

Date: Thu, 30 Sep 1999 12:56:38 +0200
From: "MeTAlMollY" <sorry@geen.nl>
Subject: multi dimensional array's
Message-Id: <7svj8a$dum$1@tasmania.dev.ict.nl>

Hello everybody,

Is it possible to have a 3 dimensional array with Perl??
I know this is possible:

%table = ('key1' => 'value1'
          'key2' => 'value2');    etc. etc.

But now I want different %table's something like this:

%table[0] = ('key1' => 'value1'
             'key2' => 'value2');
%table[1] = ('key1' => 'value1'
             'key2' => 'value2');
%table[2] = ('key1' => 'value1'
             'key2' => 'value2');    Is this possible ???

Thanks and greets, Mark




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

Date: Thu, 30 Sep 1999 22:33:21 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: perl & javascript!?
Message-Id: <Pine.GSO.4.10.9909302229430.17231-100000@user2.teleport.com>

On Fri, 1 Oct 1999, csb wrote:

>     i created an array in perl, say @num which has values (1,2,3,4,5)..the
> problem occur when i use the @num in javascript...the following is the
> program:
> ==============================
> #!/usr/local/bin/perl -w

Nothing wrong with that, if that's the proper path to your perl binary.

>    @num = (1,2,3,4,5);
> 
>    &generateHTML;

That's valid Perl code.

> sub generateHTML
> {
> 
> print <<HTML;
> 
> <SCRIPT LANGUAGE="JavaScript1.2">
> 
>   var jArray = new Array(@num)   <-------------- can i do something like
> that?..coz i have error in here.
>    ............
> 
> </script
> 
> .......
> ......
> ......
> 
> HMTL;

That's not valid. You need the end tag ('HTML') to appear on a line by
itself, with no whitespace, punctuation, or anything else before or after.

You also omitted the closing curly brace of the subroutine.

If you fix those things, you could have a valid Perl program. But if
you're trying to find out whether the resulting JavaScript is correct,
you're asking the wrong folks.

Good luck!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 01 Oct 1999 05:39:57 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: perl & javascript!?
Message-Id: <NOXI3.165$Fy1.6868@nsw.nnrp.telstra.net>

On Fri, 1 Oct 1999 12:14:21 +0800,
	csb <rc3csb@usa.net> wrote:
> hi,
>     i created an array in perl, say @num which has values (1,2,3,4,5)..the
> problem occur when i use the @num in javascript...the following is the
> program:

Perl does not generate that error. I suspect that you have a
JavaScript error.  Perl generates a few others though:

> print <<HTML;
> 

>   var jArray = new Array(@num)   <-------------- can i do something like

The output for this line looks something like:

  var jArray = new Array(1 2 3 4 5)

Is that valid JavaScript? I don't know.. or rather, I do, but I have
my Perl hat on, and that hat is of a colour that doesn't agree too
well with the colour of my JavaScript wig.

You could ask in one of the JavaScript groups, or read a good manual
on that language.

> that?..coz i have error in here.

Not a perl error. Not here. You have a spelling error, though: Because
'because' has 7 letters, not 3 :)

> </script

This doesn't look like valid HTML to me. But that's a HTML error, not
a Perl one.
 
> HMTL;

I doubt very much that this ever worked. 1) Look at the spelling, 2)
What is that semicolon doing there? At least there is _one_ Perl error
in your code. But it is not the one you're describing, because this
one will behave the same, no matter what is in @num.

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | Think of the average person. Half of
Commercial Dynamics Pty. Ltd.       | the people out there are dumber.
NSW, Australia                      | 


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

Date: Fri, 01 Oct 1999 09:50:27 +0200
From: Martin zur Heiden <heiden@fkfs.uni-stuttgart.de>
Subject: Perl Debugger
Message-Id: <37F467C3.81B8390D@fkfs.uni-stuttgart.de>

Is there any Perl-Debugger, where a breakpoint can be set before
execution of the script?



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

Date: Fri, 01 Oct 1999 07:37:27 GMT
From: c_j_marshall@my-deja.com
Subject: Re: Recurring segmentation fault
Message-Id: <7t1obm$fsn$1@nnrp1.deja.com>


> > I run 'rehash' first (I'm using csh on a solaris box)
>
> Could it be that csh is giving the segfault, not perl? In any case, if
> 'rehash' (a csh builtin!) is "fixing" the problem, that's a sign that
it's
> more likely to be a csh bug than a Perl bug. Cheers!


I suppose that's feasible as I am dicking around a bit with STDERR etc.
Hmmm I suppose that makes me guilty of asking a 'this is not a perl
question'. Damn.

Oh well I'll just give myself 20 lashes today instead of the usual 40 as
penance.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 01 Oct 1999 05:45:27 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: remove spaces
Message-Id: <XTXI3.169$Fy1.6868@nsw.nnrp.telstra.net>

On Thu, 30 Sep 1999 21:30:11 -0700,
	Linda White <hpya78@postoffice.pacbell.net> wrote:
> Hello,
> I  have a file like:.
>  $ans = "            1234\n";
>  @aaa = $ans =~ /^\s//;
>  print "@aaa\n";
> 
> Can someone help me remove spaces and get 1234 ONLY.

You can't make '1234' from "            1234\n" by removing spaces
only. First you may want to think about which characters you want to
remove, and then you should read up on the tr/// operator, with the d
flag.

Alternatively, you could use the s/// operator with a regexp (What you
have above doesn't even compile), but tr/// is much better at doing
this sort of stuff.

# perldoc perlop

$ans = "            1234\n";
$ans =~ tr/\n //d;

(Add any other whitespace character that you want to remove)

or

$ans =~ s/[\n ]+//g;

or if you really mean all whitespace as defined by \s

$ans =~ s/\s+//g;

(The + will make it slightly more efficient that just the g flag)

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | Hi, Dave here, what's the root
Commercial Dynamics Pty. Ltd.       | password?
NSW, Australia                      | 


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

Date: Thu, 30 Sep 1999 23:10:39 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Reversing records in a fixed length file.
Message-Id: <MPG.125dc44a4d76c52398a019@nntp.hpl.hp.com>

In article <jakem-0110991149480001@dialup-sa-1-475.uni.camtech.net.au> 
on Fri, 01 Oct 1999 11:49:48 +0930, jakal <jakem@camtech.net.au> says...
 ...

[Vacuous comments snipped throughout.]

> (open(FILE,"$file"))  || die "can't open $file!";
 
What purpose do the quotes aroung $file serve?  They don't make up for 
the missing $! in the diagnostic.

> @records=<FILE>;
> 
> close(FILE);
> 
> @reverse_records=reverse(@records);
> chomp(@reverse_records);

First, let's chomp all the newlines.

> (open(OUT,">$outfile")) || die "can't open $outfile!";
> 
> foreach $record (@reverse_records)
> {
>    print OUT "$record\n";

Then, let's put them all back, one at a time.  Whee!

> }

    print OUT reverse <FILE>;

does that all a lot more cleanly.

Of course, this approach assumes the file fits comfortably in memory.  
If not, one of the various approaches to reading the file backwards will 
be needed.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 01 Oct 1999 01:33:39 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Sorting weird numeric data
Message-Id: <x7yadntzkc.fsf@home.sysarch.com>

>>>>> "BM" == Bill Moseley <moseley@best.com> writes:

  BM> As just a worker-bee programmer, how do I decided during the code
  BM> design phase when some sort is so large I need to consider another
  BM> method -- especially when the program is, say, a CGI script that
  BM> I'm not monitoring every time it runs?

  BM> I mean, should a light go off in my head at some threshold? --
  BM> "Say, I'm sorting 10,000 records now, but in a year it may be
  BM> 50,000 records and that seems like a lot! I better farm this out
  BM> to the sort utility."

  BM> Or should I, as I remarked in another thread, just wait for the
  BM> sysadmin to come calling?

tough question. you will have to answer it yourself as i/we have no idea
of the actual project and its growth potential. you could design it to
handle overflow itself by figuring out the maximum number of records
perl can sort without thrashing and pick some number below that
max. note the value will change if you add more ram. if you have more
than that many records do an external sort with /bin/sort. that assume
the number of records is sorta dynamic. if it just grows, do like you
said and wait for the sysadmin to wake you up at 4am.

it is easy to check for max perl sort size. just make a sort sub for you
records and sort 10, 100, 1000, .... 10eN records until the benchmarks
jump off the page. that last sort is too big for an in memory perl
sort. you can fine tune that if you wish to get a more accurate
number. use some value that is lower than the max you calculate to
determine if you sort in memory or externally. just from my benchmarks,
on a 128MB ultrasparc ii, i would thrash on 100k records of 100
bytes. that is only 10MB of data but you have to count perl data
overhead which is not cheap. also there were xwindows and other things
running. if this is a web server, you won't/shouldn't have windows
sucking up ram. but you may/will have lots of cgi processes forking out
all over.

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: Fri, 1 Oct 1999 08:36:54 GMT
From: ijg@connect.org.uk (I.J. Garlick)
Subject: Ton NOT Tom? was(Re: Bye Tom? (WAS: Re: injecting "my" varibales into callers scope))
Message-Id: <FIx19J.37C@csc.liv.ac.uk>

In article <7su5d7$sll$1@charm.magnus.acs.ohio-state.edu>,
ilya@math.ohio-state.edu (Ilya Zakharevich) writes:
> You are missing a point:  there are two different persons posting
> under the same netidentity.  Thanks go to one of them (from me too),
> flames go to another one (from me too).

Wowww. Back up there a minute Ilya. I know you are heavly involved in the
Perl community but can you explain this to me slowly.

You are saying that the Tom Christiansen we see posting here is not the
Tom Christiansen on the book covers, like I (amd probably many others)
thought?

Or are you implying he has a split personality? :) (no offence to anyone)

I tried to find evidence on deja.com, fot your claims, but since they
screwed the interface I have fun getting to grips with it (the power
search can't be relied on).

I would just like clarification on the above statement(s) as I have not
even seen a glimpse of this in the last year or so. Or is it simply you
have insider knowledge?

-- 
Ian J. Garlick
ijg@csc.liv.ac.uk

Executive ability is deciding quickly and getting somebody else to do
the work.
                -- John G. Pollard



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

Date: Thu, 30 Sep 1999 23:01:43 -0700
From: moseley@best.com (Bill Moseley)
Subject: Understanding exec()
Message-Id: <MPG.125dee265dcaded69897a8@206.184.139.132>

I'm confused about passing parameters to exec(), and when they need to 
be split.

This bit of code works just fine:

    # $params{files}{index_file} can be either one or two files names
    # separated by a space

    my @indexes = split /\s+/,$params{files}{index_file};

    exec( $params{search},
          '-w', $query,
          '-p', 'category','subject',
          '-f', @indexes,
     ) or log_message("Failed to exec '$params{search}' $! $?",1);


But changing either of these lines
          '-p', 'category','subject',
          '-f', @indexes,
to
          '-p', 'category subject',
          '-f', $params{files}{index_file}

Causes the $params{search} program to complain about bad parameters.  

For example, just using 
          '-f', $params{files}{index_file}
works unless there are two parameters in $params{files}{index_file}.

Ok, so maybe I need to split my parameters before the exec(), but the 
$query is a string of words, and it isn't being split and it works fine 
that way.  So what's up?

Am I confused or is my external program brain damaged?

-- 
Bill Moseley mailto:moseley@best.com
pls note the one line sig, not counting this one.


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

Date: Fri, 01 Oct 1999 06:24:42 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Understanding exec()
Message-Id: <KsYI3.187$Fy1.7696@nsw.nnrp.telstra.net>

On Thu, 30 Sep 1999 23:01:43 -0700,
	Bill Moseley <moseley@best.com> wrote:
> I'm confused about passing parameters to exec(), and when they need to 
> be split.
> 
> This bit of code works just fine:
> 
>     # $params{files}{index_file} can be either one or two files names
>     # separated by a space
> 
>     my @indexes = split /\s+/,$params{files}{index_file};
> 
>     exec( $params{search},
>           '-w', $query,
>           '-p', 'category','subject',
>           '-f', @indexes,
>      ) or log_message("Failed to exec '$params{search}' $! $?",1);

Your program receives exactly 6 + scalar(@indexes) arguments.

> But changing either of these lines
>           '-p', 'category','subject',
>           '-f', @indexes,
> to
>           '-p', 'category subject',
>           '-f', $params{files}{index_file}

Your program now receives 4 arguments precisely.

> Causes the $params{search} program to complain about bad parameters.  
> 
> For example, just using 
>           '-f', $params{files}{index_file}
> works unless there are two parameters in $params{files}{index_file}.

If there are two parameters in that variable, your program will
still receive one argument from that spot. It is now up to your program
to do something clever with that one argument.

> Ok, so maybe I need to split my parameters before the exec(), but the 
> $query is a string of words, and it isn't being split and it works fine 
> that way.  So what's up?
> 
> Am I confused or is my external program brain damaged?

It's your external program that determines how the arguments need to
be passed.

exec(LIST);

does almost the same thing (without expansion) as the shell would do
if each element of the list was a space separated word.

This means that if one of you elements of the list is something that
contains two words, that those two words will arrive as one argument
to your program. Just like they would if you put them in quotes in the
login shell.

exec('foo', '-p', 'category', 'subject');

is very much like (in fact the same, since there are no shell
metacharacters.

exec('foo -p category subject');

and more or less the same as typing this from your shell prompt:

# foo -p category subject

The program foo will receive three arguments, '-p', 'category' and
'subject'.

If you have 

exec('foo', '-p', 'category subject');

it is more equivalent to 

# foo -p 'category subject'
or
# foo -p "category subject"

The program receives two arguments: '-p' and 'category subject'.

There are very few programs who can deal with either of the two, and
still do something decent :).

In short: Use exec with a list, but pass your program the arguments
exactly as it expects them. If it needs category and subject as two
separate arguments, then pass them as separates.

Now... You could make use of the fact that as long as there are no
shell metacharacters in your string, exec and system will actually
split up their single argument, on spaces, and call execve directly.
This is not a problem. However, if there is a chance that there are
shell metacharacters in the input you receive (this is a CGI, right?)
you should really really make absolutely certain that nothing
dangerous can happen when that string goes off to the shell.

I would definitely go with the 'split the arguments on spaces, and
pass a list to exec'. It is easier to write safe code that way.

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | I took an IQ test and the results were
Commercial Dynamics Pty. Ltd.       | negative.
NSW, Australia                      | 


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

Date: 1 Oct 1999 06:29:41 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: Understanding exec()
Message-Id: <7t1kcl$32i$1@news.NERO.NET>

In article <MPG.125dee265dcaded69897a8@206.184.139.132>,
Bill Moseley <moseley@best.com> wrote:
>I'm confused about passing parameters to exec(), and when they need to 
>be split.

From the docs for exec:

]If there is more than one argument in LIST, or if LIST is an array
]with more than one value, calls execvp(3) with the arguments in LIST.
]If there is only one scalar argument or an array with one element in it,
]the argument is checked for shell metacharacters, and if there are any,
]the entire argument is passed to the system's command shell for parsing
](this is C</bin/sh -c> on Unix platforms, but varies on other platforms).
]If there are no shell metacharacters in the argument, it is split into
]words and passed directly to C<execvp()>, which is more efficient. 

>This bit of code works just fine:
>
>    # $params{files}{index_file} can be either one or two files names
>    # separated by a space
>
>    my @indexes = split /\s+/,$params{files}{index_file};
>
>    exec( $params{search},
>          '-w', $query,
>          '-p', 'category','subject',
>          '-f', @indexes,
>     ) or log_message("Failed to exec '$params{search}' $! $?",1);

This is the "more than one argument in LIST" version, so each entry in 
the list is a single paramter to the exec'd program, no matter what it 
contains. 

>But changing either of these lines
>          '-p', 'category','subject',
>          '-f', @indexes,
>to
>          '-p', 'category subject',
>          '-f', $params{files}{index_file}

You are telling your search program to search on "category subject"
instead of on "category" and "subject". Then you tell it to -f on
whatever one argument that $params{files}{index_file} evaluates to. In
the former code, you search on "category" and "subject", and @indexes
is an array that evaluates to one or more arguments.

>Ok, so maybe I need to split my parameters before the exec(), but the 
>$query is a string of words, and it isn't being split and it works fine 
>that way.  So what's up?

Your execd prgram apparently expects the query argument to be a string
of words. Or it expects a sequence of one word arguments that it just
catenates into a single string anyway. It expects one or more one word
arguments for -p and -f.  You should read the documentation for your
external program to find out what it expects and give it what it
wants.



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

Date: 1 Oct 1999 06:34:29 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: Understanding exec()
Message-Id: <7t1kll$3c9$1@news.NERO.NET>

In article <KsYI3.187$Fy1.7696@nsw.nnrp.telstra.net>,
Martien Verbruggen <mgjv@comdyn.com.au> wrote:
>On Thu, 30 Sep 1999 23:01:43 -0700,
>	Bill Moseley <moseley@best.com> wrote:
>> 
>> But changing either of these lines
>>           '-p', 'category','subject',
>>           '-f', @indexes,
>> to
>>           '-p', 'category subject',
>>           '-f', $params{files}{index_file}
>
>Your program now receives 4 arguments precisely.

6. "-w", $query, "-p", 'category subject', '-f', $params{files}{index_file}.



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

Date: Fri, 01 Oct 1999 06:48:33 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Understanding exec()
Message-Id: <5PYI3.190$Fy1.8129@nsw.nnrp.telstra.net>

On 1 Oct 1999 06:34:29 GMT,
	John Stanley <stanley@skyking.OCE.ORST.EDU> wrote:

> 6. "-w", $query, "-p", 'category subject', '-f', $params{files}{index_file}.

Whoops. yes, ok, I forgot about the once that were not being replaced :)

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | Begin at the beginning and go on till
Commercial Dynamics Pty. Ltd.       | you come to the end; then stop.
NSW, Australia                      | 


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

Date: Thu, 30 Sep 1999 14:01:04 +0200
From: "MeTAlMollY" <sorry@geen.nl>
Subject: Re: using tr?
Message-Id: <7svn13$smi$1@tasmania.dev.ict.nl>


An example could be:

$name =~ tr/A-Z/a-z/; # this lowercase everything

You can also read the Perl func help, or Perl FAQ, for more information
about regular expressions and tr.






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

Date: 1 Oct 1999 03:56:57 -0500
From: abigail@delanet.com (Abigail)
Subject: Validating email addresses.
Message-Id: <slrn7v8ual.8i.abigail@alexandra.delanet.com>


We've had this question many times in this newgroups, with all
sorts of attempts to do it all in a wacky regex. 

But why use a regex if there's this wonderful Parse::RecDescent
module of Damian Conway?  Here's a module using Parse::RecDescent
to check the syntax of email addresses.


Have fun.


Abigail

package RFC::822::Address;

#
# $Id: Address.pm,v 1.1 1999/10/01 08:50:13 abigail Exp abigail $
#
# $Log: Address.pm,v $
# Revision 1.1  1999/10/01 08:50:13  abigail
# Initial revision
#
#

use strict;
use Exporter;
use Parse::RecDescent;

use vars qw /@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION/;

@ISA         = qw /Exporter/;
@EXPORT      = qw //;
@EXPORT_OK   = qw /valid/;
%EXPORT_TAGS = ();

($VERSION)   = '$Revision: 1.1 $' =~ /([\d.]+)/;

$Parse::RecDescent::skip = "";
local $/;

# Now, pay attention. There are only 2 important lines of Perl in this
# module, and they follow now. ;-)
my $parser = Parse::RecDescent -> new (<DATA>) or die "Compilation error.\n";
sub valid {$parser -> valid (shift)}

# That's it. The rest is just data....

<<'=cut'

=pod

=head1 NAME

RFC::822::Address  --  RFC 822 style address validation.

=head1 SYNOPSIS

    use RFC::822::Address qw /valid/;

    print "Valid\n" if valid ('abigail@delanet.com');

=head1 DESCRIPTION

This module checks strings to see whether they are have the valid
syntax, as defined in RFC 822 [1]. One subroutine, C<valid>, can
be imported, which takes a single string as argument. If the string
is valid according to RFC 822, a true value is returned, else a
false value is returned.

=head1 REFERENCES

=over 4

=item [1]

David H. Crocker (revisor): "STANDARD FOR THE FORMAT OF ARPA INTERNET
TEXT MESSAGES". RFC 822. 13 August 1982.

=back

=head1 CAVEATS

This module sets the variable C<$Parse::RecDescent::skip>. This will
all other C<Parse::RecDescent> parsers. And this parser will break if
you set C<$Parse::RecDescent::skip> to another value. It doesn't look
that it is possible to set an alternative skip value for each parser,
other than setting the skip value on each production.

It is often suggested that one can put I<comment>s anywhere in an 
email address. However, it doesn't look like the grammar of
RFC 822 allows that.

C<valid> will only return a true value if the argument matches exactly.
Leading and trailing whitespace B<will> cause the match to fail. That's
a feature, not a bug.

=head1 REVISION HISTORY

    $Log: Address.pm,v $
    Revision 1.1  1999/10/01 08:50:13  abigail
    Initial revision


=head1 AUTHOR

This package was written by Abigail, abigail@delanet.com.

=head1 COPYRIGHT and LICENSE

This package is copyright 1999 by Abigail.

This program is free and open software. You may use, copy, modify,
distribute and sell this program (and any modified variants) in any way
you wish, provided you do not restrict others to do the same.

=cut

__DATA__

HTAB:         /\x09/                             # ASCII Horizontal tab
LF:           /\x0A/                             # ASCII Linefeed
CR:           /\x0D/                             # ASCII Carriage return
SPACE:        ' '                                # ASCII space
AT:           '@'                                # ASCII AT

LWSP_char:    SPACE | HTAB                       # Semantics = SPACE
CHAR:         /[\x00-\x7F]/                      # Any ASCII character.
CTL:          /[\x00-\x1F\x7F]/                  # Any ASCII control character
                                                 # and DEL
special:      /[]()<>@,;:\\".[]/                 # Must be in quoted string
                                                 # to be use within word.
CRLF:         CR LF

linear_white_space:                              # Semantics = SPACE
              (CRLF(?) LWSP_char)(s)             # CRLF => folding


atom:         /[^]\x00-\x20 \x7F\x80-\xFF()<>@,;:\\".[]+/
                                                 # Any CHAR except specials,
                                                 # SPACE and CTLs
dtext:        /[^]\\\x0D\x80-\xFF[]/             # Any CHAR, excepting [, ], \,
           |  linear_white_space                 # and CR, and including
                                                 # linear-white-space =>
                                                 # may be folded
qtext:        /[^"\\\x0D\x80-\xFF]/              # Any CHAR, excepting ", \,
           |  linear_white_space                 # and CR, and including
                                                 # linear-white-space =>
                                                 # may be folded
quoted_pair:  '\\' CHAR                          # May quote any char
quoted_string:
              '"' (qtext | quoted_pair)(s?) '"'  # Regular qtext or quoted chars
domain_literal:
              '[' (dtext | quoted_pair)(s?) ']'


word:         atom
           |  quoted_string
phrase:       word(s)                            # sequence of words


valid:        address /^\Z/ {1}

address:      mailbox                            # one addressee
           |  group                              # named list

group:        phrase ':' <leftop: mailbox ',' mailbox>(?) ';'

mailbox:      addr_spec                          # simple address
           |  phrase route_addr                  # name & addr-spec

route_addr:   '<' route(?) addr_spec '>'

route:        <leftop: (AT domain) ',' (AT domain)> ':'
                                                 # path-relative

addr_spec:    local_part '@' domain              # global address

local_part:   <leftop: word '.' word>            # uninterpreted
                                                 # case-preserved

domain:       <leftop: sub_domain '.' sub_domain>

sub_domain:   domain_ref
           |  domain_literal

domain_ref:   atom                               # symbolic reference


-- 


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: Fri, 1 Oct 1999 00:05:02 -0700
From: "David McKay" <davidmck@earthlink.net>
Subject: Win32, Is there a way to associate the PID and it's image...
Message-Id: <7t1mbt$o13$1@ash.prod.itd.earthlink.net>

Is there a way to get the 'image' information that is associated to a PID,
as in the
Task Manager?

Trying to come up with a safe way to ensure that the process targeted for
'kill'
is indeed the correct one, and not a process that has been assigned to that
number
after the 'targeted' one had died.

TIA,

david





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

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


Administrivia:

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.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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.

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 V9 Issue 961
*************************************


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