[30011] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1254 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 4 03:09:42 2008

Date: Mon, 4 Feb 2008 00:09: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           Mon, 4 Feb 2008     Volume: 11 Number: 1254

Today's topics:
        circular buffering using substr() ? <azwemmer@gmail.com>
    Re: circular buffering using substr() ? <someone@example.com>
    Re: circular buffering using substr() ? <m@rtij.nl.invlalid>
    Re: circular buffering using substr() ? <azwemmer@gmail.com>
    Re: circular buffering using substr() ? <rm@dontspamme.net>
    Re: circular buffering using substr() ? xhoster@gmail.com
    Re: Need regexp to parse newsgroups <abigail@abigail.be>
        new CPAN modules on Mon Feb  4 2008 (Randal Schwartz)
    Re: perl - array functions (union, intersection, differ <joost@zeekat.nl>
        perl - array functions (union, intersection, difference <inetquestion@hotmail.com>
    Re: perl - array functions (union, intersection, differ <inetquestion@hotmail.com>
    Re: perl - array functions (union, intersection, differ <someone@example.com>
    Re: Perl on Linux and AIX <syscjm@sumire.gwu.edu>
        perl v5.8.8 arm-linux <sonet.all@gmail.com>
    Re: submitting a form when two forms with the same name <ben@morrow.me.uk>
        To strip off a prefix in a variable.. clearguy02@yahoo.com
    Re: To strip off a prefix in a variable.. <m@rtij.nl.invlalid>
    Re: To strip off a prefix in a variable.. <noreply@gunnar.cc>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 3 Feb 2008 13:46:32 -0800 (PST)
From: arz <azwemmer@gmail.com>
Subject: circular buffering using substr() ?
Message-Id: <022ab843-c815-4b28-a85f-089d1b005da6@m34g2000hsb.googlegroups.com>

Hi,

Can I use substr() to do circular buffering? I'm reading a binary data
stream from a pipe, which I need to send out on another pipe, but
since speeds may differ, I need to do some intermediate buffering (up
to a maximum amount).

I have something like the following (simplified):

my $buffer = "";
my $offset = 0;

while (my $cb = read(INPIPE, my $data, 32768)) {
    $buffer .= $data;
    $bytes = syswrite(OUTPIPE, $buffer, $offset, length($buffer) -
$offset);  # OUTPIPE is non-blocking
    $offset += $bytes;
    $buffer .= substr($buffer, $offset);   # move buffer pointer to
offset
}

It works as intended, but the script is eating memory... is $buffer
internally actually growing and growing because it does not go out of
scope and the substr() does not 'reset' it when the new string is
assigned to $buffer? What would be the best way to do this?

Thanks,

--arz


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

Date: Sun, 03 Feb 2008 22:36:35 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: circular buffering using substr() ?
Message-Id: <Tlrpj.5443$cc3.1844@edtnps82>

arz wrote:
> 
> Can I use substr() to do circular buffering?

Probably.  It may be easier to use an array.  But your example isn't 
clear on what you mean by "circular buffering".

> I'm reading a binary data
> stream from a pipe, which I need to send out on another pipe, but
> since speeds may differ, I need to do some intermediate buffering (up
> to a maximum amount).
> 
> I have something like the following (simplified):
> 
> my $buffer = "";
> my $offset = 0;
> 
> while (my $cb = read(INPIPE, my $data, 32768)) {
>     $buffer .= $data;
>     $bytes = syswrite(OUTPIPE, $buffer, $offset, length($buffer) -
> $offset);  # OUTPIPE is non-blocking

perldoc -f syswrite
        syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET
        syswrite FILEHANDLE,SCALAR,LENGTH
        syswrite FILEHANDLE,SCALAR
                Attempts to write LENGTH bytes of data from variable
                SCALAR to the specified FILEHANDLE, using the system call
                write(2).  If LENGTH is not specified, writes whole
                SCALAR.  It bypasses buffered IO, so mixing this with
                reads (other than sysread()), "print", "write", "seek",
                "tell", or "eof" may cause confusion because the perlio
                and stdio layers usually buffers data.  Returns the
                number of bytes actually written, or "undef" if there was
                an error (in this case the errno variable $! is also
                set).  If the LENGTH is greater than the available data
                in the SCALAR after the OFFSET, only as much data as is
                available will be written.

You have the offset and length arguments in the wrong order.


>     $offset += $bytes;
>     $buffer .= substr($buffer, $offset);   # move buffer pointer to
> offset

You are not moving the "buffer pointer", you are just appending data on 
to the end of the buffer, data that was already in the buffer.


> }
> 
> It works as intended, but the script is eating memory... is $buffer
> internally actually growing and growing because it does not go out of
> scope and the substr() does not 'reset' it when the new string is
> assigned to $buffer? What would be the best way to do this?

Could you try and explain more clearly how you want these buffers to work?



John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


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

Date: Sun, 3 Feb 2008 23:45:19 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: circular buffering using substr() ?
Message-Id: <pan.2008.02.03.22.45.17@rtij.nl.invlalid>

On Sun, 03 Feb 2008 13:46:32 -0800, arz wrote:

> Hi,
> 
> Can I use substr() to do circular buffering? I'm reading a binary data
> stream from a pipe, which I need to send out on another pipe, but since
> speeds may differ, I need to do some intermediate buffering (up to a
> maximum amount).
> 
> I have something like the following (simplified):
> 
> my $buffer = "";
> my $offset = 0;
> 
> while (my $cb = read(INPIPE, my $data, 32768)) {
>     $buffer .= $data;
>     $bytes = syswrite(OUTPIPE, $buffer, $offset, length($buffer) -
> $offset);  # OUTPIPE is non-blocking
>     $offset += $bytes;
>     $buffer .= substr($buffer, $offset);   # move buffer pointer to
> offset
> }
> 
> It works as intended, but the script is eating memory... is $buffer
> internally actually growing and growing because it does not go out of
> scope and the substr() does not 'reset' it when the new string is
> assigned to $buffer? What would be the best way to do this?

You are only growing $buffer (hint, you never assign to $buffer, you only 
append), so eating memory is the expected result from your program.

It is also unclear to me what you want to accomplish. I smell a XY 
problem here.

M4


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

Date: Sun, 3 Feb 2008 15:29:32 -0800 (PST)
From: arz <azwemmer@gmail.com>
Subject: Re: circular buffering using substr() ?
Message-Id: <ca39ce08-fb51-4a57-a69e-0b920124af0e@j78g2000hsd.googlegroups.com>

On Feb 3, 11:45 pm, Martijn Lievaart <m...@rtij.nl.invlalid> wrote:
> On Sun, 03 Feb 2008 13:46:32 -0800, arz wrote:
> > Hi,
>
> > Can I use substr() to do circular buffering? I'm reading a binary data
> > stream from a pipe, which I need to send out on another pipe, but since
> > speeds may differ, I need to do some intermediate buffering (up to a
> > maximum amount).
>
> > I have something like the following (simplified):
>
> > my $buffer = "";
> > my $offset = 0;
>
> > while (my $cb = read(INPIPE, my $data, 32768)) {
> >     $buffer .= $data;
> >     $bytes = syswrite(OUTPIPE, $buffer, $offset, length($buffer) -
> > $offset);  # OUTPIPE is non-blocking
> >     $offset += $bytes;
> >     $buffer .= substr($buffer, $offset);   # move buffer pointer to
> > offset
> > }
>
> > It works as intended, but the script is eating memory... is $buffer
> > internally actually growing and growing because it does not go out of
> > scope and the substr() does not 'reset' it when the new string is
> > assigned to $buffer? What would be the best way to do this?
>
> You are only growing $buffer (hint, you never assign to $buffer, you only
> append), so eating memory is the expected result from your program.

Ah I'm sorry, I was typing the code from memory, just outlining the
idea. The statement
  $buffer .= substr($buffer, $offset) should of course be an
assignment:
  $buffer = substr($buffer, $offset).
That was a typo. Same for the syswrite(), which I do use correctly in
the code.

The 'circular' lies in the fact that I assign $buffer to a substring
of itself, thereby 'moving' the buffer pointer, while at the same time
appending data to the buffer on every read... I agree it's not really
circular, but the idea is to have a buffer with moving read and write
pointers.

What I want to accomplish is saving the data that I read in a buffer
(max. say 4 MB, if it goes beyond 4MB I can discard the data, it's
just that I need to take some jitter into account with reader/writer
having different speeds). Data is coming in over one pipe, and needs
to be sent out over another pipe. I currently use the $buffer variable
to add data to ($buffer .= $data), and I move the buffer pointer with
($buffer = substr($buffer, $offset)).

Is that a good idea or would you suggest a different way?

Thanks,

--arz


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

Date: Mon, 04 Feb 2008 00:34:04 GMT
From: "RocketMan" <rm@dontspamme.net>
Subject: Re: circular buffering using substr() ?
Message-Id: <04tpj.10292$U12.7191@trnddc06>


"arz" <azwemmer@gmail.com> wrote in message 
news:022ab843-c815-4b28-a85f-089d1b005da6@m34g2000hsb.googlegroups.com...
> Hi,
>
> Can I use substr() to do circular buffering? I'm reading a binary data
> stream from a pipe, which I need to send out on another pipe, but
> since speeds may differ, I need to do some intermediate buffering (up
> to a maximum amount).
>
> I have something like the following (simplified):
>
> my $buffer = "";
> my $offset = 0;
>
> while (my $cb = read(INPIPE, my $data, 32768)) {
>    $buffer .= $data;
>    $bytes = syswrite(OUTPIPE, $buffer, $offset, length($buffer) -
> $offset);  # OUTPIPE is non-blocking
>    $offset += $bytes;
>    $buffer .= substr($buffer, $offset);   # move buffer pointer to
> offset
> }
>
> It works as intended, but the script is eating memory... is $buffer
> internally actually growing and growing because it does not go out of
> scope and the substr() does not 'reset' it when the new string is
> assigned to $buffer? What would be the best way to do this?
>
> Thanks,
>
> --arz

Perl has a FIFO for just this, Named Pipe.





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

Date: 04 Feb 2008 00:39:18 GMT
From: xhoster@gmail.com
Subject: Re: circular buffering using substr() ?
Message-Id: <20080203193921.380$AL@newsreader.com>

arz <azwemmer@gmail.com> wrote:
>
> Ah I'm sorry, I was typing the code from memory,

Yeah, don't do that.  Since we have no idea what your actual code is,
we can have no idea what the problem is.

> just outlining the
> idea. The statement
>   $buffer .= substr($buffer, $offset) should of course be an
> assignment:
>   $buffer = substr($buffer, $offset).

In my hands, when correctly incorporated into a loop, this does not leak
memory.


> That was a typo. Same for the syswrite(), which I do use correctly in
> the code.
>
> The 'circular' lies in the fact that I assign $buffer to a substring
> of itself, thereby 'moving' the buffer pointer, while at the same time
> appending data to the buffer on every read...

You do not move the buffer pointer, you copy a certain part of the buffer
to someplace else.  Perl does not look deeply enough to realize that the
left-hand side and the right-hand side of the assignment both involve the
same variable in a way that allows it to be optimized.

To do the Perl equivalent of moving the pointer without moving the data
iself, you need to make what you want more explicit:

substr($buffer, 0, $offset, "");

At some point, this copies/moves the whole buffer to avoid leaking memory,
but it only does so occasionally and so is much faster (when $buffer is
big) than the assignment method, which does it every time.

As for your "original" code, offset should not be used in the syswrite.
The whole point of the substr thing is to throw away the data once written,
so the data yet to be written is always the first stuff in the string,
needing no offset (or an offset of zero).

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


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

Date: 04 Feb 2008 08:00:09 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: Need regexp to parse newsgroups
Message-Id: <slrnfqdhg8.v9.abigail@alexandra.abigail.be>

                                   _
M.L. (me@privacy.invalid) wrote on VCCLXX September MCMXCIII in
<URL:news:ANvpj.7090$Rg1.6593@nlpi068.nbdc.sbc.com>:
{}  Hi. Using the Xref header field of newsgroup messages, I need a regexp 
{}  that will allow me to drop all newsgroups in that list containing the 
{}  word "general". I need one that works, and to find why the one I created 
{}  isn't working.
{}  
{}  Example Xref:
{}  Xref: prodigy.net general.soc:449517 chi.general:641065 
{}  soc.general.sci:329682 francom.chatting.generale:152591
{}  
{}  My regexp attempt passes general.soc (good) but not soc.general (bad) or 
{}  chi.general (good):
{}  .*[^(chi\.)(microsoft\.public\.windowsxp\.)]general.*
{}  
{}  In short, I want the following newsgroup examples to pass the Xref 
{}  filter so they can be dropped:
{}  general.soc
{}  soc.general
{}  soc.general.sci
{}  francom.chatting.generale
{}  
{}  I want the following two to fail so they will be retained:
{}  chi.general
{}  microsoft.public.windowsxp.general
{}  
{}  Any assistance would be greatly appreciated. Thanks in advance. 


Untested:

/(?!\Qchi.general\E|\Qmicrosoft.public.windowsxp.general\E)(?<!\S)\S*general\S*/

Of course, it would be much simpler if you'd have the newsgroups in a list,
then I'd do:

  @groups = grep {$_ eq 'chi.general'                        ||
                  $_ eq 'microsoft.public.windowsxp.general' ||
                 !/general/} @groups;


Abigail
-- 
BEGIN {print "Just "   }
INIT  {print "Perl "   }
CHECK {print "another "}
END   {print "Hacker\n"}


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

Date: Mon, 4 Feb 2008 05:42:16 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Mon Feb  4 2008
Message-Id: <Jvp96G.9yy@zorch.sf-bay.org>

The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN).  You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.

Acme-EyeDrops-1.52
http://search.cpan.org/~asavige/Acme-EyeDrops-1.52/
Visual Programming in Perl 
----
App-Env-0.06
http://search.cpan.org/~djerius/App-Env-0.06/
manage application specific environments 
----
Archive-Rar-1.94
http://search.cpan.org/~smueller/Archive-Rar-1.94/
Interface with the 'rar' command 
----
CPAN-SQLite-0.19
http://search.cpan.org/~rkobes/CPAN-SQLite-0.19/
maintain and search a minimal CPAN database 
----
Cache-FastMmap-1.25
http://search.cpan.org/~robm/Cache-FastMmap-1.25/
Uses an mmap'ed file to act as a shared memory interprocess cache 
----
Catalyst-Plugin-StackTrace-0.07
http://search.cpan.org/~mstrout/Catalyst-Plugin-StackTrace-0.07/
Display a stack trace on the debug screen 
----
Convert-Temperature-0.03
http://search.cpan.org/~mopy/Convert-Temperature-0.03/
Convert Temperatures 
----
Data-CPAN-DSLIP-Explain-0.01
http://search.cpan.org/~zoffix/Data-CPAN-DSLIP-Explain-0.01/
"decrypts" CPAN module DSLIP code 
----
Devel-PerlySense-0.0143
http://search.cpan.org/~johanl/Devel-PerlySense-0.0143/
IntelliSense for Perl 
----
FCGI-Engine-0.03
http://search.cpan.org/~stevan/FCGI-Engine-0.03/
A flexible engine for running FCGI-based applications 
----
Fey-Loader-0.02
http://search.cpan.org/~drolsky/Fey-Loader-0.02/
Load your schema defintion from a DBMS 
----
Fey-Loader-0.03
http://search.cpan.org/~drolsky/Fey-Loader-0.03/
Load your schema defintion from a DBMS 
----
File-HomeDir-0.69
http://search.cpan.org/~adamk/File-HomeDir-0.69/
Find your home and other directories, on any platform 
----
File-Set-1.02
http://search.cpan.org/~robm/File-Set-1.02/
Mange/build a set of files from a list of file/directories 
----
Fuzz-0.06.1
http://search.cpan.org/~ksuri/Fuzz-0.06.1/
network services fuzzing interface. 
----
GSSAPI-0.25
http://search.cpan.org/~agrolms/GSSAPI-0.25/
Perl extension providing access to the GSSAPIv2 library 
----
Games-Word-0.01
http://search.cpan.org/~doy/Games-Word-0.01/
utility functions for writing word games 
----
Geo-Coordinates-Converter-iArea-0.07
http://search.cpan.org/~tokuhirom/Geo-Coordinates-Converter-iArea-0.07/
get center point from iArea 
----
Geography-JapanesePrefectures-0.06
http://search.cpan.org/~tokuhirom/Geography-JapanesePrefectures-0.06/
Japanese Prefectures Data. 
----
HTTP-MobileAgent-Plugin-Charset-0.03
http://search.cpan.org/~tokuhirom/HTTP-MobileAgent-Plugin-Charset-0.03/
Encode::JP::Mobile friendly 
----
IPC-MorseSignals-0.09
http://search.cpan.org/~vpit/IPC-MorseSignals-0.09/
Communicate between processes with Morse signals. 
----
Language-Befunge-Vector-XS-1.0.0
http://search.cpan.org/~jquelin/Language-Befunge-Vector-XS-1.0.0/
Language::Befunge::Vector rewritten for speed 
----
Log-Log4perl-Layout-PatternLayout-Elapsed-0.01
http://search.cpan.org/~potyl/Log-Log4perl-Layout-PatternLayout-Elapsed-0.01/
Logs the time elapsed between the last log event 
----
Math-Factor-XS-0.35
http://search.cpan.org/~schubiger/Math-Factor-XS-0.35/
Factorise numbers and calculate matching multiplications 
----
MooseX-Singleton-0.05
http://search.cpan.org/~rjbs/MooseX-Singleton-0.05/
turn your Moose class into a singleton 
----
Net-Citadel-0.02
http://search.cpan.org/~drrho/Net-Citadel-0.02/
Citadel.org protocol coverage 
----
Net-DownloadMirror-0.06
http://search.cpan.org/~knorr/Net-DownloadMirror-0.06/
Perl extension for mirroring a remote location via FTP to the local directory 
----
Net-FTP-Recursive-2.01
http://search.cpan.org/~jdlee/Net-FTP-Recursive-2.01/
Recursive FTP Client class 
----
Net-MirrorDir-0.09
http://search.cpan.org/~knorr/Net-MirrorDir-0.09/
Perl extension for compare local-directories and remote-directories with each other 
----
Net-SocialGraph-1.0
http://search.cpan.org/~simonw/Net-SocialGraph-1.0/
interact with Google's Social Graph API 
----
Net-SocialGraph-1.1
http://search.cpan.org/~simonw/Net-SocialGraph-1.1/
interact with Google's Social Graph API 
----
Net-UploadMirror-0.09
http://search.cpan.org/~knorr/Net-UploadMirror-0.09/
Perl extension for mirroring a local directory via FTP to the remote location 
----
PAR-Dist-0.26
http://search.cpan.org/~smueller/PAR-Dist-0.26/
Create and manipulate PAR distributions 
----
POE-Component-IRC-Plugin-PAUSE-RecentUploads-0.01
http://search.cpan.org/~zoffix/POE-Component-IRC-Plugin-PAUSE-RecentUploads-0.01/
PoCo::IRC plugin for reporting recent uploads to "/pause.perl.org" in http:: 
----
POE-Component-WWW-PAUSE-RecentUploads-Tail-0.03
http://search.cpan.org/~zoffix/POE-Component-WWW-PAUSE-RecentUploads-Tail-0.03/
tail recent uploads to PAUSE. 
----
Perl6-Doc-0.35
http://search.cpan.org/~lichtkind/Perl6-Doc-0.35/
all useful Perl 6 Docs in your command line 
----
SNMP-Class-0.08
http://search.cpan.org/~aduitsis/SNMP-Class-0.08/
A convenience class around the NetSNMP perl modules. 
----
String-CaseProfile-0.05
http://search.cpan.org/~enell/String-CaseProfile-0.05/
Get/Set the letter case profile of a string 
----
Syntax-Highlight-Engine-Kate-0.03
http://search.cpan.org/~hanje/Syntax-Highlight-Engine-Kate-0.03/
a port to Perl of the syntax highlight engine of the Kate texteditor. 
----
Template-Like-0.09
http://search.cpan.org/~askadna/Template-Like-0.09/
Lightweight Template Engine. 
----
Template-Like-0.10
http://search.cpan.org/~askadna/Template-Like-0.10/
Lightweight Template Engine. 
----
Test-Dir-1.005
http://search.cpan.org/~mthurn/Test-Dir-1.005/
test directory attributes 
----
Tk-Pod-0.9938
http://search.cpan.org/~srezic/Tk-Pod-0.9938/
Pod browser toplevel widget 
----
XML-Mini-1.3.4
http://search.cpan.org/~pdeegan/XML-Mini-1.3.4/
Perl implementation of the XML::Mini XML create/parse interface. 
----
XML-Mini-1.35
http://search.cpan.org/~pdeegan/XML-Mini-1.35/
Perl implementation of the XML::Mini XML create/parse interface. 
----
XML-Mini-1.36
http://search.cpan.org/~pdeegan/XML-Mini-1.36/
Perl implementation of the XML::Mini XML create/parse interface. 
----
mobirc-0.04
http://search.cpan.org/~tokuhirom/mobirc-0.04/
modern IRC to HTTP gateway 


If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.

This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
  http://www.stonehenge.com/merlyn/LinuxMag/col82.html

print "Just another Perl hacker," # the original

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Sun, 03 Feb 2008 16:58:11 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: perl - array functions (union, intersection, difference, aonly,  bonly)  input problems.
Message-Id: <87sl0a3ucs.fsf@zeekat.nl>

inetquestion <inetquestion@hotmail.com> writes:

> @ArrayA = (1, 3, 5, 6, 7, 8, a, b, c, d, e, f, g, h, i, j, k, l, o, p,
> t, u, v, w, x, z);

m, q, s and y are operators. You really should quote your strings,
probably using qw() in this instance:

my @ArrayA = qw(m q s y);

You really should use strict.

http://perldoc.perl.org/strict.html

Joost.



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

Date: Sun, 3 Feb 2008 07:54:09 -0800 (PST)
From: inetquestion <inetquestion@hotmail.com>
Subject: perl - array functions (union, intersection, difference, aonly,  bonly)  input problems.
Message-Id: <8e845ec3-f1d9-43a0-8937-425ceaeef4f8@z17g2000hsg.googlegroups.com>

The following perl script computes: union, difference, intersection,
and elements which only exist in each of the arrays passed as inputs.
However If either of the original arrays have the letters: m, q, s, or
y the script fails.  Anyone have any suggestions as to what is going
on here?

-Inet






#!/usr/bin/perl

### Using the following letters in either array cause errors:  m, q,
s, y

@ArrayA = (1, 3, 5, 6, 7, 8, a, b, c, d, e, f, g, h, i, j, k, l, o, p,
t, u, v, w, x, z);
@ArrayB = (2, 3, 5, 7, 9, x, z, n, r, t, u, v, A, B, C, D);

my ($union_ref, $isec_ref, $diff_ref, $aonly_ref, $bonly_ref) =
ArrayFunctions(\@ArrayA, \@ArrayB);

print "A: @ArrayA\n";
print "B: @ArrayB\n\n";
print "Union: @$union_ref\n";
print "Inter: @$isec_ref\n";
print "Diff:  @$diff_ref\n";
print "Aonly: @$aonly_ref\n";
print "Bonly: @$bonly_ref\n";




sub ArrayFunctions
{
    my $a_ref = shift;                                  # reference to
input array A
    my @a = @$a_ref;                                    # input array
A
    my $b_ref = shift;                                  # reference to
input array B
    my @b = @$b_ref;                                    # input array
B

    @Aseen{@a} = ();                                    # lookup table
    @Bseen{@b} = ();                                    # lookup table

    @isec = @diff = @union = @aonly = @bonly = ();      # create null
arrays
    foreach $e (@a, @b) { $count{$e}++ }                # put all
items in hash table

    foreach $e (keys %count) {                          # interate
over each key of hash table
        push(@union, $e);                               # keys of hash
table = union
        if ($count{$e} == 2) {
            push @isec, $e;                             # seen more
than once = intersection
        } else {
            push @diff, $e;                             # seen once =
difference
            push(@aonly, $e) unless exists $Bseen{$e};  # seen once +
from A = Aonly
            push(@bonly, $e) unless exists $Aseen{$e};  # seen once +
from B = Bonly
        }
    }
    return (\@union, \@isec, \@diff, \@aonly, \@bonly); # return
referecnes to computed arrays
}


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

Date: Sun, 3 Feb 2008 08:10:25 -0800 (PST)
From: inetquestion <inetquestion@hotmail.com>
Subject: Re: perl - array functions (union, intersection, difference, aonly,  bonly) input problems.
Message-Id: <64c33efd-ff0e-4fdd-84f4-3ef558a0246d@v17g2000hsa.googlegroups.com>


That fixed the problem.   Thanks for the quick reply!


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

Date: Sun, 03 Feb 2008 16:43:49 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: perl - array functions (union, intersection, difference, aonly, bonly)  input problems.
Message-Id: <9bmpj.4922$C61.4916@edtnps89>

Joost Diepenmaat wrote:
> inetquestion <inetquestion@hotmail.com> writes:
> 
>> @ArrayA = (1, 3, 5, 6, 7, 8, a, b, c, d, e, f, g, h, i, j, k, l, o, p,
>> t, u, v, w, x, z);
> 
> m, q, s and y are operators. You really should quote your strings,
> probably using qw() in this instance:

And don't forget the x operator.

> my @ArrayA = qw(m q s y);
> 
> You really should use strict.


John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


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

Date: Mon, 04 Feb 2008 01:53:19 -0000
From: Chris Mattern <syscjm@sumire.gwu.edu>
Subject: Re: Perl on Linux and AIX
Message-Id: <slrnfqcs0d.9eh.syscjm@sumire.gwu.edu>

On 2008-02-02, Rob Simpson <here@my.pc> wrote:
> On Sat, 02 Feb 2008 03:33:12 +0000, Uri Guttman propped his eyelids open
> with toothpicks and wrote:
>
>> useless use of a herd of cats award!
>> 
> Definitely not a "herd" of cats.
>
> There are a number names for a group of cats, but my favorite is a 
> "glorying" of cats.
>
But "a clowder of cats" is the generally accepted term.

-- 
             Christopher Mattern

NOTICE
Thank you for noticing this new notice
Your noticing it has been noted
And will be reported to the authorities


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

Date: Mon, 4 Feb 2008 02:51:26 +0800
From: "mynews" <sonet.all@gmail.com>
Subject: perl v5.8.8 arm-linux
Message-Id: <fo52f1$hoc$1@netnews.hinet.net>

Where can find perl v5.8.8 arm-linux ?
I just can find perl v5.8.0 arm-linux. 




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

Date: Sun, 3 Feb 2008 17:13:24 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: submitting a form when two forms with the same name
Message-Id: <ka9h75-a51.ln1@osiris.mauzo.dyndns.org>
Keywords: x-No-archive:yes


Quoth "Nospam" <nospam@nospam.com>:
> 
> Trying to submit the second form, when there are two forms on the page both 
> called "submit" using www::Mechanize and Html::Form
> 
> the first form html is: <input type="submit" name="submit" value="Go" />
> 
> The second form's: <input type=submit name=submit value="  S  E  N  D  ">

Try

    $mech->click_button(value => '  S  E  N  D  ');

Ben



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

Date: Sun, 3 Feb 2008 21:56:00 -0800 (PST)
From: clearguy02@yahoo.com
Subject: To strip off a prefix in a variable..
Message-Id: <b77e9b2f-1f46-40ca-8c6f-6f4ace4ea39d@i29g2000prf.googlegroups.com>

Hi all,

I have the following variable:

$a = "xxx_active_jsmith";

Now I want to strip ohf the prefix, xxx_active_ and want to store only
the id, jsmith into the variable $b. That means, it should be $b =
"jsmith";

How can I do that?

Thanks
J


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

Date: Mon, 4 Feb 2008 08:25:28 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: To strip off a prefix in a variable..
Message-Id: <pan.2008.02.04.07.25.28@rtij.nl.invlalid>

On Sun, 03 Feb 2008 21:56:00 -0800, clearguy02 wrote:

> Hi all,
> 
> I have the following variable:
> 
> $a = "xxx_active_jsmith";
> 
> Now I want to strip ohf the prefix, xxx_active_ and want to store only
> the id, jsmith into the variable $b. That means, it should be $b =
> "jsmith";
> 
> How can I do that?

$a =~ s/^<a-regexp-for-the-prefic>//;

HTH,
M4


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

Date: Mon, 04 Feb 2008 08:57:50 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: To strip off a prefix in a variable..
Message-Id: <60nusfF1rah82U1@mid.individual.net>

clearguy02@yahoo.com wrote:
> I have the following variable:
> 
> $a = "xxx_active_jsmith";
> 
> Now I want to strip ohf the prefix, xxx_active_ and want to store only
> the id, jsmith into the variable $b. That means, it should be $b =
> "jsmith";
> 
> How can I do that?

     ($b) = $a =~ /([a-z]+)$/;

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 V11 Issue 1254
***************************************


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