[19247] in Perl-Users-Digest
Perl-Users Digest, Issue: 1442 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 4 11:05:30 2001
Date: Sat, 4 Aug 2001 08:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <996937508-v10-i1442@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 4 Aug 2001 Volume: 10 Number: 1442
Today's topics:
Re: \nhelp <krahnj@acm.org>
Re: ActiveState Perl <-> Cygwin perl and newlines... <bowman@montana.com>
Re: Appanding to hash_key_value (Tad McClellan)
Re: Benchmarking Perl modules <Dave.Stafford@globis.net>
Re: comp.infosystems.www.authoring.cgi now moderated <tsee@gmx.net>
Re: comp.infosystems.www.authoring.cgi now moderated (Randal L. Schwartz)
Re: comp.infosystems.www.authoring.cgi now moderated <flavell@mail.cern.ch>
Re: data collection and file management (Garry Williams)
Re: Database Problem <krahnj@acm.org>
Re: Database Problem <bart.lateur@skynet.be>
Re: Extract the relative sorting of items from multiple <bart.lateur@skynet.be>
FAQ: Why does defined() return true on empty arrays and <faq@denver.pm.org>
Re: how can I permanently change @INC? <gnarinn@hotmail.com>
Re: How do I select a random element from an array? <krahnj@acm.org>
Re: How do I select a random element from an array? <bart.lateur@skynet.be>
Re: Net::Ping troubles Solution <djberg96@hotmail.com>
Re: pdf file desc <bart.lateur@skynet.be>
Re: pdf file desc <joebloggs74@hotmail.com>
Re: perl "INFO" files? (emacs) Where? (Search for perl <nospam-abuse@ilyaz.org>
Re: PERL system function and variables <gnarinn@hotmail.com>
Re: Splitting a text list into smaller lists? ctverlane@NOSPAM.blackdahlia.com
Re: Splitting a text list into smaller lists? <bart.lateur@skynet.be>
Re: Splitting a text list into smaller lists? <krahnj@acm.org>
Re: Splitting a text list into smaller lists? <krahnj@acm.org>
Re: string extraction <krahnj@acm.org>
Re: string extraction (Tad McClellan)
Re: Subject : randomizing a hash <gnarinn@hotmail.com>
Re: Understanding parsers <bart.lateur@skynet.be>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 04 Aug 2001 10:37:29 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: \nhelp
Message-Id: <3B6BD0C7.33097F1B@acm.org>
Walnut wrote:
>
> On Thu, 26 Jul 2001 21:38:14 GMT, jtjohnston
> <jtjohnston@courrier.usherb.ca> wrote:
>
> > Hi,
> > I have a text file I use as a database. I have many instances of lines
> > starting with "&&4;" Can someone show me how to re-attach the "&&4;" to
> > the previous line?
> >
> > See following example:
> >
> > ---snip---
> > Record1¶field2¶field3¶field4¶field5¶field6¶field7¶
> > Record2¶field2¶field3¶
> > &&4; field4¶field5¶field6¶field7¶
> > Record3¶field2¶field3¶field4¶field5¶field6¶field7¶
> > ---snip---
>
> Suck file into a variable and substitute as follows:
>
> $variable ~= s!\n&&.;!\n!g;
In order to re-attach it to the previous line you need to _remove_ the
newline.
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 4 Aug 2001 08:47:58 -0600
From: "bowman" <bowman@montana.com>
Subject: Re: ActiveState Perl <-> Cygwin perl and newlines...
Message-Id: <AWTa7.98$iK.103229@newsfeed.slurp.net>
"nobody" <nobody@nobody.com> wrote in message
news:OgOa7.263742$E4.6547889@amsnews02.chello.com...
>
>
> Running the same line of code in cygwin perl, it won't print
> the newlines, because cygwin only outputs a \n.
$ perl -v
This is perl, v5.6.1 built for cygwin
(with 1 registered patch, see perl -V for more detail)
$ perl junk
hello
world
$ cat junk
print "hello\nworld\n";
seems to work for me.....
------------------------------
Date: Sat, 4 Aug 2001 08:58:48 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Appanding to hash_key_value
Message-Id: <slrn9mnsc8.30j.tadmc@tadmc26.august.net>
Nipa <npatel@webley.com> wrote:
>I have tried many different approch to this problem but none them seem
>to be working.
>
>here is my question: How do i append to an existing key's value in a
>Hash
$formdata{$key} .= $value;
>now, the problem is in appanding the value to an existing 'key' value.
What is the problem?
Your code should work (most of the time). My code above should work.
I don't see a problem...
>One question would be, when I do ' if($formdata{$key}) ' does it mean
>that i am checking the existance of a value or a key in a hash.
No. It means you are checking to see if $formdata{$key}'s value
is true.
You use the oddly named exists() function to check for the
existence of a key in a hash.
$formdata{$key} = 0;
$formdata{$key} is false.
exists($formdata{$key}) is true.
>Believe me or not, but I have sent close to 4 hr figuring this out,
>and still haven't figured it. Thus i am asking for your help.
There is something you are not telling us.
If you can make a short and complete program that we can run,
we can help figure out what the problem is.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 04 Aug 2001 13:21:44 GMT
From: "Dave Stafford" <Dave.Stafford@globis.net>
Subject: Re: Benchmarking Perl modules
Message-Id: <IFSa7.335722$XL1.5737613@nlnews00.chello.com>
"gnari" <gnarinn@hotmail.com> wrote in message
> It is also possible that netscape is also limiting your executions/second.
> It might be interesting to run your test with a LWP::Simple script
> instead of browsers.
Well, in this case Netscape is only the host for the Java applet, however, I
just re-ran with a LWP::Simple and LWP::UserAgent.
LWP::Simple -> 10 executions/sec (lots of disk activity)
LWP::UserAgent -> 50 executions/sec
I dunno what LWP::Simple is doing, although it looks like it is connecting
to my proxy server, who knows why?
>>Perhaps I'll compare platforms some time.
>
> and separate server and client(s) machines?
Well I purposely keep the server/client on the same machine to avoid network
delays from skewing the results. All I was really interested in was how much
module loading affected performance on cgi script on a web server.
Dave
------------------------------
Date: Sat, 4 Aug 2001 15:36:00 +0200
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: comp.infosystems.www.authoring.cgi now moderated
Message-Id: <9kgtff$vc5$07$1@news.t-online.com>
"Godzilla!" <godzilla@stomp.stomp.tokyo> schrieb im Newsbeitrag
news:3B6B570F.48F03EFB@stomp.stomp.tokyo...
>
> Have you noticed comp.infosystems.www.authoring.cgi
> is now a moderated newsgroup?
No. Everything works for me as usual.
Steffen
------------------------------
Date: 04 Aug 2001 07:37:55 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: comp.infosystems.www.authoring.cgi now moderated
Message-Id: <m1wv4j51rw.fsf@halfdome.holdit.com>
>>>>> "Godzilla!" == Godzilla! <godzilla@stomp.stomp.tokyo> writes:
Godzilla!> Do you recall a call for public vote to amend the group's charter?
Godzilla!> I do not.
Not necessary under Usenet rules. Once a moderated group has been
created, the moderator actually has the power to change things without
a revote. I learned this in a "in your face" way a few years ago when
I was looking at the charter of comp.lang.perl.announce.
>> Freedom of Speech does not mean that you get to use someone else's
>> printing press freely.
Godzilla!> I understand. Your belief is USENET is not open and free for all
Godzilla!> to use but rather each newsgroup belongs to its sponsor who can,
Godzilla!> at whim and will, impose any conditions and restrictions.
No, do not put words in my mouth. What I believe is neither of those
positions. Therefore, the rest of your argument holds no weight.
>> Usenet is a cooperative anarchy... we've got collective
>> rules here to make things work.
Godzilla!> Those rules include granting permission to a group sponsor
Godzilla!> a power to impose restrictions, independently? It is my
Godzilla!> understanding a group sponsor volunteers to host a group
Godzilla!> and adamantly agrees to not interfere with its operation
Godzilla!> and charter. My opinion is those sponsors whom violate
Godzilla!> the sancity of USENET, display a lack of good ethics.
A "group sponsor" is not "a group moderator". And yes, a "group
moderator" is given essentially czar-like powers, according to Usenet
tradition.
>> The mechanism of a moderated group is just one aspect of it.
Godzilla!> The charter for the cgi group indicates self-moderation and
Godzilla!> provides a methodology for this so all can post. This is
Godzilla!> no longer true. Boutell has imposed restrictions of his own,
Godzilla!> in violation of the group's charter and in violation of
Godzilla!> long standing USENET traditions.
Nope. He's the moderator. He can change the charter unilaterally,
"according to longstanding Usenet traditions".
If you have an issue with this, take it to news.admin.* groups, not
comp.lang.perl.*, because it's very much off-topic here.
--
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: Sat, 4 Aug 2001 16:19:34 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: comp.infosystems.www.authoring.cgi now moderated
Message-Id: <Pine.LNX.4.30.0108041607500.20736-100000@lxplus023.cern.ch>
On Aug 4, Steffen Müller juggled electrons into holes to say:
> "Godzilla!" <godzilla@stomp.stomp.tokyo> schrieb im Newsbeitrag
> news:3B6B570F.48F03EFB@stomp.stomp.tokyo...
> >
> > Have you noticed comp.infosystems.www.authoring.cgi
> > is now a moderated newsgroup?
As it has been since late 1996, if I've got the dates right.
> No. Everything works for me as usual.
Hmmm.
Here's what Tom Boutell, the promoter of the automoderation scheme,
claimed about it as of around 1998:
http://www.boutell.com/boutell/usenet.html
I won't say it's been a disaster - far from it: it's been an
interesting experiment, but it has quite a few shortcomings to balance
against the benefits.
I'd certainly like to see some fine-tuning done to its bot rules: on
the one hand to keep out more spam, and on the other hand to allow
some perfectly proper usenet techniques, like moving a discussion to
or from the group by means of crosspost-and-followup, or like the
original author issuing a replacement posting with Supersedes: header.
Anyhow, I'm afraid I'm drifting off-topic for here.
------------------------------
Date: Sat, 04 Aug 2001 14:43:51 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: data collection and file management
Message-Id: <slrn9mo2h6.s5t.garry@zfw.zvolve.net>
On 2 Aug 2001 16:55:44 -0700, katherine <kstar8864@hotmail.com> wrote:
> I am trying to write a data collection program (in Perl) that will
> gather system statistics synchronously using utilities like iostat,
> vmstat, cpustat, netstat, etc.
[snip]
> Any help/suggestions would be greatly appreciated.
Check out the sar(1) manual page.
--
Garry Williams
------------------------------
Date: Sat, 04 Aug 2001 10:25:19 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Database Problem
Message-Id: <3B6BCDED.461C58C8@acm.org>
Walnut wrote:
>
> On 24 Jul 2001 08:00:08 -0700, tommyumuc@aol.com (JR) wrote:
>
> >
> > my $typeChange = $q->param('typeChange');
>
> This should change all the newlines to spaces.
>
> my $typeChange = $q->param('typeChange') =~ s/\n*/\s/g;
No, that will change newlines to the letter s.
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 04 Aug 2001 11:13:41 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Database Problem
Message-Id: <08mnmtst98tpjpa86upp9ajpod4avsvn71@4ax.com>
Walnut wrote:
>On 24 Jul 2001 08:00:08 -0700, tommyumuc@aol.com (JR) wrote:
>
>>
>> my $typeChange = $q->param('typeChange');
>
>This should change all the newlines to spaces.
>
>my $typeChange = $q->param('typeChange') =~ s/\n*/\s/g;
Precedence problem.
(my $typeChange = $q->param('typeChange')) =~ s/\n*/\s/g;
--
Bart.
------------------------------
Date: Sat, 04 Aug 2001 10:33:11 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Extract the relative sorting of items from multiple lists
Message-Id: <pnjnmt8k6pl8as26f3p9qj5panfqsbbl13@4ax.com>
David Combs wrote:
>>The Graph module, as found on CPAN and discussed in
>>"Mastering Algorithms with Perl" has such a method.
>>
>
>Some of the more nifty algorithms in that Aho, Ullman, etc
>algorithms book (way back when) somehow didn't make
>into that perl book. (Pretty much every algorithms
>book SINCE the aho/ullman book also has them).
Aho, Ullman, etc? Those are the guys from the Dragon Book, "Compilers:
Principles, Techniques and Tools". (BTW the third name is Sethi.)
"Mastering Algorithms with Perl" is written by Jon Orwant, Jarkko
Hietaniemi & John Macdonald.
A quick scan at O'Reilly's website, section "Perl", could have told you
that.
--
Bart.
------------------------------
Date: Sat, 04 Aug 2001 12:17:03 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: Why does defined() return true on empty arrays and hashes?
Message-Id: <3JRa7.21$T3.171035648@news.frii.net>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.
+
Why does defined() return true on empty arrays and hashes?
The short story is that you should probably only use defined on scalars
or functions, not on aggregates (arrays and hashes). See the defined
entry in the perlfunc manpage in the 5.004 release or later of Perl for
more detail.
-
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to
news:news.answers
or to the many thousands of other useful Usenet news groups.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-1999 Tom Christiansen and Nathan
Torkington. All rights reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
04.52
--
This space intentionally left blank
------------------------------
Date: Sat, 4 Aug 2001 10:03:17 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: how can I permanently change @INC?
Message-Id: <996919397.968773283995688.gnarinn@hotmail.com>
In article <3B6B45A7.9A173F40@cfl.rr.com>, tuxy <perlgirl@cfl.rr.com> wrote:
>I realize I can push @INC,$newdir and it works nicely on a case-by-case
>basis, but how can I change the default value of @INC? I tried perdoc -q
>@INC but I don't see an answer there.
>
see perldoc perlrun
look for ENVIRONMENT and PERL5LIB
gnari
------------------------------
Date: Sat, 04 Aug 2001 10:45:48 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: How do I select a random element from an array?
Message-Id: <3B6BD25A.35D4B76F@acm.org>
~greg wrote:
>
> > +
> > How do I select a random element from an array?
> >
> > Use the rand() function (see the rand entry in the perlfunc manpage):
> >
> > # at the top of the program:
> > srand; # not needed for 5.004 and later
>
> Isn't that a fault? - not that srand is now in rand()
> but the apparent lack of a way to use an explicit
> seed to generate the same random sequence
> over again when the sequence is being used
> to test a program. Or is there a way?
You can still use srand() to seed the random sequence.
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 04 Aug 2001 11:15:19 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: How do I select a random element from an array?
Message-Id: <9cmnmtk71vbvscdi1fpgprucdinfdgmke9@4ax.com>
~greg wrote:
>> Use the rand() function (see the rand entry in the perlfunc manpage):
>>
>> # at the top of the program:
>> srand; # not needed for 5.004 and later
>
>Isn't that a fault? - not that srand is now in rand()
>but the apparent lack of a way to use an explicit
>seed to generate the same random sequence
>over again when the sequence is being used
>to test a program. Or is there a way?
Yes. Use srand() with an explicit parameter, a long integer.
--
Bart.
------------------------------
Date: Sat, 04 Aug 2001 14:05:07 GMT
From: "Daniel Berger" <djberg96@hotmail.com>
Subject: Re: Net::Ping troubles Solution
Message-Id: <niTa7.26975$X6.899250@typhoon.mn.mediaone.net>
use Net::Ping::External
------------------------------
Date: Sat, 04 Aug 2001 10:27:52 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: pdf file desc
Message-Id: <kfjnmt4ltcacge5h9g6147sknvkdqgbtkd@4ax.com>
Bernhard Sept, BHS Schulungen wrote:
>I know, this is not the correct ng, but you might know the answer...
>
>I am looking for the pdf file structure, because I want to create pdf files
>from a program.
>
>Any hints?
http://www.pdfzone.com/
Search for "file format" and you'll get lots of hits.
The full spec is available at Adobe's website <http://www.adobe.com>,
but these guys keeps changing their website so much that it even makes
not much sense to make a bookmark.
--
Bart.
------------------------------
Date: Sat, 4 Aug 2001 11:50:12 +0100
From: "Joe Bloggs" <joebloggs74@hotmail.com>
Subject: Re: pdf file desc
Message-Id: <9kgjum$scq$1@neptunium.btinternet.com>
Bernd,
> I know, this is not the correct ng, but you might know the answer...
You're right, it isn't. Try comp.text.pdf.
> I am looking for the pdf file structure, because I want to create pdf
files
> from a program.
People on this group probably use Perl's powerful PDF modules to read/write
such files, try searching for pdf on search.cpan.org
"Bernhard Sept, BHS Schulungen" <b-sept@gmx.de> wrote in message
news:9kg5as$v8c$04$1@news.t-online.com...
> Hi,
> I know, this is not the correct ng, but you might know the answer...
>
> I am looking for the pdf file structure, because I want to create pdf
files
> from a program.
>
> Any hints?
>
> Have a nice day
>
> Bernd
>
>
>
>
------------------------------
Date: Sat, 4 Aug 2001 10:07:17 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: perl "INFO" files? (emacs) Where? (Search for perl-info fails)
Message-Id: <9kghgl$21fn$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
David Combs
<dkcombs@panix.com>], who wrote in article <9kdq3e$99i$1@panix6.panix.com>:
> Well, that was 1995, the most recent(!) version of
> cperl-mode.
???!!!
> Does this exist, for eg 5.6?
$CPAN/doc (sp?) contains pod2texi (sp?) which may be able to do the job.
Ilya
------------------------------
Date: Sat, 4 Aug 2001 10:15:48 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: PERL system function and variables
Message-Id: <996920148.502430097199976.gnarinn@hotmail.com>
In article <169bb2e3.0108031500.7a5e9077@posting.google.com>,
Scott <swcmeng@yahoo.com> wrote:
[top-posting rearranged]
>
>tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrn9mj9b2.skr.tadmc@tadmc26.august.net>...
>> Scott <swcmeng@yahoo.com> wrote:
>> >
>> >I am trying to assign the output of the below system function-based
>> >command to a variable.
>> >
>> >system "ls -d /etc/lp/interface/* | grep $lprinter";
>>
>> >Does anyone know how to accomplish this?
>>
>>
>> Anybody who could be troubled to read the documentation for the
>> functions they are using would know how to accomplish that.
>>
>> I suggest that you start reading the documentation for the
>> functions that you are using:
>>
>> perldoc -f system
>>
>>
>> >Any assistance would be
>> >greatly appreciated.
>>
>>
>> The description of the function that you are using tells you how
>> to accomplish what you want to accomplish. Just do it that way.
>I usually don't respond to such doltish nonsense, but--really--you
>need to try and lift that chip off your shoulders. It's only holding
>you back my friend.
>
really, there is no reason to get excited about this.
Tad did tell the OP how to get the info he wanted, and he pointed
out how to avoid looking foolish on this newsgroup, and he did it
without insults. the odds are that the OP will have been helped,
both for this particular problem, and also for his next problem,
as he has been made more aware of perldoc.
gnari
------------------------------
Date: 3 Aug 2001 17:38:12 GMT
From: ctverlane@NOSPAM.blackdahlia.com
Subject: Re: Splitting a text list into smaller lists?
Message-Id: <9keni4$1pf$1@news.netmar.com>
In article <74f348f7.0108020727.18bd9b7d@posting.google.com>, Yves Orton
<demerphq@hotmail.com> writes:
>Incidentally to the OP, what kind of file do you have that uses the 4
>character as a delimeter? Surely you might a username with a 4 in it?
> Especially in 25000 users???
Hello, Yves --
It does sound strange. I should have given a bit more info in my original
post.
The list of 25000 users I am working with is a list of Common Names (cn)
exported from an Oracle Internet Directory server and reformatted into MS
Exchange distribution lists. That's why the input and the output will both
be one long line. That's also why there's no chance of the numeral 4 (I
picked 4 as something that wouldn't be reserved in Perl) appearing in any of
the cns, since we have a restriction in our OID that cns are only alpha
characters.
Thanks very much for the help you've given me with this. I am currently
working on the problem using a combination of your code and John's code. I'd
have it whipped already thanks to you guys, except that I modified the script
to accept the input from a file instead of STDIN, and broke it... :-> I am
learning a great deal from studying the code you both so kindly supplied.
Many thanks!!
-CT
----- Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web -----
http://newsone.net/ -- Free reading and anonymous posting to 60,000+ groups
NewsOne.Net prohibits users from posting spam. If this or other posts
made through NewsOne.Net violate posting guidelines, email abuse@newsone.net
------------------------------
Date: Sat, 04 Aug 2001 10:48:14 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Splitting a text list into smaller lists?
Message-Id: <rkknmt81fc2nk8osme9dvm35dlorqf92o7@4ax.com>
ctverlane@NOSPAM.blackdahlia.zzn.com wrote:
>I have a long list of users (25000) of them, in a
>delimited text file. What I want to do is use Perl to take the long list and
>divide it up into 500 lists of 50 users each. So the task breaks down to 1)
>dividing the list into groups of 50, using the delimiter to show where each
>username ends, and then 2) writing each list to a separate file.
Every time your count modulo 50 reaches zero, open a new file. Untested:
my $fileno;
while(<>) {
if(($.-1)%50 == 0) {
open OUT, sprintf ">file%03d.txt", ++$fileno;
}
print OUT;
}
--
Bart.
------------------------------
Date: Sat, 04 Aug 2001 11:39:04 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Splitting a text list into smaller lists?
Message-Id: <3B6BDF36.2B67C03E@acm.org>
ctverlane@NOSPAM.blackdahlia.com wrote:
>
> In article <74f348f7.0108020727.18bd9b7d@posting.google.com>, Yves Orton
> <demerphq@hotmail.com> writes:
> >Incidentally to the OP, what kind of file do you have that uses the 4
> >character as a delimeter? Surely you might a username with a 4 in it?
> > Especially in 25000 users???
>
> Hello, Yves --
>
> It does sound strange. I should have given a bit more info in my original
> post.
>
> The list of 25000 users I am working with is a list of Common Names (cn)
> exported from an Oracle Internet Directory server and reformatted into MS
> Exchange distribution lists. That's why the input and the output will both
> be one long line. That's also why there's no chance of the numeral 4 (I
> picked 4 as something that wouldn't be reserved in Perl) appearing in any of
perl does not "reserve" any characters, you can use any character in a
perl string or regular expression.
> the cns, since we have a restriction in our OID that cns are only alpha
> characters.
>
> Thanks very much for the help you've given me with this. I am currently
> working on the problem using a combination of your code and John's code. I'd
> have it whipped already thanks to you guys, except that I modified the script
> to accept the input from a file instead of STDIN, and broke it... :-> I am
> learning a great deal from studying the code you both so kindly supplied.
> Many thanks!!
If you're having problems just post the code. I'm sure someone will jump
in and correct it. :-)
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 04 Aug 2001 11:46:23 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Splitting a text list into smaller lists?
Message-Id: <3B6BE0EE.586203E1@acm.org>
Bart Lateur wrote:
>
> ctverlane@NOSPAM.blackdahlia.zzn.com wrote:
>
> >I have a long list of users (25000) of them, in a
> >delimited text file. What I want to do is use Perl to take the long list and
> >divide it up into 500 lists of 50 users each. So the task breaks down to 1)
> >dividing the list into groups of 50, using the delimiter to show where each
> >username ends, and then 2) writing each list to a separate file.
>
> Every time your count modulo 50 reaches zero, open a new file. Untested:
>
> my $fileno;
> while(<>) {
> if(($.-1)%50 == 0) {
> open OUT, sprintf ">file%03d.txt", ++$fileno;
Tsk, tsk. You didn't test whether open() succeeded or failed.
> }
> print OUT;
> }
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 04 Aug 2001 10:34:02 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: string extraction
Message-Id: <3B6BCFF8.D8AF4EAF@acm.org>
Walnut wrote:
>
> On 23 Jul 2001 18:37:33 -0700, ssa1701@yahoo.co.uk (shaz) wrote:
>
> > Does anyone know how to go about extracting keywords from text files?
> > The following code only finds some words in the text file but does not
> > show the no of occurances of each word.
>
> If you only have a limited number of matches to count, why not suck
> the file into a single string then count matches. However, if you have
> an unknown number, it would be best to generalise the procedure:
>
> $number_xxx_found = $string =~ m!xxx!g;
> $number_yyy_found = $string =~ m!yyy!g;
> $number_zzz_found = $string =~ m!zzz!g;
I don't think so.
perl -le'$string = "one xxx two xxx three xxx four xxx\n";
$number_xxx_found = $string =~ m!xxx!g; print $number_xxx_found'
1
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 4 Aug 2001 09:33:54 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: string extraction
Message-Id: <slrn9mnue2.30j.tadmc@tadmc26.august.net>
shaz <ssa1701@yahoo.co.uk> wrote:
>Does anyone know how to go about extracting keywords from text files?
If you tell us how to recognize "keywords" we could tell you
how to count them.
>#!/usr/bin/perl -w
use strict; # take all the help you can get
>print "Enter the name of the word file, including extension: ";
>
>$file=<STDIN>;
my $file=<STDIN>;
>chomp $file;
>
>open(W, "$file") || die "Cannot open wordfile: $!";
>@lines=<W>;
>close(W);
I see several problems with the above section of code, the first
being a "biggie":
1) You should taint-check the contents of $file unless you
are *sure* that you can trust every single person who
can provide input.
2) You have useless double quotes in your open().
3) It would help in debugging to know the name of the file
that could not be opened.
4) You read the Whole Darn File but process it line-by-line.
You should read a process a single line at a time instead.
open(W, $file) || die "Cannot open '$file' $!";
>foreach(@lines)
my %wordcount;
while ( <W> ) {
$wordcount{$1}++ while /(\w+)/g;
}
foreach ( sort keys %wordcount ) {
print "$_ ==> $wordcount{$_}\n";
}
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 4 Aug 2001 09:57:55 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Subject : randomizing a hash
Message-Id: <996919075.161656884476542.gnarinn@hotmail.com>
In article <Pine.GSO.4.31.0108031410390.6470-100000@epic26.Stanford.EDU>,
Stuart Aaron White <superstu@stanford.edu> wrote:
>
>Will do. Here is the code:
>
>
>#!/usr/bin/perl -w
>srand;
>
>$vocab{"one"} = "uno";
>$vocab{"two"} = "dos";
>$vocab{"three"} = "tres";
>$vocab{"four"} = "cuatro";
>$vocab{"five"} = "cinco";
>$vocab{"six"} = "seis";
>$vocab{"seven"} = "siete";
>$vocab{"eight"} = "ocho";
>$vocab{"nine"} = "nueve";
>$vocab{"ten"} = "diez";
>
>@native = keys(%vocab); # create an array of native lang keys
>$numNative = @native; # find out the length of the array
>
>
>print ("@native\n");
>$randomKey = "$native[rand($native)]";
here -w give us the warning: Use of uninitialized value at t line 20.
this is because the variable $native has not been defined.
what you mean is:
$randomKey = "$native[rand(@native)]";
(@native in a scalar context is number of elements in array @native)
>chomp ($randomKey);
there is no need to chomp this
(snipped some)
>$randomValue = $vocab{"$randomKey"};
>chomp ($randomValue);
no need to chomp this
(snipped some)
>for ($i = 0; $i <= $numNative; $i++)
>{
> print ("what is the spanish word for $randomKey?\n");
now $randomKey is not changed within the loop
> $guess = <STDIN>;
> if ($guess eq $randomValue)
here you need to chomp
> {
> print ("You got it!\n");
> }
> else
> {
> print ("That is incorrect. The correct answer is:
>$randomValue\n");
> }
>}
it looks to me as you want to shuffle the keys, and go through them all.
try to use the code in the FAQ and come back if you still have problems
gnari
------------------------------
Date: Sat, 04 Aug 2001 11:10:09 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Understanding parsers
Message-Id: <k2lnmtkifnr6ok9nnp2ng6m1p0so0n3l2q@4ax.com>
David Wall wrote:
>I've been trying to learn how to use modules such as HTML::Parser and
>Parse::RecDescent, but I think I lack the background to completely
>understand the documentation. Should I get a book or two from the
>comp.compilers FAQ, or are there other references I should read first?
>URLs are ok, but I generally prefer books that I can read at leisure.
IMO HTML::Parser and Parse::RecDescent are completely unrelated beasts,
because IMO HTML is a completely different kind of "language" than what
Parse::RecDescent is designed for: programming languages. I'll only
discuss the latter group here.
But, anyway, have you seen Damian Conway's tutorial? It's on CPAN. Click
on the "tutorial/tutorial.html" link at the bottom of
<http://search.cpan.org/search?dist=Parse-RecDescent>.
I think this is a much gentler intro than the official teaching books,
such as the Compilers book by Aho, Ullman and Sethi (the Dragon Book).
Playing with Lex and Yacc, or rather Flex and Bison, can be fun too. You
need a C compiler, GNU's gcc is best for this purpose (free; djgpp for
DOS and Cygwin for Win32). See Microman's Lex and Yacc page,
<http://www.uman.com/lexyacc.shtml>.
If you still insist on a book, please take a practical one, on which
includes source code and which builds a compiler as a project. No
examples, sorry.
--
Bart.
------------------------------
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 1442
***************************************