Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > find similar characters in strings?

Reply
Thread Tools

find similar characters in strings?

 
 
jonas.huckestein@web.de
Guest
Posts: n/a
 
      09-22-2005
hi guys,

i've got the following problem: i have lots of strings with only 1 and
0 as characters. all are of the same length. now i need to create a
string which has a 1 where all of the strings have a 1 and a 0
everywhere else.

thanks in advance, you're great

--
greetings, jonas

 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      09-22-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> i've got the following problem: i have lots of strings with only 1 and
> 0 as characters. all are of the same length. now i need to create a
> string which has a 1 where all of the strings have a 1 and a 0
> everywhere else.


Have a look at
perldoc perlop

Specifically, the section on the & bit-wise operator.

Then make an attempt, and if it doesn't work, feel free to post your
attempt here for assistance in debugging it.

Paul Lalli

 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      09-22-2005
(E-Mail Removed) wrote:
> i've got the following problem: i have lots of strings with only 1 and
> 0 as characters. all are of the same length. now i need to create a
> string which has a 1 where all of the strings have a 1 and a 0
> everywhere else.


Not sure what it is you need, but if you are going to use Perl for the
task, it sounds as if the tr/// operator might be useful. Look up the
docs for that operator in

perldoc perlop

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      09-22-2005
Gunnar Hjalmarsson wrote:
> (E-Mail Removed) wrote:
> > i've got the following problem: i have lots of strings with only 1 and
> > 0 as characters. all are of the same length. now i need to create a
> > string which has a 1 where all of the strings have a 1 and a 0
> > everywhere else.

>
> Not sure what it is you need, but if you are going to use Perl for the
> task, it sounds as if the tr/// operator might be useful. Look up the
> docs for that operator in
>
> perldoc perlop
>


I agree that the OP was not at all clear in his description, but I
think he's looking to AND-together a sequence of strings, ala:
11010101
01101111
11011011
--------
01000001

If that's the case, I'm not clear on how tr/// would help here.

Of course, I could be wrong. It would have been nice if the OP had
posted some sample input and desired output to clarify his desires.
Gee, if only there were some sort of document that helped people learn
how to create a useful post. A sort of "guidelines", if you will...

Paul Lalli

 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      09-22-2005
Paul Lalli wrote:
> Gunnar Hjalmarsson wrote:
>> it sounds as if the tr/// operator might be useful. Look up the
>> docs for that operator in
>>
>> perldoc perlop

>
> I agree that the OP was not at all clear in his description, but I
> think he's looking to AND-together a sequence of strings, ala:
> 11010101
> 01101111
> 11011011
> --------
> 01000001
>
> If that's the case, I'm not clear on how tr/// would help here.


Me neither.

> Of course, I could be wrong.


Your interpretation does seem to fit the OP. Thanks for your possible
clarification.

> It would have been nice if the OP had
> posted some sample input and desired output to clarify his desires.
> Gee, if only there were some sort of document that helped people learn
> how to create a useful post. A sort of "guidelines", if you will...


Yeah, such a document would have been nice...

Actually, it's amazing how often programmers, who inevitably have the
ability of structured thinking, post vague and/or incomplete queries
about programming problems. It shows disrespect, whether they are aware
of the posting guidelines or not.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
Dr.Ruud
Guest
Posts: n/a
 
      09-23-2005
Paul Lalli schreef:

> Gee, if only there were some sort of document that helped people learn
> how to create a useful post. A sort of "guidelines", if you will...


I like to refer to "How to Ask Questions the Smart Way"

http://www.catb.org/~esr/faqs/smart-questions.html

but that might be broader than what you had in mind.

--
Affijn, Ruud

"Gewoon is een tijger."


 
Reply With Quote
 
Babacio
Guest
Posts: n/a
 
      09-23-2005
Gunnar Hjalmarsson.

> Actually, it's amazing how often programmers, who inevitably have the
> ability of structured thinking, post vague and/or incomplete queries
> about programming problems. It shows disrespect, whether they are
> aware of the posting guidelines or not.


Or it may show that they don't have so much hability of structured
thinking. I'm not speaking of the present case, no offense is meant,
but sometimes, that's the only rational solution.

--
Bé erre hue ixe eu elle, Bruxelles.
 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      09-23-2005
Dr.Ruud wrote:
> Paul Lalli schreef:
>> Gee, if only there were some sort of document that helped people learn
>> how to create a useful post. A sort of "guidelines", if you will...

>
> I like to refer to "How to Ask Questions the Smart Way"
>
> http://www.catb.org/~esr/faqs/smart-questions.html
>
> but that might be broader than what you had in mind.


Yes and no.

Paul's comment was ironic. The guidelines he'd like to see are posted
here twice a week, and they are also available on the web:
http://mail.augustmail.com/~tadmc/cl...uidelines.html

That link appears first if you search for

usenet perl guidelines

at Google.

Oh, and the smart-questions link you mentioned is included at the top of
the clpmisc guidelines.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
jonas.huckestein@web.de
Guest
Posts: n/a
 
      09-23-2005
ok guys,

thanks for the help ... in fact, i was quite sure, that my query was
not as vague as some of you appear to have understood it. i am also
aware, that it's not really helpful to criticize the people you're
asking for help, anyway i'd like you to reconsider discussing some ot
about posting guidelines (which i have read --- before i posted my
first msg) in this thread ...

Paul Lalli got it all right, i want to basically binary-add up
fixed-length ascii-strings which contain '0' and '1', character-wise
(10 + 11 = 10).

Anyway, my need has changed a bit (in fact the adding technique didn't
work ... *dough*). I need to have a 1 in the output string, if _the
majority of remaining strings_ (more than half) has a 1 there. My
attempt is to simply iterate through the indices $i of the strings and
then add up (arithmetically) all $i'th characters in all strings. If
they amount to more than half of the number of strings, i'll write a 1.
I didn't implement it yet (not working right now).

Just to clarify: I am indeed capable of writing such trivial snippets
myself. Yet in my (very recent) experience with perl i have learned,
that there are A LOT of very neat and short ways of doing such things.
Additionally If your project is supposed to scale properly you also
need to consider the speed of your implementation of such frequently
used code-snippets ... I think it's fun to think of such snippets which
are small, fast and do a lot, that's why I posted ...

--
greetings, jonas

 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      09-23-2005
(E-Mail Removed) wrote:
> ok guys,


To which guys are you speaking? Please quote some relevant context
when you post a reply. Have you seen the Posting Guidelines?

> thanks for the help ... in fact, i was quite sure, that my query was
> not as vague as some of you appear to have understood it.


That's precisely how we know that it *was* vague - that only *some*
people understood what you wanted. If what you posted had not been
vague, everyone would have understood it, and your chances for a
helpful response would have increased significantly.

Have you read the Posting Guidelines?

> i am also
> aware, that it's not really helpful to criticize the people you're
> asking for help, anyway i'd like you to reconsider discussing some ot
> about posting guidelines (which i have read --- before i posted my
> first msg) in this thread ...


Ahhh, so you have read them. But you choose not to follow them.
Explain to us, then, why any of us should make an attempt to help you
if you can't be bothered to follow the simple requests contained
therein?

Good bye.
Paul Lalli

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: convert unicode characters to visibly similar ascii characters Laszlo Nagy Python 6 07-02-2008 04:42 PM
Re: convert unicode characters to visibly similar ascii characters M.-A. Lemburg Python 0 07-02-2008 08:39 AM
Re: convert unicode characters to visibly similar ascii characters Terry Reedy Python 0 07-01-2008 07:46 PM
Any similar Webcam broadcasting site similar to youtube Chaudhry Nijjhar Computer Support 0 02-19-2008 11:48 PM
Find similar images using python Thomas W Python 15 04-04-2006 07:28 AM



Advertisments