Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

(crazyinsomniac) Re: Excluding words with more than three a

by crazyinsomniac (Prior)
on Dec 20, 2001 at 10:44 UTC ( [id://133418]=note: print w/replies, xml ) Need Help??


in reply to Excluding words with more than three a

Some monks have smelled homework ...
Hi Monks, I believe this is a simple question, but I ran in troubles when I tried to resolve it. Here is the problem: I've a list of words (a dictionary), and I need to exclude from it all the words that have more than three a, or more than two b, or more than two k. How can this be done? Many thanks for any advise. Best regards, Richard
I did not like this post because when I read "this is a simple question" and "I ran in troubles when I tried to resolve it" all I can respond with is "liar liar, fingers on fire".

As this is a site for "learning" perl, and enhancing your skill, after I see "How can this be done?", my first thought is "write a program", immediately after which I think "using perl" and then I think of a couple of potential strategies in non specific programming terms (pseudo code) and then I think in terms of accomplishing this with perl.

Since you don't even attempt to solve the problem, and you do not seem to be able to express your problem in programming terms, I assume this is a homework question (since practically nobody who is very new to perl would come up with such a problem for themselves to solve).

I sincerely doubt you even know how to write a simple "Hello world" program. I may be wrong, and surely if I am, i'd like you to tell me. I dont think I am, but it could be the case that your question asking strategy might be a little flawed or whatever.

Some monks replied the way I would've (if I they didn't) with some reading material, giving you everything you needed to know (strategy, functions, everything) without literally writing the program for you.

This is good, this is good advice. You say "Many thanks for any advise" which makes me a little sad because you cannot effectively get any advice that will do you any good (you might get a solution, but I seriously doubt it would do you much good).

Judging from the way you asked your question, you'll just grab a working solution without knowing how or even why it works. This is not learning. If you truly wanted to learn, you would've (should've) described a what strategy you tried using to solve your problem that failed you, so that someone can help you with appropriate advice (maybe you had a poor strategy, didn't know how to use a certain function or what have you, didn't know the syntaxt for ...).

I hope you read this and rethink how you'll ask the question next time.

Here are a few links I think everybody shold visit:
How to RTFM
On asking for help
Don't just provide a module name

 
___crazyinsomniac_______________________________________
Disclaimer: Don't blame. It came from inside the void

perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"

  • Comment on (crazyinsomniac) Re: Excluding words with more than three a

Replies are listed 'Best First'.
Re: (crazyinsomniac) Re: Excluding words with more than three a
by Anonymous Monk on Dec 20, 2001 at 22:17 UTC
    Hi crazyinsomniac,

    As my second language, I am sorry if my poor English mislead you to such funny exegesis of my post, and though I found some good points in it, other points were really dead wrong. Anyway, since some advises you offered seemed to me as good ones, I stand corrected and I would try to make a better move on future questions. So thanks for bring them.

    Also, you wondered about my perl skills. I am aware that they are not strong -- I'm only starting with perl and no, my question wasn't a homework assignment, as I am not taking perl lessons --, but they are not so weak as to couldn't write a "Hello world" program, as you unfortunately guessed. Here is a code snippet, the one I wrote to find out how many times a letter appears in the names of the days (please read my other replies to know more about the target problem). It runs fine under MacPerl, so if you like to check it out, you may need to change it a bit (I guess only the first line).

    #!perl -w use strict; my %semanal; while (<DATA>) { chomp; foreach my $letra (split //) { $semanal{$letra}++; } } foreach my $pal (sort keys %semanal) { print "$pal\t$semanal{$pal}\n"; } __DATA__ lunes martes miercoles jueves viernes sabado domingo output: a 3 b 1 c 1 d 2 e 8 g 1 i 3 j 1 l 2 m 3 n 3 o 4 r 3 s 6 t 1 u 2 v 2
    Thank you.

    Best regards,
    Richard
      Hey, I'm glad I was wrong (well, on some points). That's pretty good actually (as knowledge of m// and y// escaped me for a long time when I started learning perl) and that is how I would've approached it about two years ago. In terms of efficiency, and this is without any benchmarks of this particular problem, but from previous knowledge, your best bet would be to use y// aka tr//.

       
      ___crazyinsomniac_______________________________________
      Disclaimer: Don't blame. It came from inside the void

      perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://133418]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-25 21:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found