[30682] in Perl-Users-Digest
Perl-Users Digest, Issue: 1927 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 16 16:09:47 2008
Date: Thu, 16 Oct 2008 13:09:12 -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, 16 Oct 2008 Volume: 11 Number: 1927
Today's topics:
"Out of memory!" error with PerlIO::via <socyl@987jk.com.invalid>
compare strings <dirknbr@googlemail.com>
Re: compare strings <cartercc@gmail.com>
Re: compare strings <anfi@onet.eu>
Re: compare strings <tim@burlyhost.com>
Re: compare strings <tadmc@seesig.invalid>
Re: compare strings <john@castleamber.com>
Re: crisis Perl <cartercc@gmail.com>
Re: crisis Perl <cwilbur@chromatico.net>
Re: crisis Perl <cartercc@gmail.com>
Re: Filehandle Adapter for String? <bugbear@trim_papermule.co.uk_trim>
Re: Good reference for Math::MatrixReal? <zentara@highstream.net>
Re: Help: How to process output of a program <zentara@highstream.net>
Re: HOW TO LEARN LISP? <xahlee@gmail.com>
Re: HOW TO LEARN LISP? <xahlee@gmail.com>
mod_perl in Apache httpd <setesting001@gmail.com>
Re: Text::CSV problem sln@netherlands.com
Re: Textmining with Lisp <tzz@lifelogs.com>
Re: Textmining with Lisp <jurgenex@hotmail.com>
Re: Textmining with Lisp <xahlee@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 16 Oct 2008 18:32:11 +0000 (UTC)
From: kj <socyl@987jk.com.invalid>
Subject: "Out of memory!" error with PerlIO::via
Message-Id: <gd81bb$pbs$1@reader1.panix.com>
I've written a very simple PerlIO::via module, that implements only
two API functions:
sub PUSHED { bless \*PUSHED, $_[ 0 ] } # lifted from PerlIO::via::QuotedPrint
sub FILL {
my $in = $_[ 1 ];
while ( <$in> ) {
next if _is_blank_or_comment( $_ );
my ( $q, $e ) = ( split /\t/, $_, -1 )[ 3, 6 ];
return $_ unless length $q or $e !~ /$SOME_REGEXP/;
}
return undef;
}
When I use this layer like this:
open my $in, '<:via(MyLayer)', '/path/to/some/file' or die $!;
while ( <$in> ) { print }
...I get an "Out of memory!" error.
Intriguingly enough, if I run the same code through the Perl
debugger, it produces the correct output and the program terminates
without an error.
This behavior under the debugger is good news and bad news. The
good news is that it suggests that, whatever the problem is, it is
not something like a syntax error or some other error of usage
(e.g. wrong order of arguments to some function, etc.) in my code.
The bad news I can't use the debugger to get to the bottom of this!
In fact I've run out of ways to troubleshoot this problem.
Any ideas? (I'm open to the possibility of using something other
than PerlIO layers to implement this general filtering function.)
TIA!
Kynn
--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
------------------------------
Date: Thu, 16 Oct 2008 08:52:33 -0700 (PDT)
From: DirkN <dirknbr@googlemail.com>
Subject: compare strings
Message-Id: <54734e4d-15c5-4acf-be60-ac6f8faa266f@v56g2000hsf.googlegroups.com>
hi
I am comparing two string arrays, yet I get this warning:
Argument "sas " isn't numeric in numeric eq (==) at ./alljobs_read
line 22.
this is the code
if ("$user[$i]"=="$uniq[$j]") {..}
is there a different operator when comparing strings?
Dirk
------------------------------
Date: Thu, 16 Oct 2008 10:26:58 -0700 (PDT)
From: cartercc <cartercc@gmail.com>
Subject: Re: compare strings
Message-Id: <43712d4f-7d2f-41f8-9502-b2a374b08233@s50g2000hsb.googlegroups.com>
On Oct 16, 11:52=A0am, DirkN <dirk...@googlemail.com> wrote:
> hi
>
> I am comparing two string arrays, yet I get this warning:
> Argument "sas =A0 =A0 " isn't numeric in numeric eq (=3D=3D) at ./alljobs=
_read
> line 22.
>
> this is the code
> if ("$user[$i]"=3D=3D"$uniq[$j]") {..}
>
> is there a different operator when comparing strings?
>
> Dirk
eq
------------------------------
Date: Thu, 16 Oct 2008 19:39:51 +0200
From: Andrzej Adam Filip <anfi@onet.eu>
Subject: Re: compare strings
Message-Id: <g2874hym78@kevin.huge.strangled.net>
DirkN <dirknbr@googlemail.com> wrote:
> hi
>
> I am comparing two string arrays, yet I get this warning:
> Argument "sas " isn't numeric in numeric eq (==) at ./alljobs_read
> line 22.
>
> this is the code
> if ("$user[$i]"=="$uniq[$j]") {..}
>
> is there a different operator when comparing strings?
>
> Dirk
if ($user[$i] eq $uniq[$j]) {..}
--
[pl>en Andrew] Andrzej Adam Filip : anfi@onet.eu : anfi@xl.wp.pl
Why won't you let me kiss you goodnight? Is it something I said?
-- Tom Ryan
------------------------------
Date: Thu, 16 Oct 2008 11:12:10 -0700
From: Tim Greer <tim@burlyhost.com>
Subject: Re: compare strings
Message-Id: <_tLJk.4830$Tu6.2085@newsfe14.iad>
DirkN wrote:
> hi
>
> I am comparing two string arrays, yet I get this warning:
> Argument "sas " isn't numeric in numeric eq (==) at ./alljobs_read
> line 22.
>
> this is the code
> if ("$user[$i]"=="$uniq[$j]") {..}
>
> is there a different operator when comparing strings?
>
> Dirk
== is only a numeric check and can have unexpected results unless you
know what it does and why. Use eq instead for non numeric checks.
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
------------------------------
Date: Thu, 16 Oct 2008 13:35:54 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: compare strings
Message-Id: <slrngff2ca.ns8.tadmc@tadmc30.sbcglobal.net>
DirkN <dirknbr@googlemail.com> wrote:
> hi
>
> I am comparing two string arrays, yet I get this warning:
> Argument "sas " isn't numeric in numeric eq (==) at ./alljobs_read
> line 22.
>
> this is the code
> if ("$user[$i]"=="$uniq[$j]") {..}
>
> is there a different operator when comparing strings?
Yes.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: 16 Oct 2008 18:53:36 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: compare strings
Message-Id: <Xns9B398D5728808castleamber@130.133.1.4>
DirkN <dirknbr@googlemail.com> wrote:
> hi
>
> I am comparing two string arrays, yet I get this warning:
> Argument "sas " isn't numeric in numeric eq (==) at ./alljobs_read
> line 22.
>
> this is the code
> if ("$user[$i]"=="$uniq[$j]") {..}
Read
perldoc -q always
(What's wrong with always quoting "$vars")
> is there a different operator when comparing strings?
Yes. I recommend to study
perldoc perlop
(section Relational Operators)
--
John http://johnbokma.com/ - Hacking & Hiking in Mexico
Perl help in exchange for a gift:
http://johnbokma.com/perl/help-in-exchange-for-a-gift.html
------------------------------
Date: Thu, 16 Oct 2008 05:48:11 -0700 (PDT)
From: cartercc <cartercc@gmail.com>
Subject: Re: crisis Perl
Message-Id: <5494703f-77dd-47ac-a542-0afed0900554@l42g2000hsc.googlegroups.com>
Thank you all. Every post had something valuable, and I appreciate all
the input.
As to writing good code to begin with, it's easier said than done.
When it's almost midnight, and you've been at work for about 14 hours,
and you have people (not just your manager, but his boss, the big
boss, and the guy in charge of the project) calling you every 15
minutes, and the people you had promised things mad at you because you
were tasked with doing a job THAT THEY KNEW ABOUT FOUR WEEKS AGO BUT
DIDN'T GIVE YOU A HEADS UP (!!!) ... well, pretty code takes a back
seat.
Particularly when the guy who should be showering you with praise for
performing over and beyond the call of duty will the very next day
will blame the programmer for the project being late, omitting the
fact that the programmer wasn't even told about the project until the
day of the deadline.
My solution is to teach my manager (who came by his position as a
result of a management background and has no grounding in IT ...
couldn't program Hello World if his life depended on it) how to
program under the explanation that he should know what's involved. The
result: he hasn't learned how to program but he HAS learned how to
look at a project from a technical point of view.
On Oct 16, 12:48=A0am, Charlton Wilbur <cwil...@chromatico.net> wrote:
> >>>>> "cc" =3D=3D cartercc =A0<carte...@gmail.com> writes:
>
> =A0 =A0 cc> How do you deal with a manager who tells you to leave a scrip=
t
> =A0 =A0 cc> alone, when you know good and well that it's such poorly writ=
ten
> =A0 =A0 cc> code that it will be extremely hard to maintain, and perhaps
> =A0 =A0 cc> will be buggy as well? =A0Getting another job isn't an option=
, and
> =A0 =A0 cc> firing the manager isn't an option, either.
>
> Educate the manager. =A0Keeping shoddy code in production is a gamble:
> you're gambling that the cost of fixing the code *now* is higher than
> the cost of fixing it when it breaks or when there's a crisis. =A0This is
> almost never the case, and a competent manager will realize this. =A0But
> the risk of fixing the code now is that you'll break something that's
> working, and that's often the key factor in "if it ain't broke, don't
> fix it" decisions.
I mostly grab data from one place, massage it, and send it to another
place. The format of the data I get, and/or the format of the final
form, changes several times a year. It's not that the code breaks a
lot, but that the specifications change. Since we can't 'fix' the
specifications, we have to 'fix' the code, and guess who gets blamed
if the code isn't 'fixed.'
Thanks, CC.
------------------------------
Date: Thu, 16 Oct 2008 10:34:43 -0400
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: crisis Perl
Message-Id: <86skqwr4l8.fsf@mithril.chromatico.net>
>>>>> "cc" == cartercc <cartercc@gmail.com> writes:
cc> As to writing good code to begin with, it's easier said than
cc> done. When it's almost midnight, and you've been at work for
cc> about 14 hours, and you have people (not just your manager, but
cc> his boss, the big boss, and the guy in charge of the project)
cc> calling you every 15 minutes,
Ah, this is fixable. Use your backbone: "I am working on solving the
problem as fast as I can. Every minute I spend explaining the status to
four different people is a minute I am not spending solving the problem.
Every two-minute interruption because of a phone call means a
five-minute delay into getting back to where I was in the work. Until
the problem is solved, I am going to ignore the phone, and give periodic
updates to $manager, who can update $boss, $big_boss, and
$guy_in_charge."
cc> Particularly when the guy who should be showering you with
cc> praise for performing over and beyond the call of duty will the
cc> very next day will blame the programmer for the project being
cc> late, omitting the fact that the programmer wasn't even told
cc> about the project until the day of the deadline.
This sounds like a toxic work environment. If it's a poor manager, the
solution is probably to grin and bear it -- the other people who work
with him don't believe him any more than you do. If the rot goes all
the way to the top, though, it's probably time to polish your resume.
cc> I mostly grab data from one place, massage it, and send it to
cc> another place. The format of the data I get, and/or the format
cc> of the final form, changes several times a year. It's not that
cc> the code breaks a lot, but that the specifications change. Since
cc> we can't 'fix' the specifications, we have to 'fix' the code,
cc> and guess who gets blamed if the code isn't 'fixed.'
So you write your test suite to have an example of data in the format
you expect to receive and in the format you expect to produce.
And you need to start building an expectation of a certain lag between
you being notified of the specification change and the new system being
in place. If there's actually *blame* being assigned for an obvious
managerial defect, this sounds even more like a toxic work environment.
I've been there, I've done that, and I've got scars to show for it. My
solution was to painstakingly document every process I was responsible
for, so that the manager-types could see that there was 30+ pages of
information about how data was retrieved from point A, massaged, and
provided at point B. This prevented them from thinking it was trivial;
and when my resume was fully polished and I left that job, no doubt the
documentation was a great comfort to my replacement.
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
Date: Thu, 16 Oct 2008 10:14:02 -0700 (PDT)
From: cartercc <cartercc@gmail.com>
Subject: Re: crisis Perl
Message-Id: <8ccca22f-3526-4b6c-9b7c-fcd774f309be@p58g2000hsb.googlegroups.com>
On Oct 16, 11:40=A0am, Andrew DeFaria <And...@DeFaria.com> wrote:
> You switched from "good code" to "pretty code". It's not necessarily the
> same! What's that saying again? Oh yes "A lack of preparation on your
> part does not constitute an emergency on my part!". Get a backbone and
> tell them that. Stand your ground or quite frankly get out. Life is too
> short to put up with other people's crap if they really are behaving as
> you describe.
This is an academic environment. The people are pretty good,
particularly the IT dept (all hardware guys except for me). Most of
our requirements come from the academic side, faculty, deans,
provosts, vice chancellors, and the like, and they commonly don't know
the right questions to ask or sometimes even what they want!
It's a good job, little stress, lots of time off, interesting work,
the only drawback is the pay but there are always tradeoffs.
> > Particularly when the guy who should be showering you with praise for
> > performing over and beyond the call of duty will the very next day
> > will blame the programmer for the project being late, omitting the
> > fact that the programmer wasn't even told about the project until the
> > day of the deadline.
>
> Such a manager should give you the time the next day to clean stuff up.
> If he doesn't then get a new manager!
I don't think this is intentional, but more of not understanding the
process. I quite routinely get my work out real quick, and my clients
have come to expect results well within the hour of making the
request. I've automated so much of what I do that much of it is
mindlessly pushing buttons. From their point of view, if I take a long
time with something, it's obviously my fault -- but this isn't is bad
as it sounds because I'm the only guy who knows how to do what I do
(yes, we are one deep) and the praises I get sometimes are unearned.
A story: We generate several thousand contracts five times a year,
using a script I wrote. I got a panic call a couple of hours ago
because the data file had the contract amounts all as zeros. So I
started at the bottom of the stack, checking the inputs of the
functions. Yep. All zeros. Worked my way up the stack to the very top.
Zeros all the way up. Then, I looked at the input file and wouldn't
you know it -- the script expects an eleven column input file but the
actual input file contained ten columns. The reason we were getting
zeros was that the relevant column had been shifted one to the left.
Once we revised the input file to the correct format, all was fine.
Yeah, this is a routine event in the World of Work, but it's kind of
interesting that we get to deal with people issues as well as logical
and language issues, "If you would match the input file to the
documentation you would have seen that you were using the wrong input
file, and saved both yourself and me a panic attack and a wasted
morning."
CC
------------------------------
Date: Thu, 16 Oct 2008 10:19:34 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: Filehandle Adapter for String?
Message-Id: <G9qdnY0tv7e6mmrVnZ2dneKdnZydnZ2d@posted.plusnet>
John Bokma wrote:
> bugbear <bugbear@trim_papermule.co.uk_trim> wrote:
>
>> It is quite common for modules to be able to handle
>> files, or filehandles, but not strings.
>>
>> In order to ease some of the uses I have for
>> such modules, in an age where a 1 Mb scalar
>> is reasonable, I would quite like to have a class/module
>> that Implements FileHandle, but is (really)
>> a scalar(string).
>>
>> A readonly version of this would present
>> the string as a readable FileHandle,
>
> my $yourstring = "hello, world";
> open my $fh, '<', \$yourstring or ...
>
>
>> and a writeonly
>> version would allow writing/printing to a string,
>> which could be picked up later.
>
> open my $fh, '>', \$yourstring or ...
>
> "
> Since v5.8.0, perl has built using PerlIO by default. Unless
> you've changed this (i.e. Configure -Uuseperlio), you can open
> file handles to "in memory" files held in Perl scalars via:
> "
>
> perldoc -f open
Well, that couldn't be much easier to use, or harder to find!
It *never* occurred to me that it would be that easy, and (thus)
I never looked in perldoc -f open.
Thanks for the (perfect) reply.
BugBear
------------------------------
Date: Thu, 16 Oct 2008 07:00:14 -0400
From: zentara <zentara@highstream.net>
Subject: Re: Good reference for Math::MatrixReal?
Message-Id: <dg7ef4hednei5nr8p1p56fkgilfnc6ee7i@4ax.com>
On Wed, 15 Oct 2008 11:29:15 -0500, mike_l_rossREMOVE@REMOVEcomcast.net
wrote:
>I found the man pages for the Math::MatrixReal module somewhat lacking in
>code examples. Does anyone know of a better source of reference info for
>this module? Book, web page, I'll take anything showing me how to properly
>declare the variables used for the arrays. Thanks for any pointers.
>
>Mike Ross
See
http://perlmonks.org?node_id=347877
for some simple examples and explanations.
zentara
------------------------------
Date: Thu, 16 Oct 2008 07:12:13 -0400
From: zentara <zentara@highstream.net>
Subject: Re: Help: How to process output of a program
Message-Id: <ls7ef45j73ec03op253eknku6fujcg0j35@4ax.com>
On 15 Oct 2008 18:06:31 GMT, xhoster@gmail.com wrote:
>Tim Greer <tim@burlyhost.com> wrote:
>>
>> Also, IPC::Open2 does work on Win32 or am I mistaken?
>
>Based on my test, I'd say it doesn't work on Win32, or at least not
>well.
See
http://perlmonks.org?node_id=621058
http://perlmonks.org?node_id=714691
for good examples of how to setup non-blocking pipe reads on win32
zentara
------------------------------
Date: Thu, 16 Oct 2008 10:52:47 -0700 (PDT)
From: "xahlee@gmail.com" <xahlee@gmail.com>
Subject: Re: HOW TO LEARN LISP?
Message-Id: <25e22742-f4da-4535-a512-0fa6f6731047@s1g2000prg.googlegroups.com>
On Oct 16, 3:28 am, p...@informatimago.com (Pascal J. Bourguignon)
wrote:
> MasterZiv <master...@gmail.com> writes:
> > On Oct 13, 11:33 am, jack <jackl...@gmail.com> wrote:
>
> >> is lisp language hard to learn ?
>
> > I would say, no.
> > I mean, the language itself is not that difficult
> > to learn. The main problem is the great shift in mind you have
> > to do to understand how complex things can be made easy.
> > This is what LISP really does.
>
> Indeed. When you read a book such as SICP, there's almost no material
> about learning scheme. These languages are very small, R5RS is 50
> pages, Common Lisp is really just 17 special operators (and associated
> notions). All the rest is libraries.
>
> But indeed that may be a shock for learners. Learning lisp is easy,
> you don't spend a semester on it, just a couple of weeks. Then the
> rest of the semester is spent on learning more interesting things such
> as algorithms, paradigms, AI, etc. This means _real_ _work_!
>
> When you learn C++, you can spend the year learning by heart little
> insignificant syntactic details, and when you're done, you still have
> a low level language where you need to implement (or integrate
> libraries) even the most basic mechanisms such as bignums.
The above is a typical Evangelical bullshit. A warm and fuzzy ball of
words, lacking any substance and reality. Similar sentiment you'll get
from perl fanatics about perl, and java fanatics about java.
its value is that its plausible and pleasing to hear for the group, so
it gets spread as gospels.
All you have to do to test its validity is to publish it outside of
your community. (such as cross-posting lang X gospels to lang X, Y, Z,
groups) Even though lots of response will be senseless knee-jerking
drivels, but in the discussion, you'll start to see how vain was your
beliefs.
Xah
=E2=88=91 http://xahlee.org/
=E2=98=84
------------------------------
Date: Thu, 16 Oct 2008 11:01:01 -0700 (PDT)
From: "xahlee@gmail.com" <xahlee@gmail.com>
Subject: Re: HOW TO LEARN LISP?
Message-Id: <5ebdd082-1881-476f-81ef-5eacc987de73@s20g2000prd.googlegroups.com>
Pascal J. Bourguignon wrote:
> Indeed. When you read a book such as SICP, there's almost no material
> about learning scheme. These languages are very small, R5RS is 50
> pages,
When i read SICP, it was R4RS.
> Common Lisp is really just 17 special operators (and associated
> notions). All the rest is libraries.
LOL. Your mom is 17 special operators and associated notions.
> But indeed that may be a shock for learners. Learning lisp is easy,
> you don't spend a semester on it, just a couple of weeks. Then the
> rest of the semester is spent on learning more interesting things such
> as algorithms, paradigms, AI, etc. This means _real_ _work_!
Learning Mathematica is even easier. Just couple days instead of
lisp's weeks. Then, you spend the rest of your life learning
mathematics.
> When you learn C++, you can spend the year learning by heart little
> insignificant syntactic details,
Such as lisp's =E2=80=9C`'#;@,|=E2=80=9D syntactic details?
> and when you're done, you still have
> a low level language where you need to implement (or integrate
> libraries) even the most basic mechanisms such as bignums.
and when you are done leaning lisp's syntactical warts, you still need
to implement (or integrate libraries), even the most basic pattern
matching facilities, infinite precision arithmetic, mathematical
functions.
-----------------------------------
Pascal's writings above is a typical Evangelical bullshit. A warm and
fuzzy ball of words, lacking any substance and reality. Similar
sentiment you'll get from perl fanatics about perl, and java fanatics
about java.
its value is that its plausible and pleasing to hear for the group, so
it gets spread as gospels.
All you have to do to test its validity is to publish it outside of
your community. (such as cross-posting lang X gospels to lang X, Y, Z,
groups) Even though lots of response will be senseless knee-jerking
drivels, but in the discussion, you'll start to see how vain was your
beliefs.
Xah
=E2=88=91 http://xahlee.org/
=E2=98=84
------------------------------
Date: Thu, 16 Oct 2008 09:17:56 -0700 (PDT)
From: Roy M <setesting001@gmail.com>
Subject: mod_perl in Apache httpd
Message-Id: <4fb51cbc-7f60-4e54-89e8-b3e7a73092a2@t18g2000prt.googlegroups.com>
According to the httpd document:
http://httpd.apache.org/docs/2.2/stopping.html
Even using `apachectl restart`, the parent process is still alive
during the restart.
So it that when using mod_perl, it is safe to only restart the httpd,
without stop => start ?
Thanks.
------------------------------
Date: Thu, 16 Oct 2008 16:29:15 GMT
From: sln@netherlands.com
Subject: Re: Text::CSV problem
Message-Id: <nrqef49rie0eg141mfhi3m3gjlqvdq5bvg@4ax.com>
On Wed, 15 Oct 2008 20:22:15 -0500, Tad J McClellan <tadmc@seesig.invalid> wrote:
>sln@netherlands.com <sln@netherlands.com> wrote:
>
>
>> $tmp =~ s/\s+$//s;
> ^
> ^
>
>What is the point of the s modifier here?
It is a typo. \s includes newline. You know that
------------------------------
Date: Thu, 16 Oct 2008 08:17:05 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Textmining with Lisp
Message-Id: <86r66gel2m.fsf@lifelogs.com>
On Wed, 15 Oct 2008 16:27:32 -0700 (PDT) "xahlee@gmail.com" <xahlee@gmail.com> wrote:
xc> On Oct 15, 1:48 pm, Francogrex <fra...@grex.org> wrote:
>> Hi all, I'm trying to write a little program that searches through a
>> text for a specific word and then outputs the sentence containg the
>> word as well as the sentence before and the sentence after; for
>> example the little text below (stored in "c:/target.txt"):
>>
>> I wandered lonely as a cloud
>> That floats on high over vales and hills,
>> When all at once I saw a crowd,
>> A host, of golden daffodils;
>> Beside the lake, beneath the trees,
>> Fluttering and dancing in the breeze.
>> William Wordsworth
>>
>> Now if I search for the word daffodils I should get as output:
>>
>> > When all at once I saw a crowd, A host, of golden daffodils;Beside the lake, beneath the trees,
xc> this is much easier in emacs lisp.
xc> Here's the code that does what u want, quickly coded in 11 minutes.
xc> (writing this post took more than 11 min.)
xc> (defun my-search (file word)
xc> "search `file' and return adjacent lines containing the `word'.
xc> `file' is a file path. `word' is a string."
xc> (interactive)
xc> (let (neighborLines p1 p2)
xc> (find-file file)
xc> (while (search-forward word nil t)
xc> (save-excursion
xc> (move-beginning-of-line 1)
xc> (previous-line)
xc> (setq p1 (point))
xc> (next-line 2)
xc> (move-end-of-line 1)
xc> (setq p2 (point))
xc> (setq neighborLines (buffer-substring-no-properties p1 p2))
xc> (print neighborLines)
xc> )
xc> )
xc> ))
xc> (my-search "xx.el" "daffodils")
xc> as you can see, the code is geared toward text processing, so you
xc> don't have to deal with nitty-gritty details. (for example, it has
xc> primitives that deals with lines, sentences, syntax, and handles file
xc> encoding, backup, access, permissions etc all automatically)
xc> Basically, elisp system is the best text processing language, even
xc> more powerful than Perl.
For this particular problem, "grep -C 1 daffodils textfile" would be the
best solution. It would be significantly faster than ELisp or Perl,
especially for large files.
The equivalent in Perl, which would work on any size file (like the grep
solution):
perl -n -e'@out[0,1,2] = ($out[1], $out[2], $_); print @out if $out[1] =~ m/daffodils/;' FILE1 FILE2 ...
I strongly disagree ELisp is the best text processing language. It's
generally OK for small files, but really too slow and memory-intensive
for more demanding tasks. Perl is generally a good compromise between
memory usage, speed, ease of development, and features for any file size.
Ted
------------------------------
Date: Thu, 16 Oct 2008 07:33:09 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Textmining with Lisp
Message-Id: <krjef4p7589te7rqv6a2q944derbjetor0@4ax.com>
Ted Zlatanov <tzz@lifelogs.com> wrote:
>On Wed, 15 Oct 2008 16:27:32 -0700 (PDT) "xahlee@gmail.com" <xahlee@gmail.com> wrote:
>
>xc> On Oct 15, 1:48 pm, Francogrex <fra...@grex.org> wrote:
>>> Hi all, I'm trying to write a little program that searches through a
>>> text for a specific word and then outputs the sentence containg the
>>> word as well as the sentence before and the sentence after; for
>>> example the little text below (stored in "c:/target.txt"):
>>>
>>> I wandered lonely as a cloud
>>> That floats on high over vales and hills,
>>> When all at once I saw a crowd,
>>> A host, of golden daffodils;
>>> Beside the lake, beneath the trees,
>>> Fluttering and dancing in the breeze.
>>> William Wordsworth
>>>
>>> Now if I search for the word daffodils I should get as output:
>>>
>>> > When all at once I saw a crowd, A host, of golden daffodils;Beside the lake, beneath the trees,
You seem to have an uncommon defintion of 'sentence'. To me the whole
poem is one single sentence.
>xc> this is much easier in emacs lisp.
[...]
>xc> as you can see, the code is geared toward text processing, so you
>xc> don't have to deal with nitty-gritty details. (for example, it has
>xc> primitives that deals with lines, sentences, syntax, and handles file
>xc> encoding, backup, access, permissions etc all automatically)
>
>xc> Basically, elisp system is the best text processing language, even
>xc> more powerful than Perl.
Oh, sorry for replying, didnt' see that this was just another bait from
our second-favourite troll.
jue
------------------------------
Date: Thu, 16 Oct 2008 11:09:48 -0700 (PDT)
From: "xahlee@gmail.com" <xahlee@gmail.com>
Subject: Re: Textmining with Lisp
Message-Id: <203f3a72-1e12-41db-a350-841c0997d3ce@t18g2000prt.googlegroups.com>
On Oct 16, 6:17 am, Ted Zlatanov <t...@lifelogs.com> wrote:
> On Wed, 15 Oct 2008 16:27:32 -0700 (PDT) "xah...@gmail.com" <xah...@gmail=
.com> wrote:
>
> xc> On Oct 15, 1:48 pm, Francogrex <fra...@grex.org> wrote:
>
>
>
> >> Hi all, I'm trying to write a little program that searches through a
> >> text for a specific word and then outputs the sentence containg the
> >> word as well as the sentence before and the sentence after; for
> >> example the little text below (stored in "c:/target.txt"):
>
> >> I wandered lonely as a cloud
> >> That floats on high over vales and hills,
> >> When all at once I saw a crowd,
> >> A host, of golden daffodils;
> >> Beside the lake, beneath the trees,
> >> Fluttering and dancing in the breeze.
> >> William Wordsworth
>
> >> Now if I search for the word daffodils I should get as output:
>
> >> > When all at once I saw a crowd, A host, of golden daffodils;Beside t=
he lake, beneath the trees,
>
> xc> this is much easier in emacs lisp.
>
> xc> Here's the code that does what u want, quickly coded in 11 minutes.
> xc> (writing this post took more than 11 min.)
>
> xc> (defun my-search (file word)
> xc> "search `file' and return adjacent lines containing the `word'.
> xc> `file' is a file path. `word' is a string."
> xc> (interactive)
> xc> (let (neighborLines p1 p2)
> xc> (find-file file)
> xc> (while (search-forward word nil t)
> xc> (save-excursion
> xc> (move-beginning-of-line 1)
> xc> (previous-line)
> xc> (setq p1 (point))
> xc> (next-line 2)
> xc> (move-end-of-line 1)
> xc> (setq p2 (point))
> xc> (setq neighborLines (buffer-substring-no-properties p1 p2))
> xc> (print neighborLines)
> xc> )
> xc> )
> xc> ))
>
> xc> (my-search "xx.el" "daffodils")
>
> xc> as you can see, the code is geared toward text processing, so you
> xc> don't have to deal with nitty-gritty details. (for example, it has
> xc> primitives that deals with lines, sentences, syntax, and handles file
> xc> encoding, backup, access, permissions etc all automatically)
>
> xc> Basically, elisp system is the best text processing language, even
> xc> more powerful than Perl.
>
> For this particular problem, "grep -C 1 daffodils textfile" would be the
> best solution. It would be significantly faster than ELisp or Perl,
> especially for large files.
>
> The equivalent in Perl, which would work on any size file (like the grep
> solution):
>
> perl -n -e'@out[0,1,2] =3D ($out[1], $out[2], $_); print @out if $out[1] =
=3D~ m/daffodils/;' FILE1 FILE2 ...
Nice code.
> I strongly disagree ELisp is the best text processing language.
> It's generally OK for small files, but really too slow and
> memory-intensive for more demanding tasks. Perl is generally a good
> compromise between memory usage, speed, ease of development, and
> features for any file size.
Thanks. From my experience, i also feel similar.
To summarize, i think that for small scale tasks, elisp is far more
powerful and flexible for text processing (mostly due to its buffer
datatype and the whole associated functions (e.g. the point) and few
thousand functions designed to manipulate text)
For larger scale tasks where a file size is too large to be read into
memory comfortably, then i think elisp is basically not usable.
Xah
=E2=88=91 http://xahlee.org/
=E2=98=84
------------------------------
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 1927
***************************************