[22109] in Perl-Users-Digest
Perl-Users Digest, Issue: 4331 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 1 18:05:42 2003
Date: Wed, 1 Jan 2003 15:05:07 -0800 (PST)
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, 1 Jan 2003 Volume: 10 Number: 4331
Today's topics:
Re: Cookies, forms, and LWP? <nobody@dev.null>
Re: Direct Shared Memory Mapping? <gordan@_NOSPAM_bobich.net>
Re: Direct Shared Memory Mapping? <goldbb2@earthlink.net>
Re: embeding perl / getting results (Anno Siegel)
Re: embeding perl / getting results <pa@panix.com>
Re: embeding perl / getting results (=?ISO-8859-1?Q?Hans_Schl=FCter?=)
Re: Freebsd memory leak. <goldbb2@earthlink.net>
Re: How can I comment out a large block of perl code? <kasp@NO_SPAMepatra.com>
Re: How can I comment out a large block of perl code? <bart.lateur@pandora.be>
Re: how to load a module depending on 'if' condition ? <murat.uenalan@gmx.de>
need help for regular expression <sarath.chandra@uaeexchange.com>
Re: need help for regular expression <mbudash@sonic.net>
Re: need help for regular expression <mbudash@sonic.net>
Re: need help for regular expression <kasp@NO_SPAMepatra.com>
Re: need help for regular expression <bongie@gmx.net>
Re: need help for regular expression <wksmith@optonline.net>
Re: Perl Tutorials <yanoff@yahoo.com>
Re: pod 2 info? <ryan@cardweb.com>
system command and $_ variable (juha)
Re: system command and $_ variable <ian@WINDOZEdigiserv.net>
Re: system command and $_ variable <goldbb2@earthlink.net>
Re: system command and $_ variable <bart.lateur@pandora.be>
Re: Using perl to captuer IP of person submitting a for <photos@agileemmy.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 01 Jan 2003 14:11:45 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: Cookies, forms, and LWP?
Message-Id: <3E12F65F.5040800@dev.null>
> I am using LWP::UserAgent in a script on my site (let's call it A.com) to
> POST form data to a third-party site (let's call it B.com), and print the
> result to the user's browser. Great. That's all fine.
> The problem is, B.com generates a cookie(s) for the user after the form data
> is submitted.
> I need to give this cookie(s) to the user.
> I could get the header data and print it out, but that would only give them
> a cookie from A.com.
> I could use the cookie_jar but that doesn't appear to do what I need.
> How do I give the user the "real" cookie from B.com when I'm printing the
> form results from a script?
This is really not a Perl issue. If the user is latched on to your A.com
and you give them a cookie, then, from the user's perspective it's a
cookie from A.com, regardless of the fact that you obtained the data in
the cookie from B.com. If the user is using a well-designed browser, you
will not be able to dupe it into believing that the cookie came from
B.com when in fact it came from A.com. This is a feature (not a bug) of
the cookie scheme: the bad guys can't plant cookies on my machine and
pretend those cookies came from the good guys.
------------------------------
Date: Wed, 01 Jan 2003 15:55:26 +0000
From: Gordan <gordan@_NOSPAM_bobich.net>
Subject: Re: Direct Shared Memory Mapping?
Message-Id: <_bEQ9.5410$kS.276684@newsfep2-win.server.ntli.net>
Benjamin Goldberg wrote:
>> >> Is there a way to get something mapped directly into shared memory,
>> >> and then access it efficiently via, say, a pointer in Perl?
>> >
>> > Perl doesn't have pointers.
>> >
>> > It has scalars, hashes, and arrays.
>>
>> I'm talking about passing by reference, i.e. Function(\%Hash). So if
>> content of the shared memory was fitting the structure of a hash, then
>> I was hoping I could pass it by reference and thus avoid the overhead
>> of the fetch->thaw->change->freeze->store by having the data structure
>> physically only mapped in the shared memory.
>
> When you add data to or change elements of a hash or array, or lengthen
> a string, there is a good chance that memory allocation will take
> place. To make a "normal" hash or array sit in shared memory, you would
> need to hijack perl's malloc if called within your particular hash or
> array, so that it allocates from a seperate memory pool instead of
> wherever it normally gets bytes from.
>
> This simply isn't practical to do.
I understand what you are saying. I was actually referring to the case where
you allocate a large chunk of shared memory (e.g. 4 MB) for a particular
hash to sit in, and be limited to that size. But either way, this now gets
FAR too complicated, so we might as well drop this part of the thread
anyway.
> [snip]
[shared memory allocation for hashes and variable length string arrays
snipped]
>> >> What I am really looking for is a way to map a piece of shared
>> >> memory, and then manipulate it as a hash, and/or an array/list
>> >> WITHOUT copying the contents into a local, unshared variable.
>> >
>> > Err, manipulate how? And an hash/array/list of what?
>>
>> Very basic stuff. Find out $#List, push and shift.
>
> If you *only* wanted $#List, and push, and *pop*, then 'twould be
> simple. But shift() requires removing stuff from the *front*, which
> isn't so simple.
Hence my earlier suggestion of mapping each element into a separate shared
memory segment, and treating the whole thing as a list, rather than an
array. In practice, though, there is no reason why pop() couldn't be used
instead of shift() for my problem.
> Are you absolutely certain that what you want is a shared *array* (which
> implies accessing arbitrary elements), not, e.g., some sort of shared
> *queue* (remove from front, add to end, test if empty; nothing else)?
That's about it, yes. A queue is probably the closest approximation,
although a stack would do just as well. But I would need to check the size,
because sometimes multiple elements may need to be added/removed at the
same time, i.e. not just a simple "empty" check.
> If it is a queue, then do you ever need to examine (some of) the
> elements of it without removing those elements? If *not*, then I would
> suggest using a pipe (either from the pipe() function, or a named pipe
> made by mkfifo or mknod)
There's an idea. I'll look into that. Thanks. :-)
And no, I never need to check the elements without removing them first. Once
they are removed, they are either acted upon (retrieve this site), or just
thrown away (site doesn't match a search pattern).
>> Also checking and setting $Hash{"Key"}.
>
> Does the set of keys that %Hash has ever change?
It would change constantly, as the main use I have is for checking whether a
page has already been retrieved, i.e.
unless ($Visited{$URL})
{
Retrieve($URL);
$Visited{$URL} = 1;
}
> Are the values of %Hash fixed length, or variable length?
Almost always variable length. :-(
> [snip]
>> >> avoiding the lock->fetch->change->write->unlock process on
>> >> the ENTIRE memory segment. I guess I could map EACH element of an
>> >> array into a SEPARATE segment, and store pointers/keys into a list,
>> >> so only that list segment has to be completely copied in and out of
>> >> memory on each iteration, but this seems far too complicated, and
>> >> potentially wasteful for the memory, as it can only be allocated in
>> >> 4KB chunks.
>> >
>> > That would depend entirely on how you did it.
>>
>> What I mean is that in the case of a list, there is going to be the
>> equivalent of:
>>
>> $Wasted = $PAGE_SIZE % $ItemSize;
>
> Hmm... regarding this discussion, it sounds as if you're wanting a set
> of malloc/reallof/free primitives which acquire shared memory, rather
> than process-private memory.
I was, but after our discussion so far, I'm starting to think this is not
too practical. There seems to be a better way to do this by allocating
separate shmem chunks for each entry in the list. It also provides a nice
interface for dynamically sizing lists, as each entry is allocated
separately, and only the list of pointers is kept shared.
For the uniqueness hash, as I mentioned above, there is unlikely to be all
that much overhead in sharing it. Alternatively, even better, I could set
up some sort of an IPC where I can have a uniquness monitoring thread that
ONLY keeps track of visited URLs in it's non-shared memory, so there is no
unnecessary duplication. I could have this listening on a socket for remote
requests.
> ISTM that if you looked into glibc's
> malloc implementation, or perl's malloc implementation, you might be
> able design something along these lines.
>
> Perhaps you could write an API like:
> struct memory_arena * a = create_mmapped_arena();
> void * data = arena_malloc( a, count );
> data = arena_realloc( a, count + 5 );
> arena_free( a, data );
> Where inside of 'a' would be all of the stuff that's in the static
> variables of the malloc implementations.
Hmm... Could do, but this starts heading in the direction of using a 100 ton
weight to crack a nut.
> [snip]
>> Yup, I follow this, we just retrieve the shared memory segment where
>> the particular entry we are interested in resides. So, the memory
>> duplicated across the threads/processes is limited to the array
>> containing the pointers into shared memory, but we don't have to
>> duplicate the whole of the data content as well - only the shared
>> segment containing our data. Precisely what I meant.
>
> This is part of why I asked if the keys of the hash you're interested in
> are fixed. If so, then you could initially do:
>
> my %key_to_index;
> @key_to_index{ @array_of_keys } = 0 .. $#array_of_keys;
>
> And have that duplicated between processes -- then whenever someone does
> a hash access, you could look up the index in %key_to_index, and then do
> an *array* access in your shared array.
This could work if I pad the keys to the same length - which is not
necessarily a problem...
> [snip]
>> > It would be nice if you could give a clear explanation of your
>> > initial problem; what exactly is the problem you're trying to solve.
>>
>> Say I have a simple parallel web crawler and I need to store a list of
>> URLs. I only ever need to do 3 things on the array:
>>
>> 1) Find if ($#List > 1)
>> 2) $URL = shift(@List)
>> 3) push(@List, $URL)
>>
>> But, this needs to be shared across all crawler threads, so that the
>> load can be distributed.
>
> It sounds like you don't need a shared array here -- not in the least.
The joys of the Perl paradigm - there is always a better way to do
something. ;-)
> I would suggest is something like the following:
>
> pipe( my($reader, $writer) ) or die horribly;
> $| = 1, select $_ for select $writer;
>
> # perform forking.
>
> use Fcntl qw(:flock);
> flock( $writer, LOCK_EX ) or die horribly;
> if( -s $reader ) {
> my $len = "";
> READ_LEN: {
> sysread( $reader, $len, 4 - length($len), length($len) )
> or die horribly;
> redo READ_LEN if length($len) < 4;
> }
> $len = unpack "N", $len;
> my $url = "";
> READ_URL: {
> sysread( $reader, $url, $len - length($url), length($url) )
> or die horribly;
> redo READ_LEN if length($url) < $len;
> }
> flock( $writer, LOCK_UN ) or die horribly;
> my @urls = fetch_and_extract_urls( $url );
> flock( $writer, LOCK_EX ) or die horribly;
> foreach $url (@urls) {
> print $writer pack("N", length($url)), $url;
> }
> }
> flock( $writer, LOCK_UN ) or die horribly;
I follow. I think the pack template be Z, rather than N, seen as URLs are
strings, rather than just network addresses. But yes, I understand what You
mean. It is certainly more efficient than mucking around with the shared
memory.
> All perfectly ordinary stuff done here. The only slightly unusual
> things are the locking, which can be replaced with *any* kind of locking
> (semaphores, if you want), and using -s on the pipe (which doesn't work
> on some systems).
Yup, could just set up flags in shared memory for both if all else fails,
seen as it's only a few bytes that are needed for signalling. But I don't
really see that as a problem, and I like the flock() approach on pipes. Is
there a limit on the amount of data that can sit in a pipe waiting for
reading, other than the amount of memory on the system? Or is this a
ulimit() issue?
>> Similar approach could be used in coordinating saving of those pages,
>> by having multiple crawler bots retrieve pages, and save the content
>> into a list of content strings. A separate database thread could then
>> go through that list and save the elements one by one.
>
> Out of curiosity, what kind of database is this database thread storing
> the data into?
Just a normal SQL database. MySQL at the moment, because that's what I had
handy at the time. I'm trying to do a small, local index for the sites that
I'm hosting. I know I could leave most of it to google, but this way I can
also get a list of broken links and suchlike. I also hadn't played with
Perl threads before, so this seemed like an interesting learning exercise.
> [snip stuff for dealing with shared memory, which I've just shown is the
> entirely wrong solution for the given problem.]
Agreed. :-)
Thank you.
Gordan
------------------------------
Date: Wed, 01 Jan 2003 17:28:39 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Direct Shared Memory Mapping?
Message-Id: <3E136B96.65212614@earthlink.net>
Gordan wrote:
> Benjamin Goldberg wrote:
[snip]
> > Are you absolutely certain that what you want is a shared *array*
> > (which implies accessing arbitrary elements), not, e.g., some sort
> > of shared *queue* (remove from front, add to end, test if empty;
> > nothing else)?
>
> That's about it, yes. A queue is probably the closest approximation,
> although a stack would do just as well. But I would need to check the
> size, because sometimes multiple elements may need to be added/removed
> at the same time, i.e. not just a simple "empty" check.
>
> > If it is a queue, then do you ever need to examine (some of) the
> > elements of it without removing those elements? If *not*, then I
> > would suggest using a pipe (either from the pipe() function, or a
> > named pipe made by mkfifo or mknod)
>
> There's an idea. I'll look into that. Thanks. :-)
> And no, I never need to check the elements without removing them
> first. Once they are removed, they are either acted upon (retrieve
> this site), or just thrown away (site doesn't match a search pattern).
For efficiency, you would be better off matching them against your
search pattern before considering wether or not to put them into the
queue.
> >> Also checking and setting $Hash{"Key"}.
> >
> > Does the set of keys that %Hash has ever change?
>
> It would change constantly, as the main use I have is for checking
> whether a page has already been retrieved, i.e.
>
> unless ($Visited{$URL})
> {
> Retrieve($URL);
> $Visited{$URL} = 1;
> }
Instead of trying to share a hash, consider having *one* process keep a
hash of urls -- use a pair of pipes to communicate with it.
pipe( my ($to_hash_r, $to_hash_w) ) or die horribly;
pipe( my ($from_hash_r, $from_hash_w) ) or die horribly;
$| = 1, select $from_hash_w,
$| = 1, select $_ for select $to_hash_w;
... perform forking ...
if( $in_hash_process ) {
close $_ for $to_hash_w, $from_hash_r;
my %hash;
# tie %hash, "DB_File", ....;
while( read( $to_hash_r, my($len), 4 ) == 4 ) {
$len = unpack "N", $len;
read( $to_hash_r, my($url), $len ) == $len or die;
my $response = exists $hash{$url} ? 1 : 0;
print $from_hash_w $response;
$hash{$url} = 1 if $response == 0;
}
exit;
}
# otherwise:
close $_ for $to_hash_r, $from_hash_w;
while( my($url) = get_a_url() ) {
flock( $to_hash_w, LOCK_EX );
print $to_hash_w, pack("N/Z*", $url);
sysread( $from_hash_r, my($already), 1 ) or die;
flock( $to_hash_w, LOCK_UN );
next if $already == 1;
# process $url.
}
> > Are the values of %Hash fixed length, or variable length?
>
> Almost always variable length. :-(
From what you said before, the *values* are fixed length ("this url was
processed/not processed"), though the keys are variable length.
[snip]
> For the uniqueness hash, as I mentioned above, there is unlikely to be
> all that much overhead in sharing it.
Err, actually, for a hash for which keys are being added and removed,
then there's significantly a *higher* overhead for sharing it, than
there is for a shared array. But if IPC is used instead, as I show
above, and as you say below, then there's little/no overhead.
> Alternatively, even better, I could set up some sort of an IPC where I
> can have a uniquness monitoring thread that ONLY keeps track of
> visited URLs in it's non-shared memory, so there is no unnecessary
> duplication. I could have this listening on a socket for remote
> requests.
[snip]
> > This is part of why I asked if the keys of the hash you're
> > interested in are fixed. If so, then you could initially do:
> >
> > my %key_to_index;
> > @key_to_index{ @array_of_keys } = 0 .. $#array_of_keys;
> >
> > And have that duplicated between processes -- then whenever someone
> > does a hash access, you could look up the index in %key_to_index,
> > and then do an *array* access in your shared array.
>
> This could work if I pad the keys to the same length - which is not
> necessarily a problem...
But this only works for a fixed set of keys; for a hash for uniqueness,
this is *not* going to work.
[snip]
> I follow. I think the pack template be Z, rather than N, seen as URLs
> are strings, rather than just network addresses.
Err, the thing which was packed with N was the *lengths* of the urls.
The urls themselves were merely printed as is.
Actually, doing:
print pack("N", length($url)), $url;
Is rather a lot like doing:
print pack("N/a*", $url);
But I think there's less data copying with the former than the latter.
> But yes, I understand what You mean. It is certainly more efficient
> than mucking around with the shared memory.
Well, a hashred memory thing, if done really cleverly, and in XS, could
be made fairly efficient, but it would be *very* complicated. Using
pipes is far simpler.
> > All perfectly ordinary stuff done here. The only slightly unusual
> > things are the locking, which can be replaced with *any* kind of
> > locking (semaphores, if you want), and using -s on the pipe (which
> > doesn't work on some systems).
>
> Yup, could just set up flags in shared memory for both if all else
> fails, seen as it's only a few bytes that are needed for signalling.
Ack, no -- setting flags in shared memory wouldn't work, unless you have
an atomic test-and-set operation. Shared memory does not, by itself,
provide synchronization.
You can use flock for synchornization, or semaphores, or even a pipe
dedicated to the task (reading a byte from the dedicated pipe acquires
the lock, writing a byte to that pipe releases the lock), or any number
of other things. But you can't use shared memory alone.
> But I don't really see that as a problem, and I like the flock()
> approach on pipes. Is there a limit on the amount of data that can sit
> in a pipe waiting for reading, other than the amount of memory on the
> system?
Sadly, yes, there is a limit to the amount of data which you can have in
a pipe unread. Trying to write more than this will cause the writing
process/thread to become blocked until data is read from the reading end
of the pipe.
The solution to this is to have a dedicated process to act as the queue;
one pipe would be used to send extracted urls to this process to be
pushed on to the queue, and another to request a url to be dequeued.
This dedicated process could be combined with the one for doing the
uniqness checks.
sub sysreadn { # read a fixed length of data, without buffering.
my ($fh, $n) = @_;
my $str = "";
while( length($str) < $n ) {
sysread( $fh, $str, $n-length($str), length($str) ) or die;
}
$str;
}
pipe( my ($to_queue_r, $to_queue_w) ) or die horribly;
pipe( my ($from_queue_r, $from_queue_w) ) or die horribly;
$| = 1, select $from_queue_w,
$| = 1, select $_ for select $to_queue_w;
... perform forking ...
if( $in_queue_process ) {
close $_ for $to_queue_w, $from_queue_r;
my (%processed, @queue);
# tie %processed, "DB_File", ....;
# tie @queue, "DB_File", ....;
while( read( $to_queue_r, my($len), 4 ) == 4 ) {
$len = unpack "N", $len;
if( $len == 0 ) { # This is a request for a url
my $url = shift(@queue) || "";
$processed{$url} = 1;
print pack("N/a*", $url);
next;
} else { # This is a url to enqueue.
read( $to_queue_r, my($url), $len ) == $len or die;
push @queue, $url unless exists $processed{$url};
}
}
exit;
}
# in worker process:
close $_ for $to_queue_r, $from_queue_w;
flock( $to_queue_w, LOCK_EX );
while( 1 ) {
print $to_queue_w pack("N",0);
my $len = unpack("N", sysreadn( $from_queue_r, 4 ) );
if( $len == 0 ) {
flock( $to_queue_w, LOCK_UN );
sleep 10;
flock( $to_queue_w, LOCK_EX );
redo;
}
my $url = sysreadn( $from_queue_r, $len );
flock( $to_queue_w, LOCK_UN );
my @urls = grep length, fetch_url_and_extract_urls($url);
flock( $to_queue_w, LOCK_EX );
print $to_queue_w, pack("N/a*", $_) for @urls;
}
print $to_queue_w pack("N/Z*", $url);
sysread( $from_queue_r, my($already), 1 ) or die;
flock( $to_queue_w, LOCK_UN );
next if $already == 1;
# process $url.
}
> Or is this a ulimit() issue?
It's a limit compiled into your Operating System's kernel, and not
changable except by recompiling your OS.
> >> Similar approach could be used in coordinating saving of those
> >> pages, by having multiple crawler bots retrieve pages, and save the
> >> content into a list of content strings. A separate database thread
> >> could then go through that list and save the elements one by one.
> >
> > Out of curiosity, what kind of database is this database thread
> > storing the data into?
>
> Just a normal SQL database. MySQL at the moment, because that's what I
> had handy at the time. I'm trying to do a small, local index for the
> sites that I'm hosting. I know I could leave most of it to google, but
> this way I can also get a list of broken links and suchlike. I also
> hadn't played with Perl threads before, so this seemed like an
> interesting learning exercise.
If you're saving the *entire* contents of each page in your SQL
database, then you might consider giving each crawler thread it's own
SQL database connection, and skip having a dedicated process for that
task. After all, a database connection *already* is a pipe (or socket,
or something) to a dedicated process; there's no reason to slow things
down by having an extra layer of IO.
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: 1 Jan 2003 15:13:21 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: embeding perl / getting results
Message-Id: <auv0ih$31h$1@mamenchi.zrz.TU-Berlin.DE>
Hans Schlüter <hans@schlueters.de> wrote in comp.lang.perl.misc:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message
> news:<aut2mf$pgb$1@mamenchi.zrz.TU-Berlin.DE>...
> > Well, printing things isn't the way to return values to the calling
> > C program.
>
> Yes I know. But I'm maintaining a bad application with a large amount
> of Perl scripts that are mostly run through pipes. The Output is then
> parsed by some string manipulation tasks to get a value of a variable
> that is printed, too. Depending on this value the C-Application does
> different tasks.
How is this done now? I imagine there is some (shell?) script that
calls the Perl script(s), captures their output and feeds it to your
C program. Is that the situation you're coming from?
> This all is very dirty and not very performant and I
> want to make it a little bit faster. By embedding Perl do the C
> application, reading the variable with get_sv and then look what to do
> with the output (print, store to a file, send via socket, ....) And
> it's that much Perl Source and I wouldn't like changing it.
If the existing Perl code prints its results and you want it to deposit
them in package variables, I don't see how you can possibly get around
changing it. "print" will be "print", unless you run it through a mutant
Perl interpreter.
Anno
------------------------------
Date: Wed, 1 Jan 2003 18:21:04 +0000 (UTC)
From: Pierre Asselin <pa@panix.com>
Subject: Re: embeding perl / getting results
Message-Id: <auvbid$72o$1@reader1.panix.com>
In <4209e1d7.0301010433.5456d234@posting.google.com> hans@schlueters.de (=?ISO-8859-1?Q?Hans_Schl=FCter?=) writes:
>anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<aut2mf$pgb$1@mamenchi.zrz.TU-Berlin.DE>...
>> Well, printing things isn't the way to return values to the calling
>> C program.
>Yes I know. But I'm maintaining a bad application with a large amount
>of Perl scripts that are mostly run through pipes.
Well, you could dup2() your stdout to one end of a pipe before you
run the perl, and read from the other end at your leasure. If your
C wrapper needs its stdout for other purposes, you'll have to call
dup2() and run the perl in a forked child. Is it worth the trouble?
------------------------------
Date: 1 Jan 2003 12:00:20 -0800
From: hans@schlueters.de (=?ISO-8859-1?Q?Hans_Schl=FCter?=)
Subject: Re: embeding perl / getting results
Message-Id: <4209e1d7.0301011200.2dc66064@posting.google.com>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<auv0ih$31h$1@mamenchi.zrz.TU-Berlin.DE>...
> How is this done now? I imagine there is some (shell?) script that
> calls the Perl script(s), captures their output and feeds it to your
> C program. Is that the situation you're coming from?
At the moment there are some Perl-Script that does something like
----
$key = "foobar"
print "bsdsdrfgzhrtfsdfgbfdfdfas\n";
print "Key: $key\n";
print "<some more content>";
----
Then there is a C written application this uses popen() to run the
Perl-Scripts and read its STDOUT output. Now the C-Application looks
for key (needs a little bit RegExp'ing, caus it's not that clear like
in the example above). Depending on the key and other information the
complete output is used somewhere als (stored, transmitted via socket,
...)
I thought I could embed perl to the C-Application have a "real" look
on $key AND read the output into a C variable.
> If the existing Perl code prints its results and you want it to deposit
> them in package variables, I don't see how you can possibly get around
> changing it. "print" will be "print", unless you run it through a mutant
> Perl interpreter.
If I didn't miss a directory it are around 50 Perl-Scripts and they
are maintained by different people and I can't change them all. If
nobody has an idea how I could do this, I keep using this pipe...
Thanks
Hans
------------------------------
Date: Wed, 01 Jan 2003 17:57:11 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Freebsd memory leak.
Message-Id: <3E137247.68585653@earthlink.net>
Brian Skreeg wrote:
First suggestion: Use strict and warnings. Without them, you'll get a
lot less help than you'll get with them.
[snip]
> foreach $row ($ts->rows) {
> if (@$row[0] =~ /Norm/)
This isn't related to your problem, but why are you asking perl for an
array slice (@$row[0]) when what you appear to want is a single element
from the arrayref (either $$row[0], or $row->[0])?
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: Thu, 2 Jan 2003 01:07:57 +0530
From: "Kasp" <kasp@NO_SPAMepatra.com>
Subject: Re: How can I comment out a large block of perl code?
Message-Id: <auvg2s$dav$1@newsreader.mailgate.org>
Can someone give me a link to "download" the Perl FAQs?
Thanks.
--
Perl is designed to give you several ways to do anything, so
consider picking the most readable one.
-- Larry Wall in the perl man page
------------------------------
Date: Wed, 01 Jan 2003 19:53:21 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: How can I comment out a large block of perl code?
Message-Id: <uih61vs2mabuevq2necke0htvjts0u4h8g@4ax.com>
Kasp wrote:
>Can someone give me a link to "download" the Perl FAQs?
They come with every installation of Perl. You can consult them online
on <http://www.perldoc.com>. There's even more FAQs reachable from
<http://www.perl.com/pub/q/FAQs>.
--
Bart.
------------------------------
Date: Wed, 1 Jan 2003 23:26:43 +0100
From: "Murat Ünalan" <murat.uenalan@gmx.de>
Subject: Re: how to load a module depending on 'if' condition ?
Message-Id: <auvq05$dpf$04$1@news.t-online.com>
> if (!$ENV{OSTYPE} eq 'linux')
> {
> use Win32::GUI;
> };
>
> Could you help me ?
Your "use" will be called during compile-time, not runtime. So you if()
doesn't do anything on the "use". I think you asked for this:
if ( !$ENV{OSTYPE} eq 'linux' )
{
eval "use Win32::GUI";
};
Good Luck,
Murat
------------------------------
Date: Wed, 1 Jan 2003 22:12:31 +0400
From: "sarath" <sarath.chandra@uaeexchange.com>
Subject: need help for regular expression
Message-Id: <auvba7$47r5@news.emirates.net.ae>
I want to write a regular expression for evaluating an numeric input
of this format :
+123-123567-24524567
I am new at this, so tried ^\(d{1,6})\-\(d{1,8})\-\(d{3,10})$
and it wont work.
Any help please.
regards
Sarath
------------------------------
Date: Wed, 01 Jan 2003 18:40:15 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: need help for regular expression
Message-Id: <mbudash-4F0985.10401301012003@typhoon.sonic.net>
In article <auvba7$47r5@news.emirates.net.ae>,
"sarath" <sarath.chandra@uaeexchange.com> wrote:
> I want to write a regular expression for evaluating an numeric input
> of this format :
>
> +123-123567-24524567
>
> I am new at this, so tried:
>
> ^\(d{1,6})\-\(d{1,8})\-\(d{3,10})$
>
> and it won't work.
don't know what "won't work" means, but try:
^(\d{1,6})\-(\d{1,8})\-(\d{3,10})$
hth-
------------------------------
Date: Wed, 01 Jan 2003 18:44:12 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: need help for regular expression
Message-Id: <mbudash-7BC6C9.10441101012003@typhoon.sonic.net>
In article <mbudash-4F0985.10401301012003@typhoon.sonic.net>,
Michael Budash <mbudash@sonic.net> wrote:
> In article <auvba7$47r5@news.emirates.net.ae>,
> "sarath" <sarath.chandra@uaeexchange.com> wrote:
>
> > I want to write a regular expression for evaluating an numeric input
> > of this format :
> >
> > +123-123567-24524567
> >
> > I am new at this, so tried:
> >
> > ^\(d{1,6})\-\(d{1,8})\-\(d{3,10})$
> >
> > and it won't work.
>
> don't know what "won't work" means, but try:
>
> ^(\d{1,6})\-(\d{1,8})\-(\d{3,10})$
>
> hth-
oops - just noticed the beginning-of-line anchor you had there, so try
this instead:
^\+(\d{1,6})-(\d{1,8})-(\d{3,10})$
(escaping of dashes unnecessary outside of character classes.)
hth-
------------------------------
Date: Thu, 2 Jan 2003 00:26:36 +0530
From: "Kasp" <kasp@NO_SPAMepatra.com>
Subject: Re: need help for regular expression
Message-Id: <auvdlc$c4t$1@newsreader.mailgate.org>
+123-123567-24524567
-^^^
3 digits right? Why are you writing \d{1,6} then? Let's hope you know
what you are doing here.
To detect the number with d{1,6} logic.... try this regular expression:
^\+\d{1,6}\-\d{1,8}\-\d{3,10}$
(assuming + and - are fixed and not interchangeable...otherwise just replace
them with (+|-) .
I am new to Perl too, so my answer may not be perfect or close to it.
But critics please respond, so that I can improve!
--
Perl is designed to give you several ways to do anything, so
consider picking the most readable one.
-- Larry Wall in the perl man page
------------------------------
Date: Wed, 01 Jan 2003 22:11:32 +0100
From: "Harald H.-J. Bongartz" <bongie@gmx.net>
Subject: Re: need help for regular expression
Message-Id: <1095117.PayD8yhozJ@nyoga.dubu.de>
sarath wrote:
> I want to write a regular expression for evaluating an numeric input
> of this format :
Please do not multipost; use the cross-posting feature of your usenet
client software. I answered your question on alt.perl (Msg-Id:
<1082663.IFaKkDdn8k@nyoga.dubu.de>).
Ciao,
Harald
--
Harald H.-J. Bongartz <bongie@gmx.net>
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Life would be so much easier if we could just look at the source code.
------------------------------
Date: Wed, 01 Jan 2003 21:39:58 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: need help for regular expression
Message-Id: <OeJQ9.217108$a8.13903@news4.srv.hcvlny.cv.net>
"sarath" <sarath.chandra@uaeexchange.com> wrote in message
news:auvba7$47r5@news.emirates.net.ae...
>
> I want to write a regular expression for evaluating an numeric input
> of this format :
>
> +123-123567-24524567
>
> I am new at this, so tried ^\(d{1,6})\-\(d{1,8})\-\(d{3,10})$
> and it wont work.
>
> Any help please.
>
> regards
> Sarath
>
>
>
Do you really want to 'evaluate' it? Your regular expression only
attempts to match it. 'Evaluating' does not even require a match.
use strict;
use warnings;
my $str = '+123-123567-24524567';
my $val = eval $str;
print "$val\n";
------------------------------
Date: Wed, 01 Jan 2003 10:22:25 -0600
From: Scott Yanoff <yanoff@yahoo.com>
Subject: Re: Perl Tutorials
Message-Id: <3e131356$0$589$39cecf19@nnrp1.twtelecom.net>
Scott Hoopes wrote:
> Hello,
>
> I want to learn how to code in PERL. What are some good books/tutorials to
> go through to understand the introductory programming necessities for PERL.
A good place to start is http://learn.perl.org/
Good luck,
--
-Scott
yanoff@yahoo.com | http://www.yanoff.org | AOL IM: SAY KJY
------------------------------
Date: Wed, 01 Jan 2003 10:15:32 -0500
From: Ryan <ryan@cardweb.com>
Subject: Re: pod 2 info?
Message-Id: <CEDQ9.11$396.8245@news.abs.net>
Ron Savage wrote:
>
> Personally, I write in POD format, and use the Pod::POM module and my script
> fancy-pom2.pl to convert to HTML.
Hmmm... after a couple days of finding no solution, it looks like I
might have to roll my own, or just not support info. Most likely the
latter, as I'm pretty lazy...
> Yep, that's it - no other formats supported. People have browsers, right? So
> HTML is sufficient.
Yup, I suppose. Althought you could easily support man by dropping a
quick pod2man command into your Makefiles. Rather unnecessary for Perl
modules though.
thanks,
Ryan
------------------------------
Date: 1 Jan 2003 12:42:59 -0800
From: salmjuh@hotmail.com (juha)
Subject: system command and $_ variable
Message-Id: <c9858ca5.0301011242.731c20dd@posting.google.com>
Hi all
My script try to wake up another program and give some variables at
the same time to that program.
Here is what doesn't work:
system ('ffmpeg -i /tmp/$_ -b 1300 -s 352*288 /tmp/ready/$_');
It has read the real file name before OK, but when I run it, it gives
me:
ffmpeg -i /tmp/$_ -b 1300 -s 352*288 /tmp/ready/$_
I have tryit almost everything and running out of ideas.
So people, how do I get real filenames to right places ??
Thanks for any help
JS
------------------------------
Date: Wed, 01 Jan 2003 20:44:13 GMT
From: "Ian.H [dS]" <ian@WINDOZEdigiserv.net>
Subject: Re: system command and $_ variable
Message-Id: <3ok61v00q3331ged4g8kr1he2gjg3nnbtd@4ax.com>
Keywords: Remove WINDOZE to reply
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
In a fit of excitement on 1 Jan 2003 12:42:59 -0800,
salmjuh@hotmail.com (juha) managed to scribble:
> Hi all
>
> My script try to wake up another program and give some variables at
> the same time to that program.
>
> Here is what doesn't work:
>
> system ('ffmpeg -i /tmp/$_ -b 1300 -s 352*288 /tmp/ready/$_');
>
> It has read the real file name before OK, but when I run it, it gives
> me:
>
> ffmpeg -i /tmp/$_ -b 1300 -s 352*288 /tmp/ready/$_
>
> I have tryit almost everything and running out of ideas.
> So people, how do I get real filenames to right places ??
>
> Thanks for any help
>
> JS
Use " " rather than ' ' for the system call.
HTH.
Regards,
Ian
-----BEGIN xxx SIGNATURE-----
Version: PGP Personal Privacy 6.5.3
iQA/AwUBPhNTGGfqtj251CDhEQITFACg/WxAnx0gpxjfaPMZ0PXunZEZcncAoLIY
A1xiXPd6rKhwCoasdH4f+Ico
=msDL
-----END PGP SIGNATURE-----
--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Scripting, Web design, development & hosting.
------------------------------
Date: Wed, 01 Jan 2003 17:33:09 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: system command and $_ variable
Message-Id: <3E136CA5.70B49B42@earthlink.net>
juha wrote:
>
> Hi all
>
> My script try to wake up another program and give some variables at
> the same time to that program.
>
> Here is what doesn't work:
>
> system ('ffmpeg -i /tmp/$_ -b 1300 -s 352*288 /tmp/ready/$_');
Try:
system(qw(ffmpeg -i), "/tmp/$_", qw(-b 1300 -s 352*288),
"/tmp/ready/$_")
Note that I use "" around the parts containing $_, so that string
interpolation occurs.
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: Wed, 01 Jan 2003 22:28:20 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: system command and $_ variable
Message-Id: <ecq61vgo2uui78ivfkk7oma2de35vcpfc1@4ax.com>
juha wrote:
>Here is what doesn't work:
>
>system ('ffmpeg -i /tmp/$_ -b 1300 -s 352*288 /tmp/ready/$_');
Learn about the difference between single and double quotes from perlop,
in the docs which come with Perl, or from
<http://www.perldoc.com/perl5.8.0/pod/perlop.html>
In particular, the sections
"Quote and Quote-like Operators"
<http://www.perldoc.com/perl5.8.0/pod/perlop.html#Quote-and-Quote-like-Operators>
"Gory details of parsing quoted constructs",
subsection "interpolation"
<http://www.perldoc.com/perl5.6/pod/perlop.html#Gory-details-of-parsing-quoted-constructs>
--
Bart.
------------------------------
Date: Wed, 01 Jan 2003 17:53:14 GMT
From: "Manu" <photos@agileemmy.com>
Subject: Re: Using perl to captuer IP of person submitting a form
Message-Id: <eWFQ9.6952$134.764048@newsread1.prod.itd.earthlink.net>
"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:ZDnQ9.34259$Jb.22385@nwrddc02.gnilink.net...
> Bill wrote:
> > Does anyone know how to capture the IP of a user submitting a form,
> > and store that IP along with the data they submit?
>
> Why do you want to do that?
> The IP doesn't tell you anything. It may be different with the next access
> of the same person or it may be the same although it's a totally different
> person this time.
>
We do it because of the nature of our services. If something less than cool
was done, we have an IP address which we can use to track down the access
provider who can look in their logs and know who was on that IP at that
time.
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.434 / Virus Database: 243 - Release Date: 12/25/2002
------------------------------
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 4331
***************************************