Quick easy question...

B

big.e12

I am just getting started in perl and I was wondering if someone could
help me out... I am trying to write a script that counts the number of
times a word appears in the input. Can anyone help me?
 
A

Anno Siegel

Telling your readers, first thing, that you think the question is
"quick and easy" is not very clever. I, for one, don't like to
be told what the question is like by someone who obviously doesn't
have the slightest idea how to solve it.
I am just getting started in perl and I was wondering if someone could
help me out... I am trying to write a script that counts the number of
times a word appears in the input. Can anyone help me?

Homework? What have you tried so far, and in which way does it fail
to solve the problem?

Anno
 
S

Sherm Pendley

big.e12 said:
I am just getting started in perl and I was wondering if someone could
help me out... I am trying to write a script that counts the number of
times a word appears in the input. Can anyone help me?

What have you tried so far? What were the results, and how were they
different from what you expected them to be?

Have you read the posting guidelines for this group? They're posted here
twice a week.

sherm--
 
R

Richard Gration

I am just getting started in perl and I was wondering if someone could
help me out... I am trying to write a script that counts the number of
times a word appears in the input. Can anyone help me?

How about this?

perl -e 'print [map{$t+=$_=~s/homework//g}<STDIN>]->[-1]'
 
A

Anno Siegel

Richard Gration said:
I am just getting started in perl and I was wondering if someone could
help me out... I am trying to write a script that counts the number of
times a word appears in the input. Can anyone help me?

How about this?

perl -e 'print [map{$t+=$_=~s/homework//g}<STDIN>]->[-1]'

Hey, that's a joke, right? You can't be serious...

Anno
 
R

Richard Gration

Richard Gration said:
I am just getting started in perl and I was wondering if someone
could help me out... I am trying to write a script that counts the
number of times a word appears in the input. Can anyone help me?

How about this?

perl -e 'print [map{$t+=$_=~s/homework//g}<STDIN>]->[-1]'

Hey, that's a joke, right? You can't be serious...

Anno

Well, it's a joke in the sense that I thought I smelled homework therefore
tried to obfuscate the answer :)

But it's not a joke in the sense that it does work ... at least I think it
does ... I tested it on a some inputs and it seemed OK ... is it faulty?

Rich
 
A

Alfred Z. Newmane

Richard Gration said:
How about this?

perl -e 'print [map{$t+=$_=~s/homework//g}<STDIN>]->[-1]'

Hey, that's a joke, right? You can't be serious...

Anno

Well, it's a joke in the sense that I thought I smelled homework therefore
tried to obfuscate the answer :)

I may have just been someone who is just starting out. I've yet to se
Perl taught in college courses (I haven't seen any available in any
colleges around here nor where I've attended.)

Even if it was home work, sometimes it can help a learner from working
by examples. When I was first learning Perl a few years ago, I was
constantly trying new things, see what would work, looking up examples
online and in docs, and in deja/google-groups.

True he could of found the answer by looking elsewhere (I think this one
might be in the FAQ), though I think pushing someone like this in the
right direction, who may not have /yet/ gotten a feel of how things work
around here. That is, tell them where the many good places are to look
(google, FAQ, perldoc, etc), instead of confusing them even more :)
 
A

Anno Siegel

Richard Gration said:
Richard Gration said:
On Tue, 14 Dec 2004 07:57:55 -0800, big.e12 wrote:

I am just getting started in perl and I was wondering if someone
could help me out... I am trying to write a script that counts the
number of times a word appears in the input. Can anyone help me?

How about this?

perl -e 'print [map{$t+=$_=~s/homework//g}<STDIN>]->[-1]'

Hey, that's a joke, right? You can't be serious...

Anno

Well, it's a joke in the sense that I thought I smelled homework therefore
tried to obfuscate the answer :)

But it's not a joke in the sense that it does work ... at least I think it
does ... I tested it on a some inputs and it seemed OK ... is it faulty?

For an exact word count, the regex should be /\bhomework\b/. Without
the word-boundary anchors, "homeworks" would be counted too.

Otherwise, I guess it works. In fact, it works far more than should.

Anno
 
R

Richards Noah \(IFR LIT MET\)

Alfred Z. Newmane said:
Richard Gration said:
How about this?

perl -e 'print [map{$t+=$_=~s/homework//g}<STDIN>]->[-1]'

Hey, that's a joke, right? You can't be serious...

Anno

Well, it's a joke in the sense that I thought I smelled homework therefore
tried to obfuscate the answer :)

I may have just been someone who is just starting out. I've yet to se
Perl taught in college courses (I haven't seen any available in any
colleges around here nor where I've attended.)

Perl is tought in schools near mine and including mine (RIT). While that
has
no bearing on whether or not this question was homework, you're reasoning
doesn't really debunk anything (well, I've never seen it, so it must not
exist).
Even if it was home work, sometimes it can help a learner from working
by examples. When I was first learning Perl a few years ago, I was
constantly trying new things, see what would work, looking up examples
online and in docs, and in deja/google-groups.

Learning by example is incredibly useful, but learning by others doing your
homework questions for you isn't exactly ethical.
True he could of found the answer by looking elsewhere (I think this one
might be in the FAQ), though I think pushing someone like this in the
right direction, who may not have /yet/ gotten a feel of how things work
around here. That is, tell them where the many good places are to look
(google, FAQ, perldoc, etc), instead of confusing them even more :)

Whether or not you are familiar with the newsgroup, submitting homework
questions for others to due is tantamount to plagiarism. Of course, this
may
not be homework, which is why people responded with "what have you tried
so far, and what has occurred?"

The sad thing, really, is that people do resort to newsgroups to answer
homework
questions. It has happened at my school often enough for professors to
check all
major homework/project submissions against each other (in terms of coding
styles,
which is automated by some program/script) and some minor homework against
internet sources.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top