[12744] in Perl-Users-Digest
Perl-Users Digest, Issue: 154 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 15 12:17:26 1999
Date: Thu, 15 Jul 1999 09:10:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 15 Jul 1999 Volume: 9 Number: 154
Today's topics:
perl implementation: list data structure <cadet@bu.edu>
Re: perl implementation: list data structure <tchrist@mox.perl.com>
PERL OPPORTUNITIES!! CHICAGO sadftef@my-deja.com
regular expression h0444vcs@rz.hu-berlin.de
Re: storing reference to array? <jeffp@crusoe.net>
Re: What's faster: GDBM or Storable rlw_ctx@my-deja.com
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 15 Jul 1999 10:08:53 -0400
From: David Bakhash <cadet@bu.edu>
Subject: perl implementation: list data structure
Message-Id: <cxj4sj6t37u.fsf@acs5.bu.edu>
Hi,
I'm a bit baffled by Perls lists (arrays). I noticed that they have the
following features:
0) random access of list elements
1) you can take the length of the list
2) you can get/remove the first of the list
3) you can get/remove the last of the list
# 4) you can insert elements into the list
5) circular access of elements (e.g. $list[-3])
6) dynamically resize the list
I was wondering if Perl specified the order of these operations. For example,
when you take the length, does it have to count down to the end? Same for
`pop': does it already know where the end is? or is that an O(1) operation?
If it is O(1) in time, is that part of the "Perl specification"?
How about random accesses? Are they O(1), like C arrays, or O(n), like linked
lists?
When you insert, is this a simple modification of a couple of pointers? or
does it have more overhead, like copying a chunk of the sequence?
Are these regular linked-lists? doubly linked-lists, structs containing stuff
like length, last-node...?
dave
------------------------------
Date: 15 Jul 1999 09:51:51 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: perl implementation: list data structure
Message-Id: <378e0397@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc, David Bakhash <cadet@bu.edu> writes:
:I'm a bit baffled by Perls lists (arrays). I noticed that they have the
:following features:
:
:0) random access of list elements
:1) you can take the length of the list
:2) you can get/remove the first of the list
:3) you can get/remove the last of the list
:# 4) you can insert elements into the list
:5) circular access of elements (e.g. $list[-3])
:6) dynamically resize the list
:
:I was wondering if Perl specified the order of these operations. For example,
:when you take the length, does it have to count down to the end? Same for
:`pop': does it already know where the end is? or is that an O(1) operation?
:If it is O(1) in time, is that part of the "Perl specification"?
:
:How about random accesses? Are they O(1), like C arrays, or O(n), like linked
:lists?
:
:When you insert, is this a simple modification of a couple of pointers? or
:does it have more overhead, like copying a chunk of the sequence?
:
:Are these regular linked-lists? doubly linked-lists, structs containing stuff
:like length, last-node...?
/* av.h
*
* Copyright (c) 1991-1999, Larry Wall
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
struct xpvav {
char* xav_array; /* pointer to first array element */
SSize_t xav_fill; /* Index of last element present */
SSize_t xav_max; /* Number of elements for which array has space */
IV xof_off; /* ptr is incremented by offset */
double xnv_nv; /* numeric value, if any */
MAGIC* xmg_magic; /* magic for scalar array */
HV* xmg_stash; /* class package */
SV** xav_alloc; /* pointer to malloced string */
SV* xav_arylen;
U8 xav_flags;
};
#define AVf_REAL 1 /* free old entries */
#define AVf_REIFY 2 /* can become real */
#define AVf_REUSED 4 /* got undeffed--don't turn old memory into SVs now */
#define Nullav Null(AV*)
#define AvARRAY(av) ((SV**)((XPVAV*) SvANY(av))->xav_array)
#define AvALLOC(av) ((XPVAV*) SvANY(av))->xav_alloc
#define AvMAX(av) ((XPVAV*) SvANY(av))->xav_max
#define AvFILLp(av) ((XPVAV*) SvANY(av))->xav_fill
#define AvARYLEN(av) ((XPVAV*) SvANY(av))->xav_arylen
#define AvFLAGS(av) ((XPVAV*) SvANY(av))->xav_flags
#define AvREAL(av) (AvFLAGS(av) & AVf_REAL)
#define AvREAL_on(av) (AvFLAGS(av) |= AVf_REAL)
#define AvREAL_off(av) (AvFLAGS(av) &= ~AVf_REAL)
#define AvREIFY(av) (AvFLAGS(av) & AVf_REIFY)
#define AvREIFY_on(av) (AvFLAGS(av) |= AVf_REIFY)
#define AvREIFY_off(av) (AvFLAGS(av) &= ~AVf_REIFY)
#define AvREUSED(av) (AvFLAGS(av) & AVf_REUSED)
#define AvREUSED_on(av) (AvFLAGS(av) |= AVf_REUSED)
#define AvREUSED_off(av) (AvFLAGS(av) &= ~AVf_REUSED)
#define AvREALISH(av) (AvFLAGS(av) & (AVf_REAL|AVf_REIFY))
#define AvFILL(av) ((SvRMAGICAL((SV *) (av))) \
? mg_size((SV *) av) : AvFILLp(av))
/* av.c
*
* Copyright (c) 1991-1999, Larry Wall
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
/*
* "...for the Entwives desired order, and plenty, and peace (by which they
* meant that things should remain where they had set them)." --Treebeard
*/
#include "EXTERN.h"
#include "perl.h"
void
av_reify(AV *av)
{
I32 key;
SV* sv;
if (AvREAL(av))
return;
#ifdef DEBUGGING
if (SvTIED_mg((SV*)av, 'P'))
warn("av_reify called on tied array");
#endif
key = AvMAX(av) + 1;
while (key > AvFILLp(av) + 1)
AvARRAY(av)[--key] = &PL_sv_undef;
while (key) {
sv = AvARRAY(av)[--key];
assert(sv);
if (sv != &PL_sv_undef) {
dTHR;
(void)SvREFCNT_inc(sv);
}
}
key = AvARRAY(av) - AvALLOC(av);
while (key)
AvALLOC(av)[--key] = &PL_sv_undef;
AvREIFY_off(av);
AvREAL_on(av);
}
void
av_extend(AV *av, I32 key)
{
dTHR; /* only necessary if we have to extend stack */
MAGIC *mg;
if (mg = SvTIED_mg((SV*)av, 'P')) {
dSP;
ENTER;
SAVETMPS;
PUSHSTACKi(PERLSI_MAGIC);
PUSHMARK(SP);
EXTEND(SP,2);
PUSHs(SvTIED_obj((SV*)av, mg));
PUSHs(sv_2mortal(newSViv(key+1)));
PUTBACK;
perl_call_method("EXTEND", G_SCALAR|G_DISCARD);
POPSTACK;
FREETMPS;
LEAVE;
return;
}
if (key > AvMAX(av)) {
SV** ary;
I32 tmp;
I32 newmax;
if (AvALLOC(av) != AvARRAY(av)) {
ary = AvALLOC(av) + AvFILLp(av) + 1;
tmp = AvARRAY(av) - AvALLOC(av);
Move(AvARRAY(av), AvALLOC(av), AvFILLp(av)+1, SV*);
AvMAX(av) += tmp;
SvPVX(av) = (char*)AvALLOC(av);
if (AvREAL(av)) {
while (tmp)
ary[--tmp] = &PL_sv_undef;
}
if (key > AvMAX(av) - 10) {
newmax = key + AvMAX(av);
goto resize;
}
}
else {
if (AvALLOC(av)) {
#ifndef STRANGE_MALLOC
U32 bytes;
#endif
#if defined(MYMALLOC) && !defined(PURIFY) && !defined(LEAKTEST)
newmax = malloced_size((void*)AvALLOC(av))/sizeof(SV*) - 1;
if (key <= newmax)
goto resized;
#endif
newmax = key + AvMAX(av) / 5;
resize:
#if defined(STRANGE_MALLOC) || defined(MYMALLOC)
Renew(AvALLOC(av),newmax+1, SV*);
#else
bytes = (newmax + 1) * sizeof(SV*);
#define MALLOC_OVERHEAD 16
tmp = MALLOC_OVERHEAD;
while (tmp - MALLOC_OVERHEAD < bytes)
tmp += tmp;
tmp -= MALLOC_OVERHEAD;
tmp /= sizeof(SV*);
assert(tmp > newmax);
newmax = tmp - 1;
New(2,ary, newmax+1, SV*);
Copy(AvALLOC(av), ary, AvMAX(av)+1, SV*);
if (AvMAX(av) > 64)
offer_nice_chunk(AvALLOC(av), (AvMAX(av)+1) * sizeof(SV*));
else
Safefree(AvALLOC(av));
AvALLOC(av) = ary;
#endif
resized:
ary = AvALLOC(av) + AvMAX(av) + 1;
tmp = newmax - AvMAX(av);
if (av == PL_curstack) { /* Oops, grew stack (via av_store()?) */
PL_stack_sp = AvALLOC(av) + (PL_stack_sp - PL_stack_base);
PL_stack_base = AvALLOC(av);
PL_stack_max = PL_stack_base + newmax;
}
}
else {
newmax = key < 3 ? 3 : key;
New(2,AvALLOC(av), newmax+1, SV*);
ary = AvALLOC(av) + 1;
tmp = newmax;
AvALLOC(av)[0] = &PL_sv_undef; /* For the stacks */
}
if (AvREAL(av)) {
while (tmp)
ary[--tmp] = &PL_sv_undef;
}
SvPVX(av) = (char*)AvALLOC(av);
AvMAX(av) = newmax;
}
}
}
SV**
av_fetch(register AV *av, I32 key, I32 lval)
{
SV *sv;
if (!av)
return 0;
if (key < 0) {
key += AvFILL(av) + 1;
if (key < 0)
return 0;
}
if (SvRMAGICAL(av)) {
if (mg_find((SV*)av,'P') || mg_find((SV*)av,'D')) {
dTHR;
sv = sv_newmortal();
mg_copy((SV*)av, sv, 0, key);
PL_av_fetch_sv = sv;
return &PL_av_fetch_sv;
}
}
if (key > AvFILLp(av)) {
if (!lval)
return 0;
sv = NEWSV(5,0);
return av_store(av,key,sv);
}
if (AvARRAY(av)[key] == &PL_sv_undef) {
emptyness:
if (lval) {
sv = NEWSV(6,0);
return av_store(av,key,sv);
}
return 0;
}
else if (AvREIFY(av)
&& (!AvARRAY(av)[key] /* eg. @_ could have freed elts */
|| SvTYPE(AvARRAY(av)[key]) == SVTYPEMASK)) {
AvARRAY(av)[key] = &PL_sv_undef; /* 1/2 reify */
goto emptyness;
}
return &AvARRAY(av)[key];
}
SV**
av_store(register AV *av, I32 key, SV *val)
{
SV** ary;
U32 fill;
if (!av)
return 0;
if (!val)
val = &PL_sv_undef;
if (key < 0) {
key += AvFILL(av) + 1;
if (key < 0)
return 0;
}
if (SvREADONLY(av) && key >= AvFILL(av))
croak(PL_no_modify);
if (SvRMAGICAL(av)) {
if (mg_find((SV*)av,'P')) {
if (val != &PL_sv_undef) {
mg_copy((SV*)av, val, 0, key);
}
return 0;
}
}
if (!AvREAL(av) && AvREIFY(av))
av_reify(av);
if (key > AvMAX(av))
av_extend(av,key);
ary = AvARRAY(av);
if (AvFILLp(av) < key) {
if (!AvREAL(av)) {
dTHR;
if (av == PL_curstack && key > PL_stack_sp - PL_stack_base)
PL_stack_sp = PL_stack_base + key; /* XPUSH in disguise */
do
ary[++AvFILLp(av)] = &PL_sv_undef;
while (AvFILLp(av) < key);
}
AvFILLp(av) = key;
}
else if (AvREAL(av))
SvREFCNT_dec(ary[key]);
ary[key] = val;
if (SvSMAGICAL(av)) {
if (val != &PL_sv_undef) {
MAGIC* mg = SvMAGIC(av);
sv_magic(val, (SV*)av, toLOWER(mg->mg_type), 0, key);
}
mg_set((SV*)av);
}
return &ary[key];
}
AV *
newAV(void)
{
register AV *av;
av = (AV*)NEWSV(3,0);
sv_upgrade((SV *)av, SVt_PVAV);
AvREAL_on(av);
AvALLOC(av) = 0;
SvPVX(av) = 0;
AvMAX(av) = AvFILLp(av) = -1;
return av;
}
AV *
av_make(register I32 size, register SV **strp)
{
register AV *av;
register I32 i;
register SV** ary;
av = (AV*)NEWSV(8,0);
sv_upgrade((SV *) av,SVt_PVAV);
AvFLAGS(av) = AVf_REAL;
if (size) { /* `defined' was returning undef for size==0 anyway. */
New(4,ary,size,SV*);
AvALLOC(av) = ary;
SvPVX(av) = (char*)ary;
AvFILLp(av) = size - 1;
AvMAX(av) = size - 1;
for (i = 0; i < size; i++) {
assert (*strp);
ary[i] = NEWSV(7,0);
sv_setsv(ary[i], *strp);
strp++;
}
}
return av;
}
AV *
av_fake(register I32 size, register SV **strp)
{
register AV *av;
register SV** ary;
av = (AV*)NEWSV(9,0);
sv_upgrade((SV *)av, SVt_PVAV);
New(4,ary,size+1,SV*);
AvALLOC(av) = ary;
Copy(strp,ary,size,SV*);
AvFLAGS(av) = AVf_REIFY;
SvPVX(av) = (char*)ary;
AvFILLp(av) = size - 1;
AvMAX(av) = size - 1;
while (size--) {
assert (*strp);
SvTEMP_off(*strp);
strp++;
}
return av;
}
void
av_clear(register AV *av)
{
register I32 key;
SV** ary;
#ifdef DEBUGGING
if (SvREFCNT(av) <= 0) {
warn("Attempt to clear deleted array");
}
#endif
if (!av)
return;
/*SUPPRESS 560*/
if (SvREADONLY(av))
croak(PL_no_modify);
/* Give any tie a chance to cleanup first */
if (SvRMAGICAL(av))
mg_clear((SV*)av);
if (AvMAX(av) < 0)
return;
if (AvREAL(av)) {
ary = AvARRAY(av);
key = AvFILLp(av) + 1;
while (key) {
SvREFCNT_dec(ary[--key]);
ary[key] = &PL_sv_undef;
}
}
if (key = AvARRAY(av) - AvALLOC(av)) {
AvMAX(av) += key;
SvPVX(av) = (char*)AvALLOC(av);
}
AvFILLp(av) = -1;
}
void
av_undef(register AV *av)
{
register I32 key;
if (!av)
return;
/*SUPPRESS 560*/
/* Give any tie a chance to cleanup first */
if (SvTIED_mg((SV*)av, 'P'))
av_fill(av, -1); /* mg_clear() ? */
if (AvREAL(av)) {
key = AvFILLp(av) + 1;
while (key)
SvREFCNT_dec(AvARRAY(av)[--key]);
}
Safefree(AvALLOC(av));
AvALLOC(av) = 0;
SvPVX(av) = 0;
AvMAX(av) = AvFILLp(av) = -1;
if (AvARYLEN(av)) {
SvREFCNT_dec(AvARYLEN(av));
AvARYLEN(av) = 0;
}
}
void
av_push(register AV *av, SV *val)
{
MAGIC *mg;
if (!av)
return;
if (SvREADONLY(av))
croak(PL_no_modify);
if (mg = SvTIED_mg((SV*)av, 'P')) {
dSP;
PUSHSTACKi(PERLSI_MAGIC);
PUSHMARK(SP);
EXTEND(SP,2);
PUSHs(SvTIED_obj((SV*)av, mg));
PUSHs(val);
PUTBACK;
ENTER;
perl_call_method("PUSH", G_SCALAR|G_DISCARD);
LEAVE;
POPSTACK;
return;
}
av_store(av,AvFILLp(av)+1,val);
}
SV *
av_pop(register AV *av)
{
SV *retval;
MAGIC* mg;
if (!av || AvFILL(av) < 0)
return &PL_sv_undef;
if (SvREADONLY(av))
croak(PL_no_modify);
if (mg = SvTIED_mg((SV*)av, 'P')) {
dSP;
PUSHSTACKi(PERLSI_MAGIC);
PUSHMARK(SP);
XPUSHs(SvTIED_obj((SV*)av, mg));
PUTBACK;
ENTER;
if (perl_call_method("POP", G_SCALAR)) {
retval = newSVsv(*PL_stack_sp--);
} else {
retval = &PL_sv_undef;
}
LEAVE;
POPSTACK;
return retval;
}
retval = AvARRAY(av)[AvFILLp(av)];
AvARRAY(av)[AvFILLp(av)--] = &PL_sv_undef;
if (SvSMAGICAL(av))
mg_set((SV*)av);
return retval;
}
void
av_unshift(register AV *av, register I32 num)
{
register I32 i;
register SV **ary;
MAGIC* mg;
if (!av || num <= 0)
return;
if (SvREADONLY(av))
croak(PL_no_modify);
if (mg = SvTIED_mg((SV*)av, 'P')) {
dSP;
PUSHSTACKi(PERLSI_MAGIC);
PUSHMARK(SP);
EXTEND(SP,1+num);
PUSHs(SvTIED_obj((SV*)av, mg));
while (num-- > 0) {
PUSHs(&PL_sv_undef);
}
PUTBACK;
ENTER;
perl_call_method("UNSHIFT", G_SCALAR|G_DISCARD);
LEAVE;
POPSTACK;
return;
}
if (!AvREAL(av) && AvREIFY(av))
av_reify(av);
i = AvARRAY(av) - AvALLOC(av);
if (i) {
if (i > num)
i = num;
num -= i;
AvMAX(av) += i;
AvFILLp(av) += i;
SvPVX(av) = (char*)(AvARRAY(av) - i);
}
if (num) {
i = AvFILLp(av);
av_extend(av, i + num);
AvFILLp(av) += num;
ary = AvARRAY(av);
Move(ary, ary + num, i + 1, SV*);
do {
ary[--num] = &PL_sv_undef;
} while (num);
}
}
SV *
av_shift(register AV *av)
{
SV *retval;
MAGIC* mg;
if (!av || AvFILL(av) < 0)
return &PL_sv_undef;
if (SvREADONLY(av))
croak(PL_no_modify);
if (mg = SvTIED_mg((SV*)av, 'P')) {
dSP;
PUSHSTACKi(PERLSI_MAGIC);
PUSHMARK(SP);
XPUSHs(SvTIED_obj((SV*)av, mg));
PUTBACK;
ENTER;
if (perl_call_method("SHIFT", G_SCALAR)) {
retval = newSVsv(*PL_stack_sp--);
} else {
retval = &PL_sv_undef;
}
LEAVE;
POPSTACK;
return retval;
}
retval = *AvARRAY(av);
if (AvREAL(av))
*AvARRAY(av) = &PL_sv_undef;
SvPVX(av) = (char*)(AvARRAY(av) + 1);
AvMAX(av)--;
AvFILLp(av)--;
if (SvSMAGICAL(av))
mg_set((SV*)av);
return retval;
}
I32
av_len(register AV *av)
{
return AvFILL(av);
}
void
av_fill(register AV *av, I32 fill)
{
MAGIC *mg;
if (!av)
croak("panic: null array");
if (fill < 0)
fill = -1;
if (mg = SvTIED_mg((SV*)av, 'P')) {
dSP;
ENTER;
SAVETMPS;
PUSHSTACKi(PERLSI_MAGIC);
PUSHMARK(SP);
EXTEND(SP,2);
PUSHs(SvTIED_obj((SV*)av, mg));
PUSHs(sv_2mortal(newSViv(fill+1)));
PUTBACK;
perl_call_method("STORESIZE", G_SCALAR|G_DISCARD);
POPSTACK;
FREETMPS;
LEAVE;
return;
}
if (fill <= AvMAX(av)) {
I32 key = AvFILLp(av);
SV** ary = AvARRAY(av);
if (AvREAL(av)) {
while (key > fill) {
SvREFCNT_dec(ary[key]);
ary[key--] = &PL_sv_undef;
}
}
else {
while (key < fill)
ary[++key] = &PL_sv_undef;
}
AvFILLp(av) = fill;
if (SvSMAGICAL(av))
mg_set((SV*)av);
}
else
(void)av_store(av,fill,&PL_sv_undef);
}
/* AVHV: Support for treating arrays as if they were hashes. The
* first element of the array should be a hash reference that maps
* hash keys to array indices.
*/
STATIC I32
avhv_index_sv(SV* sv)
{
I32 index = SvIV(sv);
if (index < 1)
croak("Bad index while coercing array into hash");
return index;
}
HV*
avhv_keys(AV *av)
{
SV **keysp = av_fetch(av, 0, FALSE);
if (keysp) {
SV *sv = *keysp;
if (SvGMAGICAL(sv))
mg_get(sv);
if (SvROK(sv)) {
sv = SvRV(sv);
if (SvTYPE(sv) == SVt_PVHV)
return (HV*)sv;
}
}
croak("Can't coerce array into hash");
return Nullhv;
}
SV**
avhv_fetch_ent(AV *av, SV *keysv, I32 lval, U32 hash)
{
SV **indsvp;
HV *keys = avhv_keys(av);
HE *he;
he = hv_fetch_ent(keys, keysv, FALSE, hash);
if (!he)
croak("No such array field");
return av_fetch(av, avhv_index_sv(HeVAL(he)), lval);
}
bool
avhv_exists_ent(AV *av, SV *keysv, U32 hash)
{
HV *keys = avhv_keys(av);
return hv_exists_ent(keys, keysv, hash);
}
HE *
avhv_iternext(AV *av)
{
HV *keys = avhv_keys(av);
return hv_iternext(keys);
}
SV *
avhv_iterval(AV *av, register HE *entry)
{
SV *sv = hv_iterval(avhv_keys(av), entry);
return *av_fetch(av, avhv_index_sv(sv), TRUE);
}
--
It is Unix. It is possible to overcome any number of these bogus features. --pjw
------------------------------
Date: Thu, 15 Jul 1999 15:14:31 GMT
From: sadftef@my-deja.com
Subject: PERL OPPORTUNITIES!! CHICAGO
Message-Id: <7mktsa$ifd$1@nnrp1.deja.com>
Tribune is a leading media company with operations in television and
radio broadcasting, publishing, education and interactive ventures. We
are an industry leader in venture partnerships with new media companies.
Tribune ranked No. 1 among its industry peers for the second consecutive
year in Fortune's annual list of "America's Most Admired Companies". Our
businesses in 20 major markets reach more than 75 percent of U.S.
households every day.
What we do…
Tribune Information Systems and Tribune Interactive Media in partnership
with our user community is implementing key strategic core and
distributed applications as part of our Information Technology Strategic
Plan. This plan outlines a long-range blueprint for use of information
distributed applications as a competitive edge in the marketplace and to
position us as a dominant market force by the turn of the century. Part
of the strategy involves building a set of new integrated applications
encompassing leading edge technology. Our infrastructure includes the
latest mainframes, NT and UNIX servers, and PC workstations.
Applications include Oracle, Sybase, PeopleSoft, StoryServer, Novell,
Java, and Cisco router, as well as a full suite of Microsoft products.
ALL Position are located in Downtown Chicago unless otherwise noted.
Check us out http://www.tribjobs.com and apply on line!!!!
Tribune Company has a newly created business unit, Tribune Interactive.
This group of highly skilled technical professionals will be responsible
for all multimedia design, development, implementation and maintenance
for all of the Tribune Company's business units. This includes 17 TV
stations, 4 newspapers; radio stations and over 200 WWW sites. If you
are interested in joining this high-energy group, check us out at:
http://www.tribjobs.com. Then apply on line!!!!
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Thu, 15 Jul 1999 15:00:14 GMT
From: h0444vcs@rz.hu-berlin.de
Subject: regular expression
Message-Id: <7mkt1m$i46$1@nnrp1.deja.com>
Dear Participants,
I have an array consisting of lines.
Each line has different fields seperated by ":" (like /etc/passwd ).
@array = grep { !/$name/ } @array ;
would remove all entries in the array where $name appears.
But I want to ensure that only these entries are removed where
$name appears in a certain field of the line.
Many thanks for your consideration !
Markus Banach
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Thu, 15 Jul 1999 10:10:15 -0400
From: evil Japh <jeffp@crusoe.net>
Subject: Re: storing reference to array?
Message-Id: <Pine.GSO.4.10.9907151008370.23974-100000@crusoe.crusoe.net>
[posted & mailed]
On Thu, 15 Jul 1999, Brendan Reville wrote:
> I tried storing this "reference to an array" by saying:
> $message_ref = get(0);
> but I get: syntax error at test.pl line 16, near "$get("
Hmm, it sure looks from the error that you did NOT say:
$message_ref = get(0);
but rather:
$message_ref = $get(0);
Regardless, after reading the perlref man page (a good idea... read the
docs please), you'll find that this works well:
$message_ref = get(0);
@message = @$message_ref;
--
Jeff Pinyan (jeffp@crusoe.net)
www.crusoe.net/~jeffp
Crusoe Communications, Inc.
732-728-9800
www.crusoe.net
------------------------------
Date: Thu, 15 Jul 1999 15:30:44 GMT
From: rlw_ctx@my-deja.com
To: stupid@pobox.com
Subject: Re: What's faster: GDBM or Storable
Message-Id: <7mkur4$itt$1@nnrp1.deja.com>
In article <140719991333519487%stupid@pobox.com>,
Michael G Schwern <stupid@pobox.com> wrote:
> In article <7mhpfm$egs$1@nnrp1.deja.com>, <alexmc@my-deja.com> wrote:
> > Thanks very much. I quite liked MLDBM when I have used it.
> > It seemed much simpler than trying to deal with DBI and MySQL.
> > I am surprised that more people don't use it...
> Well, again, DBI and MLDBM do different things.
[...]
> As most applications need both abilities (Looking information up
> directly and searching) I tend to use DBI whenever possible over a DBM
> file unless my feature set is very well known at the start. The extra
> complexity is worth it.
>
> I've been toying for a while with the idea of writing DBD::DBM, a DBI
> driver for DBM files, basically for writing prototype programs where
> you don't want to bother setting up an SQL database so you fake it
> with a DBM file and then later on transparently switch over to
> something better.
I recall seeing a DBD::CSV that does what you describe - except, of
course, it uses a CSV file instead of a DBM file.
--
Ron Wilson
Connectex, LLC
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 99)
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V9 Issue 154
*************************************