[22108] in Perl-Users-Digest
Perl-Users Digest, Issue: 4330 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 1 09:05:39 2003
Date: Wed, 1 Jan 2003 06:05:06 -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: 4330
Today's topics:
Cookies, forms, and LWP? <no@no.thanks>
Re: Dealing with split() and quotes (Max Power)
Re: Direct Shared Memory Mapping? <gordan@_NOSPAM_bobich.net>
Re: Direct Shared Memory Mapping? <goldbb2@earthlink.net>
Re: embeding perl / getting results (=?ISO-8859-1?Q?Hans_Schl=FCter?=)
Freebsd memory leak. <mongrol@REMOVE.btinternet.com>
How to compile a pm Net.Telnet into .exe file <tancm@pacific.net.sg>
Re: please! ls system call help <jurgenex@hotmail.com>
Re: please! ls system call help (Tad McClellan)
Re: please! ls system call help (Tad McClellan)
Re: whats the syntax to get a scalar out an array of re <isresi1@xs4all.nl>
Re: whats the syntax to get a scalar out an array of re <mpapec@yahoo.com>
Re: whats the syntax to get a scalar out an array of re <isresi1@xs4all.nl>
Wish you all a happy new year !! <kasp@NO_SPAMepatra.com>
Re: Yet Another Question About: "my" and scope of vars <goldbb2@earthlink.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 1 Jan 2003 07:11:26 -0500
From: "Jay Stuler" <no@no.thanks>
Subject: Cookies, forms, and LWP?
Message-Id: <auulql$4rg$1@charm.magnus.acs.ohio-state.edu>
Happy New Year!
Sorry if this question is covered elsewhere but I googled and didn't find
anything. Plus it is very late/early on New Years Day!
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?
Again, hope this makes sense, no flames plz! Thanks
--
"I'm crazy protractor beard! Look, I got a beard made out of a damn
protractor. Isn't that bizarre? Now I believe you're gonna give me some
damn candy. I got nowhere to go. So you might as well cough up the candy!"
------------------------------
Date: 1 Jan 2003 05:51:25 -0800
From: Mike@Kordik.net (Max Power)
Subject: Re: Dealing with split() and quotes
Message-Id: <1e89f371.0301010551.466ffe5c@posting.google.com>
Thank you for the education.
Have a safe and happy 2003 everyone!
------------------------------
Date: Wed, 01 Jan 2003 03:12:18 +0000
From: Gordan <gordan@_NOSPAM_bobich.net>
Subject: Re: Direct Shared Memory Mapping?
Message-Id: <s0tQ9.1984$8E6.132710@newsfep1-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.
>> I have looked at IPC::Shareable, which seems to be unable to use
>> memory segments bigger than 64 KB (haven't worked out why yet), and
>> IPC::ShareLite, which only supports scalar input. They BOTH require
>> the memory contents to be copied into a local variable which means
>> that for each parallel process reading the area, the memory has to be
>> copied out, worked on, and then put back.
>
> Unless you want to write your program using XS or Inline::C, this is
> completely unavoidable.
>
> The best you would be able to do would be to use tieing or overloading
> to make it *appear* as if the "copy out, modify, put back" was a single
> step.
I figured that is the case in the existing implementations.
>> This becomes even worse when the IPC::Shareable module is used or the
>> Storeable module is used to serialize the data at every read-write to
>> the memory.
>
> You should only be using Storable if you're dealing with complex,
> arbitrary data structures. If you're using simple data structures (or
> complex but fixed-structure data structures), then there are likely
> better techniques.
Nothing too complex, just an array of strings various lengths, or a simple
hash.
>> 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. Also checking and setting
$Hash{"Key"}.
>> Is there a module out there to do this in Perl?
>>
>> The reason I'm asking this is because I am designing a parallel
>> application. The only two options I have are threads in Perl 5.8.0,
>> which is unstable (my program crashes intermittently), or fork(). I
>> have ported my program to use IPC::Shareable instead (on Perl 5.6.1),
>> but it seems that the shared variables are limited to 64 KB -
>> otherwise it is more stable than threads in 5.8.0.
>>
>> If I use threads, I can mark a variable as shared, which works great.
>
> Umm, you do realize that with threads, there is actually a hidden
> fetch/modify/store done behind the scenes? (Sharing a variable actually
> ties it to a special class)
The memory consumption of my threaded program sort of implied that. :-(
>> But if I use fork(), then I have to map the variable into shared
>> memory, to make it available to all processes, and there doesn't
>> appear to be an efficient way to do this,
>
> How about forks.pm and forks::shared from CPAN?
Thanks, I'll look into those. forks::shared in particular looks promising so
far. It should be an easy port from the initial threaded implementation I
have working.
> Just like threads::shared, it still does a fetch/modify/store, except
> that instead of fetching it from a special "shared" thread/memory pool,
> it fetches it from actual shared/mmapped memory.
Sounds like a workaround for the stability issues I'm having with threads.
I'll try it, thanks. :-)
>> 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;
> Eg, consider the situation where your data consists of just numbers.
>
> You could do:
> use constant PACKFMT => 'd';
> use constant PACKLEN => pack(PACKFMT);
> use constant MAXSHARED => 4096;
> die if MAXSHARED % PACKLEN;
> sub TIEARRAY {
> my ($class, $size) = @_;
> my @self = $size;
> $size *= PACKLEN;
> while( $size > 0 ) {
> my $get = $size > MAXSHARED ? MAXSHARED : $size;
> my $id = shmget IPC_PRIVATE, $get, S_IRWXU;
> push @self, $id;
> $size -= MAXSHARED;
> }
> bless \@self, $class;
> }
This is pretty much what I meant when I mentioned putting list blocks into
separate shared memory blocks and keeping a list of shared memory
keys/pointers.
> sub FETCH {
> my ($self, $index) = @_;
> my $size = $self->[0];
> die if $index >= $size;
> $index *= PACKLEN;
> my $id = int($index / MAXSHARED);
> my $idx = $index % MAXSHARED;
> shmread( $id, my( $packed_num ), $idx, PACKLEN );
> unpack PACKFMT, $packed_num;
> }
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.
However, depending on precisely what happens in the average case (and I
cannot guess this without doing a benchmark of all three approaches), it
may make sense to do one of these two alternatives:
1) Map EACH element of a list into a SEPARATE shared memory block (providing
that element size never exceeds the SHMMAX). Some memory is wasted to the
tune of $ElementSize % PAGE_SIZE, but only one segment of shared memory of
minimal possible size ever needs to be operated on in the
fetch->modify->store cycle.
2) A compromise between the two approaches so far - try to squeeze multiple
array entries into the same segment of a minimal size if they will fit,
thus saving some memory, but also increasing the complexity of the fetch
processes. The complexity of this is most likely to outweigh the benefits
in memory saving.
> sub STORE {
> my ($self, $index, $num) = @_;
> my $size = $self->[0];
> die if $index >= $size;
> $index *= PACKLEN;
> my $id = int($index / MAXSHARED);
> my $idx = $index % MAXSHARED;
> shmwrite( $id, pack(PACKFMT, $num), $idx, PACKLEN );
> }
> sub FETCHSIZE { $_[0][0] }
>
> After you've done this, you simply tie your array variable to the class,
> then fork, and use the array as normal. No memory is wasted.
Yes, I understand what you are saying, but fundamentally, it still means
that the entire shared memory segment up to SHMMAX needs to be copied out
and written back. The slightly modified approach 1) above would ensure that
only _one_ element of smallest possible size is ever copied out of the
shared memory to be worked on. It is still not the ideal solution of
operating directly on the shared memory segment without the need to
fetch->modify->store, but at least the size of the segment is kept to a
minimum for each operation, thus minimizing the amount of needless unshared
memory duplication across processes.
>> Shared memory can only be allocated in blocks of PAGE_SIZE, which is
>> 4096 bytes on x86, so to optimize memory usage, each segment would
>> have to consist of multiple array/list elements, thus giving a list of
>> lists arrangement, which would limit parallelism, because only each
>> "chunk" could be processed in parallel to save on shared memory
>> bandwidth and consumption. Or I could map one segment as "cache" that
>> would only be re-filled when it is empty, but this seems vastly
>> overcomplicated, and still doesn't solve the initial problem.
>
> 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.
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.
While in the case of just URLs, the segment size of 4K for each element will
be ample, in the case of the content, variable segments may need to be
used. This is where storing each element separately is likely to yield most
benefits.
>> All these solutions seem to involve a huge amount of working around
>> the problem, and ultimately mean that shared memory STILL has to be
>> copied into unshared memory first, rather than operating on the shared
>> memory directly.
>
> The closest thing you would be able to get to working on the shared
> memory directly is a combination of overload.pm, and use of XS or
> Inline::C. I'm not going to write code to do that unless I *know* that
> it's really what you need/want, and that it will be used.
Thank you for the pointers. I certainly don't expect you to write the code
for me! You have already helped far more than I expected anyone to. At the
moment it looks like the most speed and memory efficient option is going to
be to try to minimize shared memory access by mapping and retrieving each
element separately. The total memory usage, despite the wasteage due to
PAGE_SIZE allocation minimum is still likely to be smaller than if it would
be if each thread kept a complete local copy of the data structure in
shared memory. I guess I better go and write a tie class for shared memory
arrays like this.
Thanks for your help, I do appreciate it.
Happy new year, and all. :-)
Gordan
------------------------------
Date: Wed, 01 Jan 2003 01:07:12 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Direct Shared Memory Mapping?
Message-Id: <3E128590.A583CAF1@earthlink.net>
Gordan wrote:
>
> 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.
[snip]
> > You should only be using Storable if you're dealing with complex,
> > arbitrary data structures. If you're using simple data structures
> > (or complex but fixed-structure data structures), then there are
> > likely better techniques.
>
> Nothing too complex, just an array of strings various lengths, or a
> simple hash.
I like your definition of simple -- I wish it were.
Perl arrays, internally, are pointers to pointers... sort of like having
a type 'char**' in C. If you want to change the length of element X of
such an array, you could simply do:
array[X] = realloc( array[X], newlen );
But shared memory segments are flat arrays of bytes -- you can't easily
think in terms of malloc/realloc/free with them.
In fact, the best way to think of a shared memory segment is a file
which you can quickly, atomically, perform a seek() and a read().
Supposing you've a virtual array of varying length strings in a file...
what format would you use? How would you go about changing the length
of an element? How do you go about fetching or storing the Xth element?
And hashes are even *less* simple. Perl makes them *look* simple, but
there's quite a bit going on behind the scenes.
> >> 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.
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)?
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)
> Also checking and setting $Hash{"Key"}.
Does the set of keys that %Hash has ever change?
Are the values of %Hash fixed length, or 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. 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.
[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.
[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.
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;
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).
> 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?
[snip stuff for dealing with shared memory, which I've just shown is the
entirely wrong solution for the given problem.]
--
$..='(?:(?{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 04:33:54 -0800
From: hans@schlueters.de (=?ISO-8859-1?Q?Hans_Schl=FCter?=)
Subject: Re: embeding perl / getting results
Message-Id: <4209e1d7.0301010433.5456d234@posting.google.com>
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. 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.
Hans
------------------------------
Date: Wed, 1 Jan 2003 12:43:06 -0000
From: "Brian Skreeg" <mongrol@REMOVE.btinternet.com>
Subject: Freebsd memory leak.
Message-Id: <v15oinr9qc0829@corp.supernews.com>
Hi clever peeps,
I`ve written a wee prog (snippets below) that runs fine on a WinXP system
(ActivePerl 5.6.1) but has a killer memory leak on my FreeBSD server. The
program fetches data from a website, parses various information from the
webpages using HTML::TableExtract and dumps it into a mysql database.
Roughly there`s about 1000-1500 iterations of the program with 2 webpages
parsed for each. Memory raises about 200k per second and the whole thing
falls over with the error below when the max 128M ram used up. Snippets
below;
#--start
use IO::Handle;
use LWP::Simple;
use HTML::TableExtract;
use DBI;
#--- Snippet from body of code--
$te = new HTML::TableExtract( depth => 1, count => 1 );
$te->parse($doc);
$ts = $te->table_state(1,1);
#print "Table found at ", join(',', $ts->coords), "\n";
foreach $row ($ts->rows) {
$name = @$row[0];
print "$name\n";
}
# Extract Balance Sheet
$te = new HTML::TableExtract( depth => 1, count => 6 );
$te->parse($doc);
$fixedinv = 0; $netassets = 0;
$intangibles = 0; $fixedass = 0;
$fixedinv = 0 ; $stocks = 0;
$debtors = 0; $cash = 0;
$credlong = 0; $credshort = 0;
foreach $ts ($te->table_states) {
#print "Table found at ", join(',', $ts->coords), "\n";
foreach $row ($ts->rows) {
if (@$row[0] =~ /Norm/)
{ $normeps = @$row[4]; chomp($normeps); }
if (@$row[0] =~ /Div per share/)
{ $div = @$row[4]; chomp($div); }
if (@$row[0] =~ /Fixed asset/ && @$row[4] =~ /[0-9]/)
{ $fixedass = @$row[4]; chomp($fixedass); $fixedass =~ s/,//; }
if (@$row[0] =~ /Fixed invest/ && @$row[4] =~ /[0-9]/)
{ $fixedinv = @$row[4]; chomp($fixedinv); $fixedinv =~ s/,//; }
if (@$row[0] =~ /Stocks/ && @$row[4] =~ /[0-9]/)
{ $stocks = @$row[4]; chomp($stocks); $stocks =~ s/,//; }
if (@$row[0] =~ /Debtors/ && @$row[4] =~ /[0-9]/)
{ $debtors = @$row[4]; chomp($debtors); $debtors =~ s/,//; }
if (@$row[0] =~ /Cash/ && @$row[4] =~ /[0-9]/)
{ $cash = @$row[4]; chomp($cash); $cash =~ s/,//;}
if (@$row[0] =~ /Intangibles/ && @$row[4] =~ /[0-9]/)
{ $intangibles = @$row[4]; chomp($intangibles); $intangibles =~
s/,//; }
if (@$row[0] =~ /Creditors short/ && @$row[4] =~ /[0-9]/)
{ $credshort = @$row[4]; chomp($credshort); $credshort =~ s/,//; }
if (@$row[0] =~ /Creditors long/ && @$row[4] =~ /[0-9]/)
{ $credlong = @$row[4]; chomp($credlong); $credlong =~ s/,//; }
if (@$row[0] =~ /Mkt capit/)
{ $cap = @$row[4]; chomp($cap); $cap =~ s/,//; }
}
}
# do balance sheet
$netassets =
$intangibles+$fixedass+$fixedinv+$stocks+$debtors+$cash-$credlong-$credshort
;
# Extract Analyst data
$url = http://Brian.Skreegs.Secret.url.com/$ecode/$epic.htm;
$doc = get($url);
if ($doc =~ /may no longer exist/)
{
print $logfile "$epic: No Analyst page at $url\n";
next;
}
$te = new HTML::TableExtract( depth => 1, count => 3 );
$te->parse($doc);
$ts = $te->table_state(1,3);
foreach $row ($ts->rows) {
if (@$row[0] =~ /Forecast Year 1/)
{
$consensus1 = @$row[2];
#print "Consensus1 is $consensus1\n";
}
if (@$row[0] =~ /Forecast Year 2/)
{
$consensus2 = @$row[2];
#print "Consensus2 is $consensus2\n";
}
}
# Build query and insert row
$query = "UPDATE current SET
Sector = '$sector',
NormEPS = '$normeps',
ConsensusEPS1 = '$consensus1',
ConsensusEPS2 = '$consensus2',
Dividend = '$div',
Netassets = '$netassets',
Cap = '$cap',
Intangibles = '$intangibles',
Fixedassets = '$fixedass',
FixedInvestments = '$fixedinv',
Stocks = '$stocks',
Debtors = '$debtors',
Cash = '$cash',
Creditorsshort = '$credshort',
Creditorslong = '$credlong'
WHERE EPIC='$epic'";
print "$epic Done\n";
$stu = $dbh->prepare($query) || die "prepare: $query: $DBI::errstr";
$stu->execute || die "execute: $query: $DBI::errstr";
$stu->finish();
}# while($epic);
$sth->finish();
}
Killer error: Basically it can`t fetch the next url due to not having any
physical memory left. The url fetch times out, it tries to carry on but
fails doing regexp`s on non existant data. So the error below doesn`t
indicate anything.
Use of uninitialized value in pattern match (m//) at getfund.pl line 56.
Use of uninitialized value in pattern match (m//) at getfund.pl line 56.
Use of uninitialized value in pattern match (m//) at getfund.pl line 61.
Use of uninitialized value in subroutine entry at getfund.pl line 68.
Can't call method "rows" on an undefined value at getfund.pl line 71.
To my newbie head its clear the row arrays aren`t being released. Is there a
command or something to clear and reset vars each iteration?
------------------------------
Date: Wed, 1 Jan 2003 13:45:46 +0800
From: "Tan Chong Ming" <tancm@pacific.net.sg>
Subject: How to compile a pm Net.Telnet into .exe file
Message-Id: <autun0$dlv$1@reader01.singnet.com.sg>
Hi !,
I am in the stage of learning now to use Perl in a Windows Environment. I
have a perl script
that works but when I tried to compile into a .exe file and run from there,
it gives me this error
System.ApplicationException : Can't locate type Net.Telnet at
PerlRuntime.Interpreter.GetType(Int 32 x, string klass).
I believe that I did not compile the Telnet.pm module in. Pls correct me
if I am wrong and how to compile
this module into the .exe file.
Thank you.
Regards,
CM
------------------------------
Date: Wed, 01 Jan 2003 02:09:35 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: please! ls system call help
Message-Id: <z5sQ9.31345$ac.8414@nwrddc01.gnilink.net>
Abernathey Family wrote:
> Without glancing at the screen, Tad McClellan wrote 6 words:
>>
>> Abernathey Family <family2@aracnet.com> wrote:
>>> 64.130.6.101, [joe@sirfsup.com] wrote:
>>
>>>> i just want to make an 'ls' system call on /home and put that in
>>>> an array
>>
>>> my @dir_contents = 'ls -1';
>>>
>>> or
>>>
>>> my @dir_contents = system("ls -1") == 0 or die "cannot access: $?";
>>
>> Neither one of those will work.
> --snip--
> Both work fine.
Work fine for what? Not for what the OP wanted.
As I explained earlier neither of your two solutions will capture the output
of "ls" in @dir_contents.
In the first one you are using single quotes instead of the correct
backquotes.
And in the second example at best you are assigning the return value of
system (a little bit munged) to @dir_content but not the output of "ls".
Why at least don't you try your code after two people told you it doesn't
work before blindly claiming it does?
jue
------------------------------
Date: Tue, 31 Dec 2002 20:17:59 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: please! ls system call help
Message-Id: <slrnb14jun.b8f.tadmc@magna.augustmail.com>
Abernathey Family <family2@aracnet.com> wrote:
> Abernathey Family wrote:
>> my @dir_contents = 'ls -1';
^ ^
> By the way, sometimes the call must be explicit, like:
>
> my @dir_contents = `/bin/ls -1`;
^ ^
And sometimes you have to use the right syntax.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 31 Dec 2002 20:21:33 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: please! ls system call help
Message-Id: <slrnb14k5d.b8f.tadmc@magna.augustmail.com>
Without executing the code they suggested the Abernathey Family <family2@aracnet.com> wrote:
> Without glancing at the screen, Tad McClellan wrote 6 words:
>>
>> Abernathey Family <family2@aracnet.com> wrote:
>> > 64.130.6.101, [joe@sirfsup.com] wrote:
>>
>> >> i just want to make an 'ls' system call on /home and put that in an array
>>
>> > my @dir_contents = 'ls -1';
>> >
>> > or
>> >
>> > my @dir_contents = system("ls -1") == 0 or die "cannot access: $?";
>>
>> Neither one of those will work.
> --snip--
> Both work fine.
Neither work at all.
The first one uses the wrong kind of single quotes. The
ls is never even executed.
The second one does not put the dir names into the array.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 01 Jan 2003 09:40:39 +0100
From: smasr <isresi1@xs4all.nl>
Subject: Re: whats the syntax to get a scalar out an array of references.
Message-Id: <3e12a9a1$0$128$e4fe514c@dreader5.news.xs4all.nl>
Tad McClellan wrote:
> smasr <isresi1@xs4all.nl> wrote:
>
>> Anyway as the hours went by i realised that GetItemValue returns an Array
>> of memory references.
>
>
> An "array of references to arrays" is the more precise terminology.
>
>
>> But i am not sure i dont' understand the Perl errors
>> very well yet.
>
>
> What error messages did you get?
>
> Did you ask perl to explain them to you?
>
> use diagnostics; # provide more verbose messages
>
>
>> I have this and it works.
>>
>> $A = $document->GetItemValue('Product');
>> my $tmp=\@A;
> ^^^^^^^^^^^^
>
> That line does nothing useful.
>
> You don't even _have_ an @A array until that statement.
>
> $A and @A have absolutely nothing to do with each other, despite
> their similar looking names. Perhaps you should review:
>
> perldoc perldata
>
>
>> print @$A;
>>
>>
>> But now my question. How do i get the value in a normal scalar because i
>> needs the value to pass to another function.
>
>
> To figure out how to dereference the references you have gotten:
>
> perldoc perlreftut
>
>
>> As i do not have Notes at home i made my own test case:
>
>
> That was a truly brilliant move, as it allows us without Notes
> to give you concrete help.
>
> Good thinking!
>
>
>> my @arr1=qw(1 2 3);
>> my @arr2=qw(3 4 5);
>> my $ref1=\@arr1;
>> my $ref2=\@arr2;
>
>
> Now that you've perused perlreftut, you know that you can
> rewrite that without the temporary array variables:
>
> my $ref1 = [ qw(1 2 3) ];
> my $ref2 = [ qw(3 4 5) ];
>
>
>> my @result=($ref1, $ref2); #@result has now two references to an
>> array
>> #which has scalars.
>>
>> how do i get the values 1 or 2 or 3 for example via @result in $tmp?
>> I tried several things but nothing seems to work.
>>
>> my $tmp=@result[0][0]; <- nothing i tried seems to work.
> ^
> ^
>
> You should enable warnings.
>
> That was pretty darn close though.
>
>
> my $tmp = $result[0][0];
> or
> my $tmp = $result[0]->[0];
>
>
I now that $A is different from @A but i the code above works.I supposed ast
GetItemValue() returns an array by default Perl does some conversion here
with $A ?
my $A = $document->GetItemValue('Product');
print @$A;
my $A = $document->GetItemValue('Product');
$tmp=\@A; print @$tmp;
I will read perldata soon to learn a bit more.
Thank you for : my $tmp = $result[0]->[0]; I will try it at work.
After your story that $A isn't the same as @A, which is true, i think i'll
first make an array that holds the result of GetItemValue() because thats
cleaner.
Many Thanks.
------------------------------
Date: Wed, 01 Jan 2003 12:42:22 +0100
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: whats the syntax to get a scalar out an array of references.
Message-Id: <b0l51vgpefmlo6n08dua2pb0a6ktu5m8rc@4ax.com>
smasr <isresi1@xs4all.nl> wrote:
>As i do not have Notes at home i made my own test case:
>
> my @arr1=qw(1 2 3);
> my @arr2=qw(3 4 5);
> my $ref1=\@arr1;
> my $ref2=\@arr2;
> my @result=($ref1, $ref2); #@result has now two references to an array
> #which has scalars.
>
>how do i get the values 1 or 2 or 3 for example via @result in $tmp?
>I tried several things but nothing seems to work.
>
> my $tmp=@result[0][0]; <- nothing i tried seems to work.
You were pretty close, use $result[0][0] to get first element out of @arr1.
To dereference whole @arr1 at once you could
@temp = @{$result[0]};
Also take a look at perldoc perlref.
Anybody knows how perl6 will handle this, since $arr[0] will become @arr[0]?
--
Matija
------------------------------
Date: Wed, 01 Jan 2003 13:02:40 +0100
From: smasr <isresi1@xs4all.nl>
Subject: Re: whats the syntax to get a scalar out an array of references.
Message-Id: <3e12d92b$0$157$e4fe514c@dreader7.news.xs4all.nl>
Matija Papec wrote:
> smasr <isresi1@xs4all.nl> wrote:
>>As i do not have Notes at home i made my own test case:
>>
>> my @arr1=qw(1 2 3);
>> my @arr2=qw(3 4 5);
>> my $ref1=\@arr1;
>> my $ref2=\@arr2;
>> my @result=($ref1, $ref2); #@result has now two references to an
>> array
>> #which has scalars.
>>
>>how do i get the values 1 or 2 or 3 for example via @result in $tmp?
>>I tried several things but nothing seems to work.
>>
>> my $tmp=@result[0][0]; <- nothing i tried seems to work.
>
> You were pretty close, use $result[0][0] to get first element out of
> @arr1. To dereference whole @arr1 at once you could
> @temp = @{$result[0]};
>
> Also take a look at perldoc perlref.
>
>
> Anybody knows how perl6 will handle this, since $arr[0] will become
> @arr[0]?
>
>
I will read the perdata / perlref soon.
Thank you for your reply. I will try this tomorrow at work.
------------------------------
Date: Wed, 1 Jan 2003 11:59:53 +0530
From: "Kasp" <kasp@NO_SPAMepatra.com>
Subject: Wish you all a happy new year !!
Message-Id: <auu1v5$qv1$1@newsreader.mailgate.org>
--
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 00:19:07 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Yet Another Question About: "my" and scope of vars...
Message-Id: <3E127A4B.950E8781@earthlink.net>
Thomas Dehn wrote:
>
> "Michele Dondi" <bik.mido@tiscalinet.it> wrote:
> > While writing yet another url extraction script (and yes: I know the
> > relevant faq entry), I realized that the following portion of code
> > does not "work"
> >
> > /href\s*=\s*([\"\'])([^\"\']+)\1/i and push my @urlz, $2 while (<>);
>
> Oh, this code does work *snicker*.
> The very problem is that the code works ;-).
I think you mean, "The very problem is that the code works as written,
but not as intended." Perl is doing precisely what you're telling it to
be doing, but you're telling it to do the wrong thing.
--
$..='(?:(?{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: 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 4330
***************************************