Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: read string (which is in binary) and make decision

by CountZero (Bishop)
on Nov 17, 2012 at 08:39 UTC ( #1004290=note: print w/ replies, xml ) Need Help??


in reply to read string (which is in binary) and make decision

use Modern::Perl; while (<DATA>) { chomp; say "$_ : ", ( /^0+$/ or /^1+$/ ) ? 'PASS' : ( /^0+1+$/ or /^1+0+$/ ) ? 'CLEAN' : 'FAIL'; } __DATA__ 000000 111111 000011111 1111111000 10001001110000011
Output:
000000 : PASS 111111 : PASS 000011111 : CLEAN 1111111000 : CLEAN 10001001110000011 : FAIL

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics


Comment on Re: read string (which is in binary) and make decision
Select or Download Code
Re^2: read string (which is in binary) and make decision
by hey_frind (Initiate) on Nov 17, 2012 at 09:50 UTC
    Thank you very much Count Zero for prompt. Really appreciate the help. the code works great... I have used it in reg ex actually because my perl set up does not recongize Modern::Perl line. downloaded from CPAN , but then install was complaining on other modules missing (Build, Metadata....) . downloaded all of them, did install but still the install on Modern package complains. is there a single place where I can install the whole package? thanks Natasa
      What kind and version of Perl are you using on what OS?

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      My blog: Imperial Deltronics

      It will be very helpful to your learning experience if you have access to a Perl installation that allows downloading and installation of CPAN modules. It will be worth some effort to achieve this.

      However, for the purposes of running CountZero's example code, the two most important modules ('pragmas' in Perlish) to use in place of Modern::Perl and at the beginning of all code are
          use warnings;
          use strict;
      (IMHO). If your Perl installation does not offer these fundamental modules, it should be considered seriously b0rken.

      In addition to using the above-mentioned modules (pragmata), you will also need to either replace the  say() function with some variation of the print built-in, e.g.
          print $string, 'string', ..., "\n";
      or else enable the feature via the feature pragma:
          use feature 'say';
      in Perl versions 5.10+.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (16)
As of 2014-07-22 19:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (126 votes), past polls