[22948] in Perl-Users-Digest
Perl-Users Digest, Issue: 5168 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 2 11:11:07 2003
Date: Wed, 2 Jul 2003 08: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)
Perl-Users Digest Wed, 2 Jul 2003 Volume: 10 Number: 5168
Today's topics:
Perl help needed (Saya)
Re: Perl help needed <bernard.el-hagin@DODGE_THISlido-tech.net>
Perl-CGI: Return HTML and then a file problem <jon.rogers@tv.tu>
Re: Perl-CGI: Return HTML and then a file problem <flavell@mail.cern.ch>
Re: Perl-CGI: Return HTML and then a file problem <zak@mighty.co.za>
pipe - non blocking read? (fork/Win32) <stjm2@hermes.cam.ac.uk>
Re: Regular Expression Problem <abigail@abigail.nl>
Re: SHIFT not shuffling ? <asu1@c-o-r-n-e-l-l.edu>
test, pls ignore <shtil@comcast.net>
Using Win32::API To call CreateProcess - help! <dont@want.spam>
Re: XS question -- avoid memory leak <kalinabears@hdc.com.au>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 2 Jul 2003 06:44:10 -0700
From: vahu@novonordisk.com (Saya)
Subject: Perl help needed
Message-Id: <9e9517bf.0307020544.25175439@posting.google.com>
Hi,
I am a newbie to perl and regular expressions.
I need help with extracting a substring.
Presume:
$test = "thisIsATest(12)";
$subPar = should equal to (12)
$num = should equal to 12
How do I achieve this in perl ? Do I use regular expression ?
Any help would be appreciated.
------------------------------
Date: Wed, 2 Jul 2003 13:50:13 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: Perl help needed
Message-Id: <Xns93ACA0AC5A64Celhber1lidotechnet@62.89.127.66>
Saya wrote:
> Hi,
>
> I am a newbie to perl and regular expressions.
Start by reading:
perldoc perlretut
and with coming up with better Subjects.
> I need help with extracting a substring.
> Presume:
> $test = "thisIsATest(12)";
> $subPar = should equal to (12)
> $num = should equal to 12
>
> How do I achieve this in perl ? Do I use regular expression ?
You don't give too much information on the criteria for matching. For your
example the following is good enough:
$num = $1 if $test =~ m/\((\d+)\)/;
$subPar = "($num)";
but this may not be what you want for your real data.
--
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: Wed, 02 Jul 2003 16:27:02 +0200
From: jon rogers <jon.rogers@tv.tu>
Subject: Perl-CGI: Return HTML and then a file problem
Message-Id: <bdupdm$urd$2@news.gu.se>
Hi
I run a couple of Perl-CGIs under the latest Apache on my Red Hat box. I
have now come across a problem.
From my script, I'd first like to return some HTML lines:
print "Content-Type: text/html\n\n<html><head><title>The TinyBox
pages</title>\n";
etc.
Then I'd like to return a file:
print "Content-Type:application/octet-stream
Content-Disposition:attachment; filename=results.apl
Content-Length:$content_length\n\n";
However, it seems that I cannot print
Content-Type:application/octet-stream after I have printed
Content-Type: text/html ; the file just gets printed to screen, instead of
the browser opening a file save requester.
Is there some way of "resetting" the Content-Type: string sent to Apache, or
some other way around the problem?
Thanks for your time,
JR
------------------------------
Date: Wed, 2 Jul 2003 16:41:14 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Perl-CGI: Return HTML and then a file problem
Message-Id: <Pine.LNX.4.53.0307021636540.19732@lxplus014.cern.ch>
On Wed, Jul 2, jon rogers inscribed on the eternal scroll:
> From my script, I'd first like to return some HTML lines:
>
> print "Content-Type: text/html\n\n<html><head><title>The TinyBox
> pages</title>\n";
>
> etc.
>
> Then I'd like to return a file:
This question seems kind-of familiar. Didn't I see it being answered
just moments ago somewhere else? Yup, here we have it:
comp.infosystems.www.servers.unix
What led you to suppose that there was something Perl-specific about
it? The principles would be the same if you were writing your
server-side script in COBOL or FORTRAN or something.
------------------------------
Date: Wed, 02 Jul 2003 16:50:33 +0200
From: Zak McGregor <zak@mighty.co.za>
Subject: Re: Perl-CGI: Return HTML and then a file problem
Message-Id: <bdurch$h50$1@ctb-nnrp2.saix.net>
On Wed, 02 Jul 2003 16:27:02 +0200, jon rogers <"jon rogers"
<jon.rogers@tv.tu>> wrote:
Hi
> Is there some way of "resetting" the Content-Type: string sent to
> Apache, or some other way around the problem?
Not a perl question. Ask in comp.infosystems.www.authoring.cgi or
somewhere else relevant to server-side http issues. But the short answer
is "No".
Ciao
Zak
--
========================================================================
http://www.carfolio.com/ Searchable database of 10 000+ car specs
========================================================================
------------------------------
Date: Wed, 2 Jul 2003 15:46:32 +0100
From: Stuart Moore <stjm2@hermes.cam.ac.uk>
Subject: pipe - non blocking read? (fork/Win32)
Message-Id: <Pine.SOL.4.44.0307021543450.9290-100000@red.csi.cam.ac.uk>
Hi, I'm using windows, I want to create a new process using fork (in
Activestate's Perl 5.6.x for some x) and communicate between the parent
and child using pipes. But I'd like the parent to be able to check if
there was anything waiting for it in the pipe, and if not, come back and
check later.
Is this possible? If not any suggestions on what I can do?
Stuart
------------------------------
Date: 02 Jul 2003 11:38:06 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Regular Expression Problem
Message-Id: <slrnbg5h0t.khe.abigail@alexandra.abigail.nl>
Kenneth Baltrinic (kenneth@baltrinic.com) wrote on MMMDXCII September
MCMXCIII in <URL:news:ogtMa.8784$Hw.6276188@news2.news.adelphia.net>:
$$ I am trying to parse a relatively simple SQL query with a regular
$$ expression. All is going well except for one issue I don't seem to be able
$$ to find a solution for. Handling optional parentheses and brackets. This
$$ seems like a back reference problem to me but I am not sure. Let me give a
$$ simple example.
$$
$$ An table name might be enclosed in brackets or it might not. For the sake of
$$ simplification, lets assume that the pattern [A-Za-z_]+ is what we are
$$ looking for in a table name. A really simple solution to find table names
$$ that are bracket enclosed or not would as follows:
$$
$$ /(\[[A-Za-z_]+\])|([A-Za-z_]+)/
$$
$$ The problem is that the pattern for a table name is not in reality as simple
$$ as [A-Za-z_]+ . In fact it is quite long, and repeating it twice in the
$$ expression seems inefficient not to mention prone to bugs if I need to tweak
$$ it and don't get each side exactly the same. What I want to do is something
$$ like the following:
$$
$$ /(\[?)[A-Za-z_]+\1/
$$
$$ This almost works except of course that my backreference is looking for an
$$ opening bracket [ when I need it to be looking for a closing bracket ]. So
$$ here it the crux of my question. Is there any way to do something like
$$ this--to have a backreference that does some sort of fuzzy match? I have a
$$ similar issues with parentheses.
Use the (??{ }) construct:
/(\[?)[A-Za-z_]+(??{$1 ? "]" : ""})/
Abigail
--
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(
HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (
LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET",
"http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content))
=~ /(.*\))[-\s]+Addition/s) [0]'
------------------------------
Date: 2 Jul 2003 12:17:27 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: SHIFT not shuffling ?
Message-Id: <Xns93AC5457FC39Fasu1cornelledu@132.236.56.8>
sholden@flexal.cs.usyd.edu.au (Sam Holden) wrote in
news:slrnbg54uh.6ro.sholden@flexal.cs.usyd.edu.au:
> On Wed, 02 Jul 2003 08:02:19 GMT, Owen <Not_Me@pcug.org.au> wrote:
>> On 30 Jun 2003 18:09:40 GMT
>> "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu> wrote:
>>
>>> my @a = qw(one two three four five six);
>>>
>>> while(my $a = shift @a) {
>>> print "$a\n" ;
>>> }
>>
>> Is there some subtle reason for the "my" in the while loop?
>
> To limit the scope of the variable.
>
> Not that I'd use $a or $b (even my'd versions of them) in anything
> but a sort comparison function, but that's a different matter...
You are right. I used the names the OP was using without thinking about it
at all. Thanks for pointing that out.
Sinan.
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: Wed, 02 Jul 2003 14:21:51 GMT
From: "Yuri Shtil" <shtil@comcast.net>
Subject: test, pls ignore
Message-Id: <3UBMa.18176$926.1334@sccrnsc03>
------------------------------
Date: Wed, 02 Jul 2003 13:47:26 +0100
From: Chris Lowth <dont@want.spam>
Subject: Using Win32::API To call CreateProcess - help!
Message-Id: <yvAMa.1017$ju6.8993@newsfep4-glfd.server.ntli.net>
I need to call the "real" CreateProcess of windows NT from an ActiveState
perl script. The code below always reports a return of 0 (FALSE) and fails
to start "notepad". Where as the matching C code (also listed) works fine.
I cant see what's wrong myself - has anyone got this to work, and if so -
can you see what is wrong with the script?
---------- perl --------------
[ This doesnt work ]
use Win32::API;
Win32::API::Struct->typedef( "STARTUPINFO", qw(
DWORD cb;
LPTSTR lpReserved;
LPTSTR lpDesktop;
LPTSTR lpTitle;
DWORD dwX;
DWORD dwY;
DWORD dwXSize;
DWORD dwYSize;
DWORD dwXCountChars;
DWORD dwYCountChars;
DWORD dwFillAttribute;
DWORD dwFlags;
WORD wShowWindow;
WORD cbReserved2;
LPBYTE lpReserved2;
HANDLE hStdInput;
HANDLE hStdOutput;
HANDLE hStdError;
) );
Win32::API::Struct->typedef( "PROCESS_INFORMATION", qw(
HANDLE hProcess;
HANDLE hThread;
DWORD dwProcessId;
DWORD dwThreadId;
) );
my $CreateProcess = Win32::API->new( "kernel32", "
BOOL CreateProcess(
LPCTSTR lpApplicationName,
LPTSTR lpCommandLine,
LPVOID lpProcessAttributes,
LPVOID lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCTSTR lpCurrentDirectiry,
LPSTARTUPINFO lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation
)");
$cmd = "c:\\winnt\\notepad.exe";
$dir = ".";
my $si = Win32::API::Struct->new( "STARTUPINFO" );
my $pi = Win32::API::Struct->new( "PROCESS_INFORMATION" );
$rtn = $CreateProcess->Call(undef, $cmd, undef, undef, 0, 0, undef, $dir,
$si, $pi);
print "rtn = $rtn\n";
------------- and now in C -------------------
[ This works ]
#include <windows.h>
void ErrorExit( char *str )
{
printf("ERROR: %s\n", str);
exit(2);
}
void main( VOID )
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
// Start the child process.
if( !CreateProcess( NULL, // No module name (use command line).
"c:\\winnt\\notepad.exe", // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
)
{
ErrorExit( "CreateProcess failed." );
}
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
--
Real address: chris at lowth dot sea oh em.
World's first wrist-watch PDA with Palm OS, available June 30
from Amazon.com. Order now to beat the rush!
http://www.lowth.com/shop/wrist_pda
------------------------------
Date: Wed, 2 Jul 2003 21:17:43 +1000
From: "Sisyphus" <kalinabears@hdc.com.au>
Subject: Re: XS question -- avoid memory leak
Message-Id: <3f02c098$0$22125@echo-01.iinet.net.au>
"Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote in message
news:Xns93AC3D2FBFA11sdn.comcast@206.127.4.25...
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
>
> I've used XS for a few small projects over the years, so I'm familiar with
> it but by no means am an expert. The current situation I find myself in
is
> as follows.
>
> My routine needs to return a string whose length is arbitrarily variable
> based on its input parameters. What I plan to do is to decide how big the
> output string will be, malloc it, and return a char * pointer to it. But
> this sounds suspiciously like a memory leak, since my code will not ever
> get the chance to free() it.
>
> Will perl automatically free the memory pointed to by an SV created by the
> XS layer as it converts a char* pointer? I don't see how it could -- how
> could it know that it was created with malloc, or that nothing else points
> to it? How can I solve this problem?
>
Have your function return an SV* instead of a char*.
SV * your_func () {
char * string;
SV * outsv;
Copy the contents of 'string' into 'outsv'.
outsv = newSVpv(string, 0);
Then free() 'string' and return 'outsv':
free(string);
return outsv;
You've now freed the memory you allocated and because the string has been
copied into an SV, it has thus becomes perl's responsibility.
I think you're correct - returning the char * would mean that the memory you
allocated would not get freed until the program exits.
Cheers,
Rob
------------------------------
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 5168
***************************************