[30415] in Perl-Users-Digest
Perl-Users Digest, Issue: 1658 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 19 06:09:45 2008
Date: Thu, 19 Jun 2008 03:09:09 -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, 19 Jun 2008 Volume: 11 Number: 1658
Today's topics:
Re: [regex] grep for chars in any order <dalessio@motorola.NOSPAM.com>
Re: [regex] grep for chars in any order <dalessio@motorola.NOSPAM.com>
Re: extract all hotmail email addresses in a file and s vippstar@gmail.com
Re: extract all hotmail email addresses in a file and s vippstar@gmail.com
Re: extract all hotmail email addresses in a file and s <dragnet\_@_/internalysis.com>
Re: extract all hotmail email addresses in a file and s <bc@freeuk.com>
Re: extract all hotmail email addresses in a file and s <bc@freeuk.com>
Re: extract all hotmail email addresses in a file and s <pfiland@mindspring.com>
Re: extract all hotmail email addresses in a file and s <m@rtij.nl.invlalid>
Re: File Locked After Close? <zen13097@zen.co.uk>
new CPAN modules on Thu Jun 19 2008 (Randal Schwartz)
Re: Wrtiting to a file in LDIF format <usenet@davidfilmer.com>
Re: Wrtiting to a file in LDIF format <akhilshri@gmail.com>
Re: Wrtiting to a file in LDIF format <m@rtij.nl.invlalid>
Re: Wrtiting to a file in LDIF format <akhilshri@gmail.com>
Re: Wrtiting to a file in LDIF format <akhilshri@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 18 Jun 2008 13:20:24 -0500
From: "Mario D'Alessio" <dalessio@motorola.NOSPAM.com>
Subject: Re: [regex] grep for chars in any order
Message-Id: <g3bk6a$i20$1@newshost.mot.com>
"viki" <vikimun@gmail.com> wrote in message
news:4a43915e-e84a-4fc8-a56f-507bcf79de4d@w7g2000hsa.googlegroups.com...
> How can I build regex that matches all characters of the string $STR
> in any order with .* added between any two characters: ?
> And without generating all N! transpositions (where N is length of
> $STR) ?
> Example.
> For $STR "abc", I want to match equivalent to:
> /(a.*b.*c)|(a.*c.*b)|(b.*a.*c)|(b.*c.*a)|(c.*a.*b)|(c.*b.*a)/
>
> Generating all transpositions is not feasible for larger legths of
> $STR.
> /[abc].*[abc].*[abc]/ is easy and fast but gives false positives.
> What is good solution ?
>
> Thanks
> vkm
The way I see the solution, you can have any of the $STR characters,
followed by .*, followed by another of any of the $STR characters:
/[$STR].*[$STR]/
Or am I missing something?
Mario
------------------------------
Date: Wed, 18 Jun 2008 13:22:08 -0500
From: "Mario D'Alessio" <dalessio@motorola.NOSPAM.com>
Subject: Re: [regex] grep for chars in any order
Message-Id: <g3bk9j$i30$1@newshost.mot.com>
Ignore my post. I realize my mistake. I missed the
part about the regex matching ALL of the characters.
Mario
"Mario D'Alessio" <dalessio@motorola.NOSPAM.com> wrote in message
news:g3bk6a$i20$1@newshost.mot.com...
>
> "viki" <vikimun@gmail.com> wrote in message
> news:4a43915e-e84a-4fc8-a56f-507bcf79de4d@w7g2000hsa.googlegroups.com...
>> How can I build regex that matches all characters of the string $STR
>> in any order with .* added between any two characters: ?
>> And without generating all N! transpositions (where N is length of
>> $STR) ?
>> Example.
>> For $STR "abc", I want to match equivalent to:
>> /(a.*b.*c)|(a.*c.*b)|(b.*a.*c)|(b.*c.*a)|(c.*a.*b)|(c.*b.*a)/
>>
>> Generating all transpositions is not feasible for larger legths of
>> $STR.
>> /[abc].*[abc].*[abc]/ is easy and fast but gives false positives.
>> What is good solution ?
>>
>> Thanks
>> vkm
>
> The way I see the solution, you can have any of the $STR characters,
> followed by .*, followed by another of any of the $STR characters:
>
> /[$STR].*[$STR]/
>
> Or am I missing something?
>
> Mario
>
>
------------------------------
Date: Wed, 18 Jun 2008 22:41:21 -0700 (PDT)
From: vippstar@gmail.com
Subject: Re: extract all hotmail email addresses in a file and store in separate file
Message-Id: <dd9d359d-321d-4a20-a2a4-83b0607c6a88@y21g2000hsf.googlegroups.com>
On Jun 19, 1:02 am, Tom=E1s =D3 h=C9ilidhe <t...@lavabit.com> wrote:
> On Jun 18, 8:33 pm, Dennis <dcho...@gmail.com> wrote:
>
> > 1. Strip out the " characters and just leave the email addresses on
> > each line.
>
> char const *const original =3D "\"b...@hotmail.com\"";
>
> char buf[50];
>
> strcpy(buf,original);
>
> buf[strlen(original) - 1] =3D 0;
That does not strip both of the " characters.
char const is confusing, and the second const is unnecessary.
fix:
const char *original =3D "\"...\"";
> > 2. extract out the hotmail addresses and store it into another file.
>
> Take the last 12 characters, make them all lowercase, and then compare
> with "@hotmail.com".
@ does not belong to C's basic character set, so, that's not possible.
------------------------------
Date: Thu, 19 Jun 2008 02:18:47 -0700 (PDT)
From: vippstar@gmail.com
Subject: Re: extract all hotmail email addresses in a file and store in separate file
Message-Id: <569670a8-4f4d-4101-ab7c-bcc50625ad94@l64g2000hse.googlegroups.com>
On Jun 19, 12:13 pm, "Bartc" <b...@freeuk.com> wrote:
> "Marc Bissonnette" <dragnet\_@_/internalysis.com> wrote in message
>
> news:Xns9AC29F465890dragnetinternalysisc@216.196.97.131...
>
> > pete <pfil...@mindspring.com> fell face-first on the keyboard. This was
> > the result:news:oeadnWrGl4RyQMTVnZ2dnUVZ_s7inZ2d@earthlink.com:
>
> >> Dennis wrote:
> >>> Hi, I have a text file that contents a list of email addresses like
> >>> this:
> >> /* BEGIN new.c output */
> >><snip 250+ lines of C >
> > Wow - All that just to separate @hotmail.com from anything else ? I'm
> > glad I stuck with perl :)
>
> I think pete just enjoys writing huge amounts of C code. Or showing off..
Or using concrete functions he has written in the past to write
concrete programs.
<snip>
------------------------------
Date: Wed, 18 Jun 2008 23:58:47 -0500
From: Marc Bissonnette <dragnet\_@_/internalysis.com>
Subject: Re: extract all hotmail email addresses in a file and store in separate file
Message-Id: <Xns9AC29F465890dragnetinternalysisc@216.196.97.131>
pete <pfiland@mindspring.com> fell face-first on the keyboard. This was
the result: news:oeadnWrGl4RyQMTVnZ2dnUVZ_s7inZ2d@earthlink.com:
> Dennis wrote:
>> Hi, I have a text file that contents a list of email addresses like
>> this:
>>
>> "foo@yahoo.com"
>> "tom@hotmail.com"
>> "jerry@gmail.com"
>> "tommy@apple.com"
>>
>> I like to
>>
>> 1. Strip out the " characters and just leave the email addresses on
>> each line.
>> 2. extract out the hotmail addresses and store it into another file.
>> The hotmail addresses in the original file would be deleted.
>>
>> Thanks for any help
>
> /* BEGIN new.c output */
>
> Original original file contents:
> "foo@yahoo.com"
> "tom@hotmail.com"
> "jerry@gmail.com"
> "tommy@apple.com"
>
> Final original file contents:
> foo@yahoo.com
> jerry@gmail.com
> tommy@apple.com
>
> Final other file contents:
> tom@hotmail.com
>
> /* END new.c output */
>
> /* BEGIN new.c */
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <limits.h>
>
> #define STRINGS \
> { "\"foo@yahoo.com\"", "\"tom@hotmail.com\"", \
> "\"jerry@gmail.com\"", "\"tommy@apple.com\""}
>
> struct list_node {
> struct list_node *next;
> void *data;
> };
>
> typedef struct list_node list_type;
>
> void squeeze(char *s1, const int s2);
> int get_line(char **lineptr, size_t *n, FILE *stream);
> int list_fputs(const list_type *node, FILE *stream);
> list_type *list_append
> (list_type **head, list_type *tail, void *data, size_t size);
> void list_free(list_type *node, void (*free_data)(void *));
>
> int main (void)
> {
> int rc;
> size_t n;
> char fn[2][L_tmpnam];
> FILE *fp[2];
> char *string[] = STRINGS;
> size_t size = 0;
> char *buff = NULL;
> list_type *head = NULL;
> list_type *tail = NULL;
>
> puts("/* BEGIN new.c output */\n");
> /*
> ** Create input file
> */
> tmpnam(fn[0]);
> tmpnam(fn[1]);
> fp[0] = fopen(fn[0], "w");
> if (fp[0] == NULL) {
> fputs("fopen(fn[0]), \"w\") == NULL\n", stderr);
> exit(EXIT_FAILURE);
> }
> for (n = 0; n != sizeof string / sizeof *string; ++n) {
> fprintf(fp[0], "%s\n", string[n]);
> }
> fclose(fp[0]);
> /*
> ** Read input file into list
> */
> fp[0] = fopen(fn[0], "r");
> if (fp[0] == NULL) {
> fputs("fopen(fn[0], \"r\") == NULL\n", stderr);
> exit(EXIT_FAILURE);
> }
> while ((rc = get_line(&buff, &size, fp[0])) > 0) {
> tail = list_append(&head, tail, buff, rc);
> if (tail == NULL) {
> fputs("tail == NULL\n", stderr);
> break;
> }
> }
> fclose(fp[0]);
> /*
> ** Display input file contents
> */
> puts("Original original file contents:");
> list_fputs(head, stdout);
> putchar('\n');
> /*
> ** Strip out quotes from strings in memory
> */
> for (tail = head; tail != NULL; tail = tail -> next) {
> squeeze(tail -> data, '"');
> }
> /*
> ** Create output files
> */
> fp[0] = fopen(fn[0], "w");
> if (fp[0] == NULL) {
> fputs("fopen(fn[0]), \"w\") == NULL\n", stderr);
> exit(EXIT_FAILURE);
> }
> fp[1] = fopen(fn[1], "w");
> if (fp[1] == NULL) {
> remove(fn[0]);
> fputs("fopen(fn[1]), \"w\") == NULL\n", stderr);
> exit(EXIT_FAILURE);
> }
> for (tail = head; tail != NULL; tail = tail -> next) {
> if (strstr(tail -> data, "hotmail") == NULL) {
> fprintf(fp[0], "%s\n", tail -> data);
> } else {
> fprintf(fp[1], "%s\n", tail -> data);
> }
> }
> list_free(head, free);
> tail = head = NULL;
> fclose(fp[0]);
> fclose(fp[1]);
> /*
> ** Read original file
> ** Display original file contents
> */
> fp[0] = fopen(fn[0], "r");
> if (fp[0] == NULL) {
> fputs("fopen(fn[0], \"r\") == NULL\n", stderr);
> exit(EXIT_FAILURE);
> }
> puts("Final original file contents:");
> while ((rc = get_line(&buff, &size, fp[0])) > 0) {
> puts(buff);
> }
> putchar('\n');
> fclose(fp[0]);
> /*
> ** Read other file
> ** Display other file contents
> */
> fp[1] = fopen(fn[1], "r");
> if (fp[1] == NULL) {
> fputs("fopen(fn[1], \"r\") == NULL\n", stderr);
> exit(EXIT_FAILURE);
> }
> puts("Final other file contents:");
> while ((rc = get_line(&buff, &size, fp[1])) > 0) {
> puts(buff);
> }
> putchar('\n');
> free(buff);
> buff = NULL;
> size = 0;
> fclose(fp[1]);
> remove(fn[0]);
> remove(fn[1]);
> puts("/* END new.c output */");
> return 0;
> }
>
> void squeeze(char *s1, const int c)
> {
> char *p;
>
> for (p = s1; *s1 != '\0'; ++s1) {
> if (c != *s1) {
> *p++ = *s1;
> }
> }
> *p = '\0';
> }
>
> int get_line(char **lineptr, size_t *n, FILE *stream)
> {
> int rc;
> void *p;
> size_t count;
> /*
> ** The (char) casts in this function are not required
> ** by the rules of the C programming language.
> */
> count = 0;
> while ((rc = getc(stream)) != EOF
> || !feof(stream) && !ferror(stream))
> {
> ++count;
> if (count == (size_t)-2) {
> if (rc != '\n') {
> (*lineptr)[count] = '\0';
> (*lineptr)[count - 1] = (char)rc;
> } else {
> (*lineptr)[count - 1] = '\0';
> }
> break;
> }
> if (count + 2 > *n) {
> p = realloc(*lineptr, count + 2);
> if (p == NULL) {
> if (*n > count) {
> if (rc != '\n') {
> (*lineptr)[count] = '\0';
> (*lineptr)[count - 1] = (char)rc;
> } else {
> (*lineptr)[count - 1] = '\0';
> }
> } else {
> if (*n != 0) {
> **lineptr = '\0';
> }
> ungetc(rc, stream);
> }
> count = 0;
> break;
> }
> *lineptr = p;
> *n = count + 2;
> }
> if (rc != '\n') {
> (*lineptr)[count - 1] = (char)rc;
> } else {
> (*lineptr)[count - 1] = '\0';
> break;
> }
> }
> if (rc != EOF || !feof(stream) && !ferror(stream)) {
> rc = INT_MAX > count ? count : INT_MAX;
> } else {
> if (*n > count) {
> (*lineptr)[count] = '\0';
> }
> }
> return rc;
> }
>
> int list_fputs(const list_type *node, FILE *stream)
> {
> int rc = 0;
>
> while (node != NULL
> && (rc = fputs(node -> data, stream)) != EOF
> && (rc = putc('\n', stream)) != EOF)
> {
> node = node -> next;
> }
> return rc;
> }
>
> list_type *list_append
> (list_type **head, list_type *tail, void *data, size_t size)
> {
> list_type *node;
>
> node = malloc(sizeof *node);
> if (node != NULL) {
> node -> next = NULL;
> node -> data = malloc(size);
> if (node -> data != NULL) {
> memcpy(node -> data, data, size);
> if (*head != NULL) {
> tail -> next = node;
> } else {
> *head = node;
> }
> } else {
> free(node);
> node = NULL;
> }
> }
> return node;
> }
>
> void list_free(list_type *node, void (*free_data)(void *))
> {
> list_type *next_node;
>
> while (node != NULL) {
> next_node = node -> next;
> free_data(node -> data);
> free(node);
> node = next_node;
> }
> }
>
> /* END new.c */
>
Wow - All that just to separate @hotmail.com from anything else ? I'm
glad I stuck with perl :)
--
Marc Bissonnette
Looking for a new ISP? http://www.canadianisp.com
Largest ISP comparison site across Canada.
------------------------------
Date: Thu, 19 Jun 2008 09:13:23 GMT
From: "Bartc" <bc@freeuk.com>
Subject: Re: extract all hotmail email addresses in a file and store in separate file
Message-Id: <Tqp6k.12046$E41.6333@text.news.virginmedia.com>
"Marc Bissonnette" <dragnet\_@_/internalysis.com> wrote in message
news:Xns9AC29F465890dragnetinternalysisc@216.196.97.131...
> pete <pfiland@mindspring.com> fell face-first on the keyboard. This was
> the result: news:oeadnWrGl4RyQMTVnZ2dnUVZ_s7inZ2d@earthlink.com:
>
>> Dennis wrote:
>>> Hi, I have a text file that contents a list of email addresses like
>>> this:
>> /* BEGIN new.c output */
>><snip 250+ lines of C >
> Wow - All that just to separate @hotmail.com from anything else ? I'm
> glad I stuck with perl :)
I think pete just enjoys writing huge amounts of C code. Or showing off..
I thought my 50-line answer (posted to comp.lang.c only) might have been a
bit long because it didn't make clever use of scanf(), but at least it could
deal with /any number/ of email addresses from a file.
This code I /think/ only deals with the 4 email addresses in the OP's
example..
--
Bartc
------------------------------
Date: Thu, 19 Jun 2008 09:55:47 GMT
From: "Bartc" <bc@freeuk.com>
Subject: Re: extract all hotmail email addresses in a file and store in separate file
Message-Id: <D2q6k.12078$E41.1506@text.news.virginmedia.com>
<vippstar@gmail.com> wrote in message
news:569670a8-4f4d-4101-ab7c-bcc50625ad94@l64g2000hse.googlegroups.com...
> On Jun 19, 12:13 pm, "Bartc" <b...@freeuk.com> wrote:
>> "Marc Bissonnette" <dragnet\_@_/internalysis.com> wrote in message
>>
>> news:Xns9AC29F465890dragnetinternalysisc@216.196.97.131...
>>
>> > pete <pfil...@mindspring.com> fell face-first on the keyboard. This was
>> > the result:news:oeadnWrGl4RyQMTVnZ2dnUVZ_s7inZ2d@earthlink.com:
>>
>> >> Dennis wrote:
>> >>> Hi, I have a text file that contents a list of email addresses like
>> >>> this:
>> >> /* BEGIN new.c output */
>> >><snip 250+ lines of C >
>> > Wow - All that just to separate @hotmail.com from anything else ? I'm
>> > glad I stuck with perl :)
>>
>> I think pete just enjoys writing huge amounts of C code. Or showing off..
> Or using concrete functions he has written in the past to write
> concrete programs.
I thought it was some sort of unwritten rule here that when posting code
solutions you tend not to import large elements of your own library.
Otherwise everyone would post their own different version of getline() and
so on.
And also there's the possibility, as seems to have happened here, of using
something inappropriate just because it's there. There's no reason at all to
use a linked list to read all the input into memory (and risking
out-of-memory or thrashing for large input).
(Although I suspect pete may have created this over-the-top solution on
purpose..)
> concrete programs.
Which is more concrete, this code which has a memory requirement of N or
code using fixed memory?
--
Bartc
------------------------------
Date: Thu, 19 Jun 2008 00:17:46 -0400
From: pete <pfiland@mindspring.com>
Subject: Re: extract all hotmail email addresses in a file and store in separate file
Message-Id: <oeadnWrGl4RyQMTVnZ2dnUVZ_s7inZ2d@earthlink.com>
Dennis wrote:
> Hi, I have a text file that contents a list of email addresses like
> this:
>
> "foo@yahoo.com"
> "tom@hotmail.com"
> "jerry@gmail.com"
> "tommy@apple.com"
>
> I like to
>
> 1. Strip out the " characters and just leave the email addresses on
> each line.
> 2. extract out the hotmail addresses and store it into another file.
> The hotmail addresses in the original file would be deleted.
>
> Thanks for any help
/* BEGIN new.c output */
Original original file contents:
"foo@yahoo.com"
"tom@hotmail.com"
"jerry@gmail.com"
"tommy@apple.com"
Final original file contents:
foo@yahoo.com
jerry@gmail.com
tommy@apple.com
Final other file contents:
tom@hotmail.com
/* END new.c output */
/* BEGIN new.c */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#define STRINGS \
{ "\"foo@yahoo.com\"", "\"tom@hotmail.com\"", \
"\"jerry@gmail.com\"", "\"tommy@apple.com\""}
struct list_node {
struct list_node *next;
void *data;
};
typedef struct list_node list_type;
void squeeze(char *s1, const int s2);
int get_line(char **lineptr, size_t *n, FILE *stream);
int list_fputs(const list_type *node, FILE *stream);
list_type *list_append
(list_type **head, list_type *tail, void *data, size_t size);
void list_free(list_type *node, void (*free_data)(void *));
int main (void)
{
int rc;
size_t n;
char fn[2][L_tmpnam];
FILE *fp[2];
char *string[] = STRINGS;
size_t size = 0;
char *buff = NULL;
list_type *head = NULL;
list_type *tail = NULL;
puts("/* BEGIN new.c output */\n");
/*
** Create input file
*/
tmpnam(fn[0]);
tmpnam(fn[1]);
fp[0] = fopen(fn[0], "w");
if (fp[0] == NULL) {
fputs("fopen(fn[0]), \"w\") == NULL\n", stderr);
exit(EXIT_FAILURE);
}
for (n = 0; n != sizeof string / sizeof *string; ++n) {
fprintf(fp[0], "%s\n", string[n]);
}
fclose(fp[0]);
/*
** Read input file into list
*/
fp[0] = fopen(fn[0], "r");
if (fp[0] == NULL) {
fputs("fopen(fn[0], \"r\") == NULL\n", stderr);
exit(EXIT_FAILURE);
}
while ((rc = get_line(&buff, &size, fp[0])) > 0) {
tail = list_append(&head, tail, buff, rc);
if (tail == NULL) {
fputs("tail == NULL\n", stderr);
break;
}
}
fclose(fp[0]);
/*
** Display input file contents
*/
puts("Original original file contents:");
list_fputs(head, stdout);
putchar('\n');
/*
** Strip out quotes from strings in memory
*/
for (tail = head; tail != NULL; tail = tail -> next) {
squeeze(tail -> data, '"');
}
/*
** Create output files
*/
fp[0] = fopen(fn[0], "w");
if (fp[0] == NULL) {
fputs("fopen(fn[0]), \"w\") == NULL\n", stderr);
exit(EXIT_FAILURE);
}
fp[1] = fopen(fn[1], "w");
if (fp[1] == NULL) {
remove(fn[0]);
fputs("fopen(fn[1]), \"w\") == NULL\n", stderr);
exit(EXIT_FAILURE);
}
for (tail = head; tail != NULL; tail = tail -> next) {
if (strstr(tail -> data, "hotmail") == NULL) {
fprintf(fp[0], "%s\n", tail -> data);
} else {
fprintf(fp[1], "%s\n", tail -> data);
}
}
list_free(head, free);
tail = head = NULL;
fclose(fp[0]);
fclose(fp[1]);
/*
** Read original file
** Display original file contents
*/
fp[0] = fopen(fn[0], "r");
if (fp[0] == NULL) {
fputs("fopen(fn[0], \"r\") == NULL\n", stderr);
exit(EXIT_FAILURE);
}
puts("Final original file contents:");
while ((rc = get_line(&buff, &size, fp[0])) > 0) {
puts(buff);
}
putchar('\n');
fclose(fp[0]);
/*
** Read other file
** Display other file contents
*/
fp[1] = fopen(fn[1], "r");
if (fp[1] == NULL) {
fputs("fopen(fn[1], \"r\") == NULL\n", stderr);
exit(EXIT_FAILURE);
}
puts("Final other file contents:");
while ((rc = get_line(&buff, &size, fp[1])) > 0) {
puts(buff);
}
putchar('\n');
free(buff);
buff = NULL;
size = 0;
fclose(fp[1]);
remove(fn[0]);
remove(fn[1]);
puts("/* END new.c output */");
return 0;
}
void squeeze(char *s1, const int c)
{
char *p;
for (p = s1; *s1 != '\0'; ++s1) {
if (c != *s1) {
*p++ = *s1;
}
}
*p = '\0';
}
int get_line(char **lineptr, size_t *n, FILE *stream)
{
int rc;
void *p;
size_t count;
/*
** The (char) casts in this function are not required
** by the rules of the C programming language.
*/
count = 0;
while ((rc = getc(stream)) != EOF
|| !feof(stream) && !ferror(stream))
{
++count;
if (count == (size_t)-2) {
if (rc != '\n') {
(*lineptr)[count] = '\0';
(*lineptr)[count - 1] = (char)rc;
} else {
(*lineptr)[count - 1] = '\0';
}
break;
}
if (count + 2 > *n) {
p = realloc(*lineptr, count + 2);
if (p == NULL) {
if (*n > count) {
if (rc != '\n') {
(*lineptr)[count] = '\0';
(*lineptr)[count - 1] = (char)rc;
} else {
(*lineptr)[count - 1] = '\0';
}
} else {
if (*n != 0) {
**lineptr = '\0';
}
ungetc(rc, stream);
}
count = 0;
break;
}
*lineptr = p;
*n = count + 2;
}
if (rc != '\n') {
(*lineptr)[count - 1] = (char)rc;
} else {
(*lineptr)[count - 1] = '\0';
break;
}
}
if (rc != EOF || !feof(stream) && !ferror(stream)) {
rc = INT_MAX > count ? count : INT_MAX;
} else {
if (*n > count) {
(*lineptr)[count] = '\0';
}
}
return rc;
}
int list_fputs(const list_type *node, FILE *stream)
{
int rc = 0;
while (node != NULL
&& (rc = fputs(node -> data, stream)) != EOF
&& (rc = putc('\n', stream)) != EOF)
{
node = node -> next;
}
return rc;
}
list_type *list_append
(list_type **head, list_type *tail, void *data, size_t size)
{
list_type *node;
node = malloc(sizeof *node);
if (node != NULL) {
node -> next = NULL;
node -> data = malloc(size);
if (node -> data != NULL) {
memcpy(node -> data, data, size);
if (*head != NULL) {
tail -> next = node;
} else {
*head = node;
}
} else {
free(node);
node = NULL;
}
}
return node;
}
void list_free(list_type *node, void (*free_data)(void *))
{
list_type *next_node;
while (node != NULL) {
next_node = node -> next;
free_data(node -> data);
free(node);
node = next_node;
}
}
/* END new.c */
--
pete
------------------------------
Date: Thu, 19 Jun 2008 08:38:40 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: extract all hotmail email addresses in a file and store in separate file
Message-Id: <pan.2008.06.19.06.38.39@rtij.nl.invlalid>
On Wed, 18 Jun 2008 12:33:45 -0700, Dennis wrote:
> Hi, I have a text file that contents a list of email addresses like
> this:
>
> "foo@yahoo.com"
> "tom@hotmail.com"
> "jerry@gmail.com"
> "tommy@apple.com"
>
> I like to
>
> 1. Strip out the " characters and just leave the email addresses on each
> line.
> 2. extract out the hotmail addresses and store it into another file. The
> hotmail addresses in the original file would be deleted.
perl -nie 'if (/\@hotmail.com@$/) { s/"//g; print; }' text_file
HTH,
M4
------------------------------
Date: 19 Jun 2008 07:11:20 GMT
From: Dave Weaver <zen13097@zen.co.uk>
Subject: Re: File Locked After Close?
Message-Id: <485a0698$0$10629$fa0fcedb@news.zen.co.uk>
xmp333@yahoo.com <xmp333@yahoo.com> wrote:
> Hi,
>
> The last line of the following code snippet fails:
>
> open FILE, '<file.dat' || die '...';
The first line of your code snippet could be failing, and you'd not know it -
That is not checking the status of the open() call.
Due to operator precendence, that line is equivalent to:
open( FILE, ('<file.dat' || die '...') );
Use the lower precedence 'or' operator, or parentheses:
open( FILE, '<file.dat' ) || die '...';
open FILE, '<file.dat' or die '...';
Personally, I'd use a lexical file handle and the 3-arg version of open:
open my $file, '<', 'file.dat' or die '...';
------------------------------
Date: Thu, 19 Jun 2008 04:42:20 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Thu Jun 19 2008
Message-Id: <K2p12K.z5p@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.
Algorithm-Evolutionary-0.56
http://search.cpan.org/~jmerelo/Algorithm-Evolutionary-0.56/
Perl extension for performing paradigm-free evolutionary algorithms.
----
App-Todo-0.96
http://search.cpan.org/~tsibley/App-Todo-0.96/
Provides todo.pl, a command-line interface to Hiveminder
----
B-Debug-1.09
http://search.cpan.org/~rurban/B-Debug-1.09/
Walk Perl syntax tree, printing debug info about ops
----
Business-OnlinePayment-AuthorizeNet-3.20
http://search.cpan.org/~ivan/Business-OnlinePayment-AuthorizeNet-3.20/
AuthorizeNet backend for Business::OnlinePayment
----
Business-OnlinePayment-LinkPoint-0.10
http://search.cpan.org/~ivan/Business-OnlinePayment-LinkPoint-0.10/
LinkPoint (Cardservice) backend for Business::OnlinePayment
----
Business-OnlinePayment-Skipjack-0.05
http://search.cpan.org/~ivan/Business-OnlinePayment-Skipjack-0.05/
Skipjack backend module for Business::OnlinePayment
----
CGI-Application-4.10
http://search.cpan.org/~markstos/CGI-Application-4.10/
Framework for building reusable web-applications
----
CGI-Deurl-XS-0.06
http://search.cpan.org/~athomason/CGI-Deurl-XS-0.06/
Fast decoder for URL parameter strings
----
CPAN-Reporter-Smoker-0.14
http://search.cpan.org/~dagolden/CPAN-Reporter-Smoker-0.14/
Turnkey CPAN Testers smoking
----
Cache-FastMmap-1.27
http://search.cpan.org/~robm/Cache-FastMmap-1.27/
Uses an mmap'ed file to act as a shared memory interprocess cache
----
Class-MOP-0.62
http://search.cpan.org/~sartak/Class-MOP-0.62/
A Meta Object Protocol for Perl 5
----
Config-General-2.40
http://search.cpan.org/~tlinden/Config-General-2.40/
Generic Config Module
----
Crypt-Rijndael-1.06_01
http://search.cpan.org/~bdfoy/Crypt-Rijndael-1.06_01/
Crypt::CBC compliant Rijndael encryption module
----
Finance-Bank-TB-0.25
http://search.cpan.org/~kozo/Finance-Bank-TB-0.25/
Perl extension for TatraPay and CardPay of Tatrabanka and EliotPay of .eliot.
----
Finance-Bank-TB-0.26
http://search.cpan.org/~kozo/Finance-Bank-TB-0.26/
Perl extension for TatraPay and CardPay of Tatrabanka and EliotPay of .eliot.
----
Finance-Bank-TB-0.27
http://search.cpan.org/~kozo/Finance-Bank-TB-0.27/
Perl extension for TatraPay and CardPay of Tatrabanka and EliotPay of .eliot.
----
Finance-Bank-TB-0.28
http://search.cpan.org/~kozo/Finance-Bank-TB-0.28/
Perl extension for TatraPay and CardPay of Tatrabanka and EliotPay of .eliot.
----
GRID-Machine-0.095
http://search.cpan.org/~casiano/GRID-Machine-0.095/
Remote Procedure Calls over a SSH link
----
Hash-Case-1.005
http://search.cpan.org/~markov/Hash-Case-1.005/
base class for hashes with key-casing requirements
----
IO-Lambda-0.20
http://search.cpan.org/~karasik/IO-Lambda-0.20/
non-blocking I/O in lambda style
----
IPC-SRLock-0.1.61
http://search.cpan.org/~pjfl/IPC-SRLock-0.1.61/
Set/reset locking semantics to single thread processes
----
Iterator-File-1.0
http://search.cpan.org/~wreardon/Iterator-File-1.0/
A file iterator, optionally stateful and verbose.
----
Kwalify-1.17
http://search.cpan.org/~srezic/Kwalify-1.17/
Kwalify schema for data structures
----
Lingua-EN-NamedEntity-1.9
http://search.cpan.org/~ambs/Lingua-EN-NamedEntity-1.9/
Basic Named Entity Extraction algorithm
----
Lingua-StarDict-Gen-0.04
http://search.cpan.org/~jjoao/Lingua-StarDict-Gen-0.04/
----
Locale-Geocode-1.1
http://search.cpan.org/~diz/Locale-Geocode-1.1/
----
Math-Expression-Evaluator-0.1.1
http://search.cpan.org/~moritz/Math-Expression-Evaluator-0.1.1/
parses, compiles and evaluates mathematic expressions
----
Math-Geometry-Voronoi-1.1
http://search.cpan.org/~samtregar/Math-Geometry-Voronoi-1.1/
compute Voronoi diagrams from sets of points
----
MooseX-Clone-0.03
http://search.cpan.org/~nuffin/MooseX-Clone-0.03/
Fine grained cloning support for Moose objects.
----
NTLM-1.05
http://search.cpan.org/~buzz/NTLM-1.05/
An NTLM authentication module
----
Net-Moo-0.1
http://search.cpan.org/~ascope/Net-Moo-0.1/
OOP wrapper for the Moo.com API
----
Net-uFTP-0.112
http://search.cpan.org/~strzelec/Net-uFTP-0.112/
Universal interface for FTP-like modules (FTP, SFTP, SCP), in most cases Net::FTP compatible.
----
Net-uFTP-0.12
http://search.cpan.org/~strzelec/Net-uFTP-0.12/
Universal interface for FTP-like modules (FTP, SFTP, SCP), in most cases Net::FTP compatible.
----
POE-Component-Client-Whois-Smart-0.12_01
http://search.cpan.org/~nrg/POE-Component-Client-Whois-Smart-0.12_01/
Provides very quick WHOIS queries with smart features.
----
POE-Filter-JSON-Incr-0.01
http://search.cpan.org/~nuffin/POE-Filter-JSON-Incr-0.01/
Parse JSON from streams without needing per-line input
----
Qmail-Deliverable-1.06
http://search.cpan.org/~juerd/Qmail-Deliverable-1.06/
Determine deliverability of local addresses
----
SMS-Send-DE-MeinBMW-0.05
http://search.cpan.org/~borisz/SMS-Send-DE-MeinBMW-0.05/
An SMS::Send driver for the www.meinbmw.de website
----
Sort-Packed-0.01
http://search.cpan.org/~salva/Sort-Packed-0.01/
Sort records packed in a vector
----
String-CaseProfile-0.08
http://search.cpan.org/~enell/String-CaseProfile-0.08/
Get/Set the letter case profile of a string
----
Sub-Contract-0.09
http://search.cpan.org/~erwan/Sub-Contract-0.09/
Pragmatic contract programming for Perl
----
Test-Most-0.02
http://search.cpan.org/~ovid/Test-Most-0.02/
Most commonly needed test functions and features.
----
Test-Most-0.03
http://search.cpan.org/~ovid/Test-Most-0.03/
Most commonly needed test functions and features.
----
Text-CSV-1.06
http://search.cpan.org/~makamaka/Text-CSV-1.06/
comma-separated values manipulator (using XS or PurePerl)
----
Thread-CriticalSection-0.01
http://search.cpan.org/~melo/Thread-CriticalSection-0.01/
Run a coderef inside a critical section
----
Tie-Array-QueueExpire-0.49
http://search.cpan.org/~fdulau/Tie-Array-QueueExpire-0.49/
----
WWW-Curl-4.01
http://search.cpan.org/~szbalint/WWW-Curl-4.01/
Perl extension interface for libcurl
----
WWW-SchneierFacts-0.01
http://search.cpan.org/~nuffin/WWW-SchneierFacts-0.01/
API for retrieving facts about Bruce Schneier
----
WWW-SchneierFacts-0.02
http://search.cpan.org/~nuffin/WWW-SchneierFacts-0.02/
API for retrieving facts about Bruce Schneier
----
Wiki-Toolkit-Formatter-Mediawiki-0.04
http://search.cpan.org/~dprice/Wiki-Toolkit-Formatter-Mediawiki-0.04/
A Mediawiki-style formatter for Wiki::Toolkit.
----
XML-Quick-0.04
http://search.cpan.org/~robn/XML-Quick-0.04/
Generate XML from hashes (and other data)
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/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
------------------------------
Date: Wed, 18 Jun 2008 18:33:47 -0700
From: David Filmer <usenet@davidfilmer.com>
Subject: Re: Wrtiting to a file in LDIF format
Message-Id: <u66dnQazTL7LKsTV4p2dnAA@giganews.com>
dakin999 wrote:
> Hi, I am trying to write to a file elements of an array. The output I
> want is simple LDIF
That wheel has already been invented for you:
http://search.cpan.org/~leifhed/perldap-1.4/LDIF.pm
--
David Filmer (http://DavidFilmer.com)
The best way to get a good answer is to ask a good question.
------------------------------
Date: Wed, 18 Jun 2008 19:52:55 -0700 (PDT)
From: dakin999 <akhilshri@gmail.com>
Subject: Re: Wrtiting to a file in LDIF format
Message-Id: <47d3e869-5539-4780-954c-8ce8f4b57990@a32g2000prf.googlegroups.com>
On Jun 19, 11:33=A0am, David Filmer <use...@davidfilmer.com> wrote:
> dakin999 wrote:
> > Hi, I am trying to write to a file elements of an array. =A0The output =
I
> > want is simple LDIF
>
> That wheel has already been invented for you:
>
> =A0 =A0http://search.cpan.org/~leifhed/perldap-1.4/LDIF.pm
>
> --
> David Filmer (http://DavidFilmer.com)
> The best way to get a good answer is to ask a good question.
Yes, I am aware of the this. But I need to construct the LDIF file
first before exporting the data into the LDAP server.
------------------------------
Date: Thu, 19 Jun 2008 08:35:15 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Wrtiting to a file in LDIF format
Message-Id: <pan.2008.06.19.06.35.13@rtij.nl.invlalid>
On Wed, 18 Jun 2008 19:52:55 -0700, dakin999 wrote:
> On Jun 19, 11:33 am, David Filmer <use...@davidfilmer.com> wrote:
>> dakin999 wrote:
>> > Hi, I am trying to write to a file elements of an array. The output
>> > I want is simple LDIF
>>
>> That wheel has already been invented for you:
>>
>> http://search.cpan.org/~leifhed/perldap-1.4/LDIF.pm
>>
>> --
>> David Filmer (http://DavidFilmer.com) The best way to get a good answer
>> is to ask a good question.
>
> Yes, I am aware of the this. But I need to construct the LDIF file first
> before exporting the data into the LDAP server.
That's what it does, look under the heading Output.
M4
------------------------------
Date: Thu, 19 Jun 2008 01:09:19 -0700 (PDT)
From: dakin999 <akhilshri@gmail.com>
Subject: Re: Wrtiting to a file in LDIF format
Message-Id: <a1b58a16-e21a-472c-b42e-1de30c454713@i18g2000prn.googlegroups.com>
On Jun 19, 4:35=A0pm, Martijn Lievaart <m...@rtij.nl.invlalid> wrote:
> On Wed, 18 Jun 2008 19:52:55 -0700, dakin999 wrote:
> > On Jun 19, 11:33=A0am, David Filmer <use...@davidfilmer.com> wrote:
> >> dakin999 wrote:
> >> > Hi, I am trying to write to a file elements of an array. =A0The outp=
ut
> >> > I want is simple LDIF
>
> >> That wheel has already been invented for you:
>
> >> =A0 =A0http://search.cpan.org/~leifhed/perldap-1.4/LDIF.pm
>
> >> --
> >> David Filmer (http://DavidFilmer.com) The best way to get a good answe=
r
> >> is to ask a good question.
>
> > Yes, I am aware of the this. But I need to construct the LDIF file firs=
t
> > before exporting the data into the LDAP server.
>
> That's what it does, look under the heading Output.
>
> M4- Hide quoted text -
>
> - Show quoted text -
Sorry for the confusion, but I am just looking to create a output LDIF
file without doing anything after that. (No loading to LDAP server,
etc. just a plain LDIF file in the format I mentioned at the top).
------------------------------
Date: Thu, 19 Jun 2008 01:24:21 -0700 (PDT)
From: dakin999 <akhilshri@gmail.com>
Subject: Re: Wrtiting to a file in LDIF format
Message-Id: <f8b342db-be39-4864-983a-39e14e070fac@g16g2000pri.googlegroups.com>
On Jun 19, 4:35=A0pm, Martijn Lievaart <m...@rtij.nl.invlalid> wrote:
> On Wed, 18 Jun 2008 19:52:55 -0700, dakin999 wrote:
> > On Jun 19, 11:33=A0am, David Filmer <use...@davidfilmer.com> wrote:
> >> dakin999 wrote:
> >> > Hi, I am trying to write to a file elements of an array. =A0The outp=
ut
> >> > I want is simple LDIF
>
> >> That wheel has already been invented for you:
>
> >> =A0 =A0http://search.cpan.org/~leifhed/perldap-1.4/LDIF.pm
>
> >> --
> >> David Filmer (http://DavidFilmer.com) The best way to get a good answe=
r
> >> is to ask a good question.
>
> > Yes, I am aware of the this. But I need to construct the LDIF file firs=
t
> > before exporting the data into the LDAP server.
>
> That's what it does, look under the heading Output.
>
> M4- Hide quoted text -
>
> - Show quoted text -
Sorry, I forget to mention, I am using perl-ldap, not the mozilla....
------------------------------
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 1658
***************************************