[19566] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1761 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 17 14:10:31 2001

Date: Mon, 17 Sep 2001 11:10:11 -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: <1000750211-v10-i1761@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 17 Sep 2001     Volume: 10 Number: 1761

Today's topics:
        Parent/Child Tk::fileevent & very confused (Stan Brown)
    Re: Parent/Child Tk::fileevent & very confused (Clinton A. Pierce)
    Re: Parent/Child Tk::fileevent & very confused (Stan Brown)
    Re: Parent/Child Tk::fileevent & very confused (Stan Brown)
    Re: Peek and Poke on Perl? (Malcolm Dew-Jones)
    Re: Reading cookies from a different path (Jonadab the Unsightly One)
    Re: recognize MS Windows with perl (Jonadab the Unsightly One)
        Regexp Questions (Marc Schaefer)
    Re: Regexp Questions <markus.laire@usa.net>
        Simple CGI: how to set up downloads? <alicia090677@hotmail.com>
    Re: Simple CGI: how to set up downloads? <bill.kemp@wire2.com>
    Re: Simple CGI: how to set up downloads? <Peter.Dintelmann@dresdner-bank.com>
        Statistics for comp.lang.perl.misc <gbacon@cs.uah.edu>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 17 Sep 2001 09:08:39 -0400
From: stanb@panix.com (Stan Brown)
Subject: Parent/Child Tk::fileevent & very confused
Message-Id: <9o4skn$a6c$1@panix1.panix.com>

 I have a task the splits itself inot a parent, and a child, then passes
 information retrieved from an Oracle DB by the child back to the parent.

 Problem is, that the TK widgets (controled by the parent) refuse to update
 themseleves while this transfer is going on. I have even added a 10 second
 sleep, every 100 records, in the child! It still does not update the
 widgets, even while in this slepp! Also during the sleeep, system CPU
 loading becomes very low. 

 Here are some snipets of the code:


	The subroutine that does the fork.

sub fetch_records ($$$) {
#####################################################################
#
# Prepares and executes a database query, based upon the
# info in %data_fileds
#
# Inputs
#
# 1. Name of the table we are working on
# 2. Total number of rows in the table we are working on
# 3. pointer to hash of column names, and atributes
#
# Side effects
# Spawns a child task to execute the DB fetch
# The callback triggered by this cahild does the followig:
# Sets %record_set[] to contain all the returned records
# Adds quantity of records, and currently displayed record
# number widgets to main window
#
#####################################################################
my ($ltable,$total_rows_this_table,$hash_pointer)=@_;
my $pid;
my $pipe;
my $rc;
my $sths;
my $rp = 0;
my $function_name = (caller(0))[3];
my $argtmp = join ', ', map "Arg$_ " . 
			( defined $_[$_] ? "->$_[$_]<-" : 
			'*UNDEF*'), 0 .. $#_;

print_debug(2,"Entering $function_name()\n",0,0);
print_debug(3,"$argtmp\n",0,0);

	my $stmt = create_query_statement($ltable,$hash_pointer);
	print_debug(1, "**** Query = \n->$stmt<-\n",1,0);

	$record_qty = 0;
	undef $records_array_ref;
	# $MW->Busy;
	pipe my ($reader, $writer) or die "pipe: $!";
	if( my $pid = fork ) {
		# parent process here
		print_debug(1,"Parent task\n",0,1);
		$child_pid = $pid;
		close $writer;
		$please_wait_popup = popup_info("Retrieving Records From DB. Please wait");
		$MW->fileevent($reader,
						"readable",
						[\&new_records_avail, 
						  $reader, 
						  $pid, 
						  $total_rows_this_table]);
	} elsif( defined $pid ) {
		# child process here
		print_debug(1,"Child task started\n",0,1);
		close $reader;
		$writer->autoflush(1);
		select( (select($writer), $|=1)[0] );
		eval {
			# Prepare query 
			print_debug(1, "Prepare Satrted\n",1,1);
			$sths = $dbh->prepare("$stmt");
			print_debug(1, "Prepare Done. Execute Started\n",1,1);
			$rc = $sths->execute or die $DBI::errstr;
			print_debug(1, "Execute done\n",1,1);
			while( my $onerow = $sths->fetchrow_arrayref ) {
				store_fd( $onerow, $writer ) or die "can't store to $writer\n";
				if($rp == 100)
				{
					sleep(10);
					# SDB
					print "Sleeping\n";
					$rp = 0;
				}
				++$rp;
			}
			store_fd( [], $writer ) or die "can't store to $writer\n";
			print_debug(1, "Fetch done\n",1,0);
		};
		store_fd \$DBI::errstr, $writer if $@;
		close $writer;
		$sths->finish();
		print_debug(5,"Child task done\n",0,1);
		undef $child_pid;
		POSIX::_exit(0);
	}

print_debug(3,"Returning from $function_name()\n",0,0);
}

The parents fileevent callback:


sub new_records_avail($$$) {
######################################################################
#
# new_records_avail
#
# The callback routine, that is called when the child task, which
# does the actual DB fetch, has data available.
#
# Inpits
# 
# 1. The filehandle to read from
# 2. The pid of the child
# 3. The total number of records in the table we are working on
#
#####################################################################
my ($reader,$pid,$total_rows_this_table)=@_;
my $rb;
my $sb;
my $cb;
my $col;
my $plural;
my $junk;
my(@seperator_attributes) = qw/-width 10 -height 40/;
my $function_name = (caller(0))[3];
my $argtmp = join ', ', map "Arg$_ " . 
			( defined $_[$_] ? "->$_[$_]<-" : 
			'*UNDEF*'), 0 .. $#_;

print_debug(2,"Entering $function_name()\n",0,0);
print_debug(3,"$argtmp\n",0,0);

	my $arow = fd_retrieve $reader;
	die "Unexpected eof $!" if !$arow;
	if( !@$arow ) {
		print_debug(1, "Done With Fetching commify($record_qty) Selected Records\n",1,1);
		$MW->fileevent( $reader, "readable", "" );
		if ($record_qty == 1)
		{
  			$next_button->configure( -state => 'disabled');
  			$prev_button->configure( -state => 'disabled');
		}
		print_debug(1, "Sending kill for preocess $pid\n",1,1);
		kill 9, $pid;
		waitpid( $pid , 0);
		print_debug(1, "Preocess $pid is terminated\n",1,1);
		close $reader;
		$MW->Unbusy();
		if (defined $please_wait_popup)
		{
			$please_wait_popup->destroy();
		}
		popup_msg("All Records That Match Your Selected Criteria Have Now Been Fetched");
		if($record_qty == 0)
		{
			popup_msg("No Records match this query");
		}
		else
		{
			if($record_qty > 1)
			{
				$plural = "Records";
			}
			else
			{
				$plural = "Record";
			}
			my $cq = commify($record_qty);
			$fetch_status = "Displaying Record $pos Of $cq $plural Fetched So Far.";
			# Go to new state
			#
			# Yes, I know I said all of these should be in DoIT()
			# However now that the actual DB fetch is done
			# via a child process, this is asynchronous,
			# and MUST be done in this callback
			$State = 'PROCESING_QUERY_RESULTS';
		}
		return;
	}
	@{$records_array_ref->[$record_qty]} = @$arow;
	if($record_qty == 0)
	{
		STDOUT->autoflush(1);
		print_debug(1, "First record recieved\n",1,1);
		# Display first record
		$pos = 1;
		# We depend upon the order of the columns to retrieve
		# in the SELECT statement being created in this same order
		# I don't like this, but the alternative was copying
		# all the retrieved data rows, and this was prooblematic
		# on large (1 million row) record sets
		my $i = 0;
		foreach $col (sort keys  %cols)
		{
			if($cols{$col}{'DATA_TYPE'} eq 'DATE')
			{
				my $dt = ParseDate( $records_array_ref->[($pos - 1)]->[$i]);
				$data_fields{$col} = UnixDate($dt, "%s");
			}
			else
			{
				$data_fields{$col} = $records_array_ref->[($pos - 1)]->[$i];
				print_debug(6,
					"Set data_fields{col} for $col to ->$data_fields{$col}<-\n",
					0,
					0);
			}
			$i++;
		}
		# Make a copy, BEFORE anyone can change this
		# Need this to use in UPDATE
		%this_record = %data_fields;
	
		$MW->packPropagate(1);
		# Create a little space between buttons and record qty status fileds
		$rec_spacer = $MW->Frame(@seperator_attributes);
		$rec_spacer->pack( -side => 'left');

		$rec_label   = $MW->Label(-text => "Displaying Record" ,
								-anchor => 'se', 
								-height => 1, 
								-justify => 'center');
		$rec_label->pack( -side => 'top' ,
						-expand => 'n' ,
						-fill => 'none' );
		my $w = length($record_qty);
		$rec_entry   = $MW->Entry(-textvariable => \$pos ,
									-relief => 'solid' ,
									-borderwidth => 0 ,
									-takefocus => 0 ,
									-width => $w );
		$rec_entry->pack( -side => 'top' ,
						-expand => 'n' ,
						-fill => 'none' );
		$w = length($fetch_status) + 10;
		$rec_label2   = $MW->Entry(-textvariable => \$fetch_status,
								-relief => 'solid' ,
								-borderwidth => 0 ,
								-takefocus => 0,
								-width => $w );
		$fetch_status = "Displaying Record 1 Of 1 Records Fetched So Far.";
		$w = length($fetch_status);
		$rec_label2->pack( -side => 'top' ,
						-expand => 'y' ,
						-fill => 'x' );
		# Got record(s)
		# Set widgets to proper enabled/disabled state for the allowed
		# actions in this state
		if(defined $insert_button)
		{
  			$insert_button->configure( -state => 'active');
		}
		if(defined $update_button)
		{
  					$update_button->configure( -state => 'active');
		}
		if(defined $delete_button)
		{
  					$delete_button->configure( -state => 'active');
		}
  		$execute_button->configure( -state => 'disabled');
  		$enter_button->configure( -state => 'active');
  		$next_button->configure( -state => 'active');
  		$prev_button->configure( -state => 'active');
		if(defined $save_button)
		{
  			$save_button->configure( -state => 'active');
		}
 		foreach $rb (@radiobuttons) {
			if(defined $rb)
			{
  						$rb->configure( -state => 'active');
			}
		}
		while (($junk, $cb) = each %comparebuttons) {
			if(defined $cb)
			{
  						$cb->configure( -state => 'disabled');
			}
		}
		while (($junk, $sb) = each %sortbuttons) {
			if(defined $sb)
			{
  						$sb->configure( -state => 'disabled');
			}
		}
		++$record_qty;
		print_debug(1, "First record Processing Complete\n",1,1);
		return;
	}
	++$record_qty;
	# SDB
	++$qr;
	if($qr == ($total_rows_this_table / 100))
	{
		if($record_qty > 1)
		{
			$plural = "Records";
		}
		else
		{
			$plural = "Record";
		}
		my $cq = commify($record_qty);
		$fetch_status = "Displaying Record $pos Of $cq $plural Fetched So Far.";
		my $qty = commify($record_qty);
		print "\r$qty";
		$qr = 0;
		$MW->update();
	}
print_debug(3,"Returning from $function_name()\n",0,0);
} 

Can anyone explain this beahvior to me?

I originally thought the problem was sim,ple CPU loadinbg while passing all
this data back. But I have (at least for test pruposes) elimnated this. So
it looks like the parent must be stucj in some sort of system call? 

I really don't have a clue what's going on here.



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

Date: Mon, 17 Sep 2001 14:24:52 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: Parent/Child Tk::fileevent & very confused
Message-Id: <3ba601f5.5047207@localhost>

On 17 Sep 2001 09:08:39 -0400, stanb@panix.com (Stan Brown) wrote:

> I have a task the splits itself inot a parent, and a child, then passes
> information retrieved from an Oracle DB by the child back to the parent.
>
> Problem is, that the TK widgets (controled by the parent) refuse to update
> themseleves while this transfer is going on. I have even added a 10 second
> sleep, every 100 records, in the child! It still does not update the
> widgets, even while in this slepp! Also during the sleeep, system CPU
> loading becomes very low. 
>
> Here are some snipets of the code:
> [THIS IS A SNIPPET OF CODE?]
>Can anyone explain this beahvior to me?
>
>I originally thought the problem was sim,ple CPU loadinbg while passing all
>this data back. But I have (at least for test pruposes) elimnated this. So
>it looks like the parent must be stucj in some sort of system call? 
>
>I really don't have a clue what's going on here.

In a nutshell, the Tk widgets need to have some processor time turned
over to them for maintenance.  Normally Tk programs have something
like this:

	$mainwidget->MainLoop;

And they kinda just run on their own, and your code would be called as
a series of callbacks (when buttons are pushed, etc...).

What you want to do is the opposite -- you want your code to run and
loop and eat the CPU and occasionally you need to hand control back to
Tk so it can update its widgets, move things around, etc...

Sometime in the midst of your loop, tell Tk to go and do its
maintenance with:

	$MW->idletasks();   # or....
             $MW->update();

Which one you use depends on what kinds of events you want updated.
The Tk::widget manpage has details.




    Clinton A. Pierce              Teach Yourself Perl in 24 Hours  *and*
  clintp@geeksalad.org         Perl Developer's Dictionary -- May 2001
"If you rush a Miracle Man,     for details, see http://geeksalad.org
        you get rotten Miracles." --Miracle Max, The Princess Bride


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

Date: 17 Sep 2001 11:50:23 -0400
From: stanb@panix.com (Stan Brown)
Subject: Re: Parent/Child Tk::fileevent & very confused
Message-Id: <9o563v$7hl$1@panix1.panix.com>

In <3ba601f5.5047207@localhost> clintp@geeksalad.org (Clinton A. Pierce) writes:

>On 17 Sep 2001 09:08:39 -0400, stanb@panix.com (Stan Brown) wrote:

>> I have a task the splits itself inot a parent, and a child, then passes
>> information retrieved from an Oracle DB by the child back to the parent.
>>
>> Problem is, that the TK widgets (controled by the parent) refuse to update
>> themseleves while this transfer is going on. I have even added a 10 second
>> sleep, every 100 records, in the child! It still does not update the
>> widgets, even while in this slepp! Also during the sleeep, system CPU
>> loading becomes very low. 
>>
>> Here are some snipets of the code:
>> [THIS IS A SNIPPET OF CODE?]
>>Can anyone explain this beahvior to me?
>>
>>I originally thought the problem was sim,ple CPU loadinbg while passing all
>>this data back. But I have (at least for test pruposes) elimnated this. So
>>it looks like the parent must be stucj in some sort of system call? 
>>
>>I really don't have a clue what's going on here.

>In a nutshell, the Tk widgets need to have some processor time turned
>over to them for maintenance.  Normally Tk programs have something
>like this:

>	$mainwidget->MainLoop;

>And they kinda just run on their own, and your code would be called as
>a series of callbacks (when buttons are pushed, etc...).

>What you want to do is the opposite -- you want your code to run and
>loop and eat the CPU and occasionally you need to hand control back to
>Tk so it can update its widgets, move things around, etc...

>Sometime in the midst of your loop, tell Tk to go and do its
>maintenance with:

>	$MW->idletasks();   # or....
>             $MW->update();

>Which one you use depends on what kinds of events you want updated.
>The Tk::widget manpage has details.

Thanks.

Yes, I do have a main loop. See below:

# Interact...
MainLoop();

Then, form a pushbitton callback, the parent and the child are forked (see
first code snippet in original post). Later, after teh DBI fetch is
complete, the child starts writting to the pipe. The reader rend of the
pipe is a Tk::fileevent callback. Now, in the child I have a sleep. The
parent should not be in a callback, at all, once it frains the pipe.

yet it's not updateing the widgets.

Thsi is what puzzles me.



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

Date: 17 Sep 2001 13:27:38 -0400
From: stanb@panix.com (Stan Brown)
Subject: Re: Parent/Child Tk::fileevent & very confused
Message-Id: <9o5bqa$pk$1@panix1.panix.com>

In <9o563v$7hl$1@panix1.panix.com> stanb@panix.com (Stan Brown) writes:

>In <3ba601f5.5047207@localhost> clintp@geeksalad.org (Clinton A. Pierce) writes:

>>On 17 Sep 2001 09:08:39 -0400, stanb@panix.com (Stan Brown) wrote:

>>> I have a task the splits itself inot a parent, and a child, then passes
>>> information retrieved from an Oracle DB by the child back to the parent.
>>>
>>> Problem is, that the TK widgets (controled by the parent) refuse to update
>>> themseleves while this transfer is going on. I have even added a 10 second
>>> sleep, every 100 records, in the child! It still does not update the
>>> widgets, even while in this slepp! Also during the sleeep, system CPU
>>> loading becomes very low. 
>>>
>>> Here are some snipets of the code:
>>> [THIS IS A SNIPPET OF CODE?]
>>>Can anyone explain this beahvior to me?
>>>
>>>I originally thought the problem was sim,ple CPU loadinbg while passing all
>>>this data back. But I have (at least for test pruposes) elimnated this. So
>>>it looks like the parent must be stucj in some sort of system call? 
>>>
>>>I really don't have a clue what's going on here.

>>In a nutshell, the Tk widgets need to have some processor time turned
>>over to them for maintenance.  Normally Tk programs have something
>>like this:

>>	$mainwidget->MainLoop;

>>And they kinda just run on their own, and your code would be called as
>>a series of callbacks (when buttons are pushed, etc...).

>>What you want to do is the opposite -- you want your code to run and
>>loop and eat the CPU and occasionally you need to hand control back to
>>Tk so it can update its widgets, move things around, etc...

>>Sometime in the midst of your loop, tell Tk to go and do its
>>maintenance with:

>>	$MW->idletasks();   # or....
>>             $MW->update();

>>Which one you use depends on what kinds of events you want updated.
>>The Tk::widget manpage has details.

This gets more interesting. It appears that the reason that the parent is
not updateing the widgets is that it's still in the fileevent callback
while the child sleeps.

Specificly, it's hung on the fd_retrieve() line!

Isn't this supposed to be non blocking? Or should the fileevent calback not
et called when it's not ready to read?

What can I do to further diagnose this problem?



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

Date: 17 Sep 2001 09:59:35 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Peek and Poke on Perl?
Message-Id: <3ba62bf7@news.victoria.tc.ca>

Gary (gamtci1@mpinet.net) wrote:
: I have built some circuit boards which reside at one of the classic 
: PC locations of a000, b000, c000, d000 or e000. I have been using 
: (as was the intention) DOS to operate the board and have written 
: a driver for it. During the time I was designing and building these
: boards I was introduced to Perl. I decided to use Perl and Tk to 
: create an "applications generator" for the boards. That is, a user 
: may select from various options, etc. The application runs fine.

: In fact, Perl has impressed me so much that I have been thinking to 
: give it a try running the boards also. What I need in order to do 
: that are two functions identical to "peek" and "poke". I know Windows
: is running protected mode, so one can't simply peek and poke. Is 
: there a module available for Perl which provides such functionality?
: I have searched CPAN and a general web search, but either must be 
: entering the wrong search criteria or perhaps, it doesn't exist.

: Any help on locating such a module would be greatly appreciated.
: Thanks in advance.

I don't know about a module to do that, but a few ideas spring to mind..

You could write a C library and call it as a module.  The keyword is XS
and there's a pod file "perlxstut.pod" which discusses how to do this.

There's a module called Inline, which allows you to embed C code directly
in perl.  (I think it uses the XS stuff).

I think you can use languages other than C.


If you aren't sending and receiving too much data or too often, then you
could write a standalone program to access the ports and then communicate
with that program from within perl. 
	e.g.	system("toggle_the_port ON");
or perhaps
	open TOGGLER "toggler toggle commands |" or die;
	@output_from_command = <TOGGLER>;


$0.02


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

Date: Mon, 17 Sep 2001 15:25:15 GMT
From: jonadab@bright.net (Jonadab the Unsightly One)
Subject: Re: Reading cookies from a different path
Message-Id: <3ba61592.13478393@news.bright.net>

mjd@plover.com (Mark Jason Dominus) wrote:

> @P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
> @p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
> ($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
> close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print

Modification of a read-only value attempted at temp.pl line 3.
Modification of a read-only value attempted at temp.pl line 3.
Modification of a read-only value attempted at temp.pl line 3.
Modification of a read-only value attempted at temp.pl line 3.
Modification of a read-only value attempted at temp.pl line 3.

- jonadab


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

Date: Mon, 17 Sep 2001 14:58:12 GMT
From: jonadab@bright.net (Jonadab the Unsightly One)
Subject: Re: recognize MS Windows with perl
Message-Id: <3ba60f11.11813358@news.bright.net>

"Zachary Kent" <zkent@adelphia.net> wrote:

> Don't Laugh....
> 
> <ducking>I use  if (-e '\autoexec.bat') to distinguish my Win95 development
> machine from my Unix server.</ducking>

To distinguish two known systems, you can use *any* flag file
that happens to exist on one and not the other, or an environment
variable.  The OP was looking for a way to distinguish Windows
systems in general from other kinds of systems.  

- jonadab


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

Date: 17 Sep 2001 10:29:02 -0700
From: schaefer@pdtec.de (Marc Schaefer)
Subject: Regexp Questions
Message-Id: <388a211a.0109170929.60ecd5e7@posting.google.com>

Hello everybody,
i've a String, for example

#22 = X_DOC_DAT(1281825423, 1, 0, 101, 999, '22-AUG-01', '22-AUG-01',
'ddr', '82039100', '0', '000', '100101', 'X3D_MODEL', 'S1', $,
'BUEGEL, LORDOSE', $, 0, 1, 'KRC_STD', 1550, $, $, '10-JAN-01',
'01-JAN-00', $, 'y', $, $, $, $, 'S', '08', $, 212457, '82039100      
    +000+S1+S+ S+08+BOH+BUEGEL, LORDOSE         +100101',
'EFTD_AKTUELL_EDBKL', 'KRCNORM15', $, $, 'CATIA_4.2.2', '818644',
1882953024, $);

I need to get the data between the 34 and 35 comma. Up to now i did a

$field = (split /,/, $line)[35];

where $line contains the string mentioned above.

Now i realized, that sometimes there are commas in the data (right
after BUEGEL)so in the end i get not what i want.

My question is: How can i get the String between the 34 and 35 comma
without counting the commas in the strings?

Thank you in advance, i know solution will be easy but I'm new to
regexp and reading the faq's and manuals have not showed my the hint i
needed to do it myself.

Marc Schaefer


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

Date: Mon, 17 Sep 2001 18:03:34 GMT
From: Markus Laire <markus.laire@usa.net>
Subject: Re: Regexp Questions
Message-Id: <Xns911FD63A6A319markuslaire@192.89.123.233>

schaefer@pdtec.de (Marc Schaefer) wrote in
news:388a211a.0109170929.60ecd5e7@posting.google.com: 

> My question is: How can i get the String between the 34 and 35 comma 
> without counting the commas in the strings? 

This is explained in perlfaq4:

How can I split a [character] delimited string except when inside
[character]? (Comma-separated files) 

Take the example case of trying to split a string that is comma-separated
into its different fields. (We'll pretend you said comma-separated, not
comma-delimited, which is different and almost never what you mean.) You
can't use split(/,/) because you shouldn't split if the comma is inside
quotes. For example, take a data line like this: 

SAR001,"","Cimetrix, Inc","Bob Smith","CAM",N,8,1,0,7,"Error, Core
Dumped" 

Due to the restriction of the quotes, this is a fairly complex problem.
Thankfully, we have Jeffrey Friedl, author of a highly recommended book
on regular expressions, to handle these for us. He suggests (assuming
your string is contained in $text): 

@new = (); 
     push(@new, $+) while $text =~ m{ 
         "([^\"\\]*(?:\\.[^\"\\]*)*)",?  # groups the phrase inside the
         quotes 
       | ([^,]+),? , 
     }gx; push(@new, undef) if substr($text,-1,1) eq ','; 

If you want to represent quotation marks inside a
quotation-mark-delimited field, escape them with backslashes (eg, "like
\"this\"". Unescaping them is a task addressed earlier in this section. 

Alternatively, the Text::ParseWords module (part of the standard Perl
distribution) lets you say: 

use Text::ParseWords; 
    @new = quotewords(",", 0, $text); 

There's also a Text::CSV (Comma-Separated Values) module on CPAN. 



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

Date: 17 Sep 2001 10:57:00 -0400
From: Alicia <alicia090677@hotmail.com>
Subject: Simple CGI: how to set up downloads?
Message-Id: <9o52vs$9ps$1@panix3.panix.com>




How does one implement file downloads (i.e. from server to client) in
a CGI script?

I'm trying to avoid FTP; so I'm most interested in HTTP transfers.  I
looked at the HTML source of a page that offers file downloads, and
the links for these downloads look like this:

  <a href="../code/somefile.gz">Download somefile!</a>

When I tried something like it, clicking on the link just sent the
user to a page of gibberish (i.e. the binary code for somefile.gz), so
there's more to it than this, but I haven't been able to find it.

Where can I read more on implementing file downloads?

Thanks!

ali



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

Date: Tue, 18 Sep 2001 05:03:02 +0100
From: "W K" <bill.kemp@wire2.com>
Subject: Re: Simple CGI: how to set up downloads?
Message-Id: <l9pp7.711$t97.8658@news.uk.colt.net>

> How does one implement file downloads (i.e. from server to client) in
> a CGI script?
> I'm trying to avoid FTP; so I'm most interested in HTTP transfers.  I
> looked at the HTML source of a page that offers file downloads, and
> the links for these downloads look like this:
>
>   <a href="../code/somefile.gz">Download somefile!</a>
>
> When I tried something like it, clicking on the link just sent the
> user to a page of gibberish (i.e. the binary code for somefile.gz), so
> there's more to it than this, but I haven't been able to find it.
>
> Where can I read more on implementing file downloads?

Your information doesn't seem to say anything about perl or even CGI.
The above seems to be just a html question (unless somefile.gz is the name
of a perl script).
In which case its the configuration of the server that needs sorting out.

If you want perl code to send a binary its something along the lines of-
Instead of: print "Content-type: text/html\n\n";
use  :   print "Content-type: application/octet-stream\n\n";

(note I haven't tested this, but at least it sets you off on the right path)
Something to note though, if IE recognises the file format it does what it
likes.





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

Date: Mon, 17 Sep 2001 18:04:07 +0200
From: "Dr. Peter Dintelmann" <Peter.Dintelmann@dresdner-bank.com>
Subject: Re: Simple CGI: how to set up downloads?
Message-Id: <9o56aa$4cq2@news-1.bank.dresdner.net>

    Hi,

"Alicia" <alicia090677@hotmail.com> wrote in message
news:9o52vs$9ps$1@panix3.panix.com...

    [anip]

> the links for these downloads look like this:
>
>   <a href="../code/somefile.gz">Download somefile!</a>
>
> When I tried something like it, clicking on the link just sent the
> user to a page of gibberish (i.e. the binary code for somefile.gz), so
> there's more to it than this, but I haven't been able to find it.
>
> Where can I read more on implementing file downloads?

    in RFC 2616

    This has nothing to do with Perl.

    Your webserver simply needs to send the correct HTTP headers, e.g.

        Content-type: application/octet-stream
        Content-Disposition: attachment; filename="test.gz"

    Good luck,

        Peter Dintelmann





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

Date: Mon, 17 Sep 2001 16:01:26 -0000
From: Greg Bacon <gbacon@cs.uah.edu>
Subject: Statistics for comp.lang.perl.misc
Message-Id: <tqc7im860s7333@corp.supernews.com>

Following is a summary of articles spanning a 7 day period,
beginning at 10 Sep 2001 16:41:10 GMT and ending at
17 Sep 2001 15:24:52 GMT.

Notes
=====

    - A line in the body of a post is considered to be original if it
      does *not* match the regular expression /^\s{0,3}(?:>|:|\S+>|\+\+)/.
    - All text after the last cut line (/^-- $/) in the body is
      considered to be the author's signature.
    - The scanner prefers the Reply-To: header over the From: header
      in determining the "real" email address and name.
    - Original Content Rating (OCR) is the ratio of the original content
      volume to the total body volume.
    - Find the News-Scan distribution on the CPAN!
      <URL:http://www.perl.com/CPAN/modules/by-module/News/>
    - Please send all comments to Greg Bacon <gbacon@cs.uah.edu>.
    - Copyright (c) 2001 Greg Bacon.
      Verbatim copying and redistribution is permitted without royalty;
      alteration is not permitted.  Redistribution and/or use for any
      commercial purpose is prohibited.

Excluded Posters
================

perlfaq-suggestions\@(?:.*\.)?perl\.com
faq\@(?:.*\.)?denver\.pm\.org

Totals
======

Posters:  275
Articles: 836 (352 with cutlined signatures)
Threads:  256
Volume generated: 1543.2 kb
    - headers:    692.5 kb (13,496 lines)
    - bodies:     795.9 kb (26,365 lines)
    - original:   506.3 kb (18,169 lines)
    - signatures: 54.0 kb (1,032 lines)

Original Content Rating: 0.636

Averages
========

Posts per poster: 3.0
    median: 1 post
    mode:   1 post - 147 posters
    s:      5.1 posts
Posts per thread: 3.3
    median: 3.0 posts
    mode:   1 post - 70 threads
    s:      3.4 posts
Message size: 1890.3 bytes
    - header:     848.2 bytes (16.1 lines)
    - body:       974.9 bytes (31.5 lines)
    - original:   620.1 bytes (21.7 lines)
    - signature:  66.2 bytes (1.2 lines)

Top 10 Posters by Number of Posts
=================================

         (kb)   (kb)  (kb)  (kb)
Posts  Volume (  hdr/ body/ orig)  Address
-----  --------------------------  -------

   44   106.3 ( 49.1/ 51.2/ 37.8)  tadmc@augustmail.com
   38    73.4 ( 32.9/ 31.0/ 20.6)  =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
   27    40.5 ( 23.5/ 16.8/  9.6)  Bart Lateur <bart.lateur@skynet.be>
   27    53.9 ( 22.1/ 30.3/ 14.8)  Benjamin Goldberg <goldbb2@earthlink.net>
   25    55.8 ( 21.6/ 29.1/ 18.3)  mgjv@tradingpost.com.au
   19    30.6 ( 14.3/ 16.3/  6.9)  Anno Siegel <anno4000@lublin.zrz.tu-berlin.de>
   17    32.5 ( 10.7/ 21.8/ 12.5)  Malcolm Dew-Jones <yf110@vtn1.victoria.tc.ca>
   16    21.9 (  9.2/ 12.6/  7.0)  gnarinn@hotmail.com
   13    32.4 ( 11.3/ 17.7/ 10.1)  Damian James <damian@qimr.edu.au>
   13    30.7 ( 11.4/ 15.3/ 12.3)  Mark Jason Dominus <mjd@plover.com>

These posters accounted for 28.6% of all articles.

Top 10 Posters by Volume
========================

  (kb)   (kb)  (kb)  (kb)
Volume (  hdr/ body/ orig)  Posts  Address
--------------------------  -----  -------

 106.3 ( 49.1/ 51.2/ 37.8)     44  tadmc@augustmail.com
  73.4 ( 32.9/ 31.0/ 20.6)     38  =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
  55.8 ( 21.6/ 29.1/ 18.3)     25  mgjv@tradingpost.com.au
  53.9 ( 22.1/ 30.3/ 14.8)     27  Benjamin Goldberg <goldbb2@earthlink.net>
  40.5 ( 23.5/ 16.8/  9.6)     27  Bart Lateur <bart.lateur@skynet.be>
  32.5 ( 10.7/ 21.8/ 12.5)     17  Malcolm Dew-Jones <yf110@vtn1.victoria.tc.ca>
  32.4 ( 11.3/ 17.7/ 10.1)     13  Damian James <damian@qimr.edu.au>
  30.7 ( 11.4/ 15.3/ 12.3)     13  Mark Jason Dominus <mjd@plover.com>
  30.6 ( 14.3/ 16.3/  6.9)     19  Anno Siegel <anno4000@lublin.zrz.tu-berlin.de>
  30.0 (  7.8/ 22.2/ 20.2)     11  Stan Brown <stanb@panix.com>

These posters accounted for 31.5% of the total volume.

Top 10 Posters by OCR (minimum of five posts)
==============================================

         (kb)    (kb)
OCR      orig /  body  Posts  Address
-----  --------------  -----  -------

0.908  ( 20.2 / 22.2)     11  Stan Brown <stanb@panix.com>
0.895  (  4.9 /  5.5)      5  * Tong * <sun_tong@users.sourceforge.net>
0.879  (  3.8 /  4.3)      6  peter pilsl <pilsl_@goldfisch.at>
0.802  ( 12.3 / 15.3)     13  Mark Jason Dominus <mjd@plover.com>
0.797  (  7.1 /  8.9)      6  "Wyzelli" <wyzelli@yahoo.com>
0.750  (  4.1 /  5.5)      8  Jonadab the Unsightly One <jonadab@bright.net>
0.738  (  2.7 /  3.7)      5  Bravan Dahn <unspecified@location.com>
0.737  ( 37.8 / 51.2)     44  tadmc@augustmail.com
0.671  (  6.2 /  9.2)     11  Dave Tweed <dtweed@acm.org>
0.666  ( 20.6 / 31.0)     38  =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>

Bottom 10 Posters by OCR (minimum of five posts)
=================================================

         (kb)    (kb)
OCR      orig /  body  Posts  Address
-----  --------------  -----  -------

0.488  ( 14.8 / 30.3)     27  Benjamin Goldberg <goldbb2@earthlink.net>
0.448  (  2.0 /  4.5)      7  "Tintin" <tintin@snowy.calculus>
0.431  (  2.5 /  5.7)      6  Uri Guttman <uri@sysarch.com>
0.427  (  7.1 / 16.7)     12  Bob Walton <bwalton@rochester.rr.com>
0.426  (  6.9 / 16.3)     19  Anno Siegel <anno4000@lublin.zrz.tu-berlin.de>
0.404  (  1.9 /  4.7)      9  John J. Trammell <trammell@haqq.hypersloth.invalid>
0.357  (  4.4 / 12.2)      9  Ken Laird <kenlaird@yahoo.com>
0.340  (  3.4 /  9.9)      6  "David Hilsee" <davidhilseenews@yahoo.com>
0.293  (  1.5 /  5.2)      5  "Admin UsePad" <spam@funnybytes.com>
0.212  (  1.8 /  8.7)      5  "B. Caligari" <bcaligari@fireforged.com>

41 posters (14%) had at least five posts.

Top 10 Threads by Number of Posts
=================================

Posts  Subject
-----  -------

   18  Perl (slurping) is TOO much fun
   12  parsing large DNA files into smaller files
   12  Do I need file locking
   11  http server validation
   11  Parsing problem (Please HELP )
   11  Discontinue the loop
   10  Running perl scripts
   10  Printing in Perl
   10  recognize MS Windows with perl
    9  Source Code Bracket Matching Utility Needed

These threads accounted for 13.6% of all articles.

Top 10 Threads by Volume
========================

  (kb)   (kb)  (kb)  (kb)
Volume (  hdr/ body/ orig)  Posts  Subject
--------------------------  -----  -------

  40.9 ( 17.8/ 20.8/ 11.2)     18  Perl (slurping) is TOO much fun
  30.2 (  7.6/ 21.5/ 13.9)      9  PERL modules and GPL license
  25.2 (  6.6/ 17.9/  7.8)      8  Mail parser: Can it be faster?
  22.9 (  9.1/ 13.6/  5.7)     11  Parsing problem (Please HELP )
  22.7 ( 10.5/ 11.0/  6.5)     12  parsing large DNA files into smaller files
  21.5 (  8.1/ 12.7/  8.0)     10  Running perl scripts
  20.4 ( 10.0/  9.3/  4.8)     12  Do I need file locking
  17.5 (  5.8/ 11.4/  6.1)      7  embedding variables in an array
  17.4 (  6.2/ 11.0/  6.2)      7  What is package?
  17.4 (  1.0/ 16.3/ 16.3)      1  Posting Guidelines for comp.lang.perl.misc ($Revision: 1.2 $)

These threads accounted for 15.3% of the total volume.

Top 10 Threads by OCR (minimum of five posts)
==============================================

         (kb)    (kb)
OCR      orig /  body  Posts  Subject
-----  --------------  -----  -------

0.867  (  9.1/  10.5)      5  Really bizzare syntax error
0.844  (  2.8/   3.3)      6  Using Perl to post regular usenet messages.
0.817  (  3.0/   3.6)      6  passwd and perl
0.814  (  6.4/   7.9)      9  Similar file finder
0.735  (  2.9/   4.0)      5  print name of var
0.727  (  3.0/   4.1)      6  Using the c preprocessor for non c purposes
0.719  (  3.5/   4.8)      6  start a script when a process exits
0.705  (  2.9/   4.1)      5  Q: When to use eval for calling object subroutines?
0.702  (  2.0/   2.8)      6  mysql connection.
0.689  (  3.2/   4.7)      5  Can't fork on certain computers?

Bottom 10 Threads by OCR (minimum of five posts)
=================================================

         (kb)    (kb)
OCR      orig /  body  Posts  Subject
-----  --------------  -----  -------

0.476  (  2.1 /  4.5)      6  Recommendations for a PERL editor
0.472  (  2.0 /  4.3)      5  Perl is TOO much fun
0.461  (  2.1 /  4.5)      6  debug CGI script
0.458  (  4.1 /  8.8)      7  Help: TiedHash.pm module in @INC not being recognized
0.439  (  2.4 /  5.4)      5  File Upload CGI - Mac issue
0.437  (  7.8 / 17.9)      8  Mail parser: Can it be faster?
0.423  (  5.7 / 13.6)     11  Parsing problem (Please HELP )
0.422  (  2.6 /  6.2)     11  Discontinue the loop
0.300  (  2.1 /  6.9)      6  Problem with parsing more than one line ( Please HELP )
0.280  (  2.3 /  8.1)      5  Why the client still waits for input?

56 threads (21%) had at least five posts.

Top 10 Targets for Crossposts
=============================

Articles  Newsgroup
--------  ---------

      14  alt.perl
       9  comp.unix.programmer
       6  comp.lang.c
       6  comp.lang.perl.modules
       5  alt.perl.sockets
       4  comp.security.misc
       4  de.comp.lang.perl.misc
       4  comp.lang.java.programmer
       4  alt.ecommerce
       4  alt.www.webmaster

Top 10 Crossposters
===================

Articles  Address
--------  -------

       5  Malcolm Dew-Jones <yf110@vtn1.victoria.tc.ca>
       4  "Jay Flaherty" <fty@mediapulse.com>
       4  Robert Kattke <invinfo@enteract.com>
       4  Benjamin Goldberg <goldbb2@earthlink.net>
       4  "Alexander Farber (EED)" <eedalf@eed.ericsson.se>
       4  * Tong * <sun_tong@users.sourceforge.net>
       4  Joe Smith <inwap@best.com>
       4  "Gerry White" <ultradevusegrp@dergal.com>
       4  "M.L." <mel2000@hotmaildot.com>
       4  "Paul" <whamera@home.com>


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.  

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 V10 Issue 1761
***************************************


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