Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] Re: perl doubt

Expand Messages
  • Shlomi Fish
    Hi Ankit, On Tue, 28 May 2013 00:00:38 -0000 ... Do you want signed integers or unsigned integers? You can use something like (tested with is_32bit_signed):
    Message 1 of 8 , May 27, 2013
    • 0 Attachment
      Hi Ankit,

      On Tue, 28 May 2013 00:00:38 -0000
      "ankit d" <ankit_dhebarin@...> wrote:

      > Sure .. Thank you very much for your reply .
      >
      > For your distinctness question , hash is the datastructure as it has unique
      > keys but it can contain duplicate values.
      >
      > However for your first question, still I am not able to figure out how do we
      > check whether a column is 32 bit integers or not ? I did refer to your
      > reference link .

      Do you want signed integers or unsigned integers?

      You can use something like (tested with is_32bit_signed):

      < QUOTE >

      #!/usr/bin/perl

      use strict;
      use warnings;

      use Math::BigInt ":constant", lib => 'GMP';


      sub is_32bit_signed
      {
      my $i = shift;

      return (($i <= ((1 << 31) - 1)) and (-(1 << 31) <= $i));
      }

      sub is_32bit_unsigned
      {
      my $i = shift;

      return (($i <= ((1 << 32) - 1)) and (0 <= $i));
      }

      my $i = shift(@ARGV);

      print is_32bit_signed($i) ? "Signed 32-bit\n" : "Not 32-bit.\n";

      </QUOTE>

      Regards,

      Shlomi Fish

      >
      > Waiting for your reponse..
      >
      > Thanks again
      >
      >
      > --- In perl-beginner@yahoogroups.com, Joe Pepersack <joe@...> wrote:
      > >
      > > Split creates an array of values. Good first step.
      > >
      > > The next step is to loop through that array and determine if each value
      > > it contains is a valid 32-bit integer. You'll want to do a series of
      > > tests for possible error conditions (not a number, not an int, too big,
      > > too small, etc). This could be if/elsif/else or given/when (if using
      > > Perl 5.10 or newer). You can do these tests using regular expressions
      > > or mathematically. This is covered in the FAQ:
      > > http://perldoc.perl.org/perlfaq4.html#How-do-I-determine-whether-a-scalar-is-a-number%2fwhole%2finteger%2ffloat%3f
      > >
      > > For distinctness, think about what Perl variable type keeps a list of
      > > unique keys.
      > >
      > > Don't worry about pack/unpack, that's going to take you in the wrong
      > > direction.
      > >
      > >
      > >
      > > On 5/23/2013 8:18 PM, ankit d wrote:
      > > >
      > > > Well ,thanks for your quick reply ..
      > > > I followed the below steps to do it,
      > > >
      > > > 1) using split , I could assign each tab delimited value and store it
      > > > into a variable.
      > > > But I am not actually able to understand what exactly do I have to do .
      > > >
      > > > Hence I need your help.
      > > >
      > > > Thanks again
      > > >
      > > > --- In perl-beginner@yahoogroups.com
      > > > <mailto:perl-beginner%40yahoogroups.com>, "interrobang"
      > > > <CedricCicada@> wrote:
      > > > >
      > > > > This is obviously a homework assignment. You won't learn very much
      > > > if we do your work for you. Please show us what you have tried so far
      > > > and tell us what happens when you try to run your program. We'll try
      > > > to help you over any rough spots you may be finding.
      > > > >
      > > > > RobR
      > > > >
      > > > > --- In perl-beginner@yahoogroups.com
      > > > <mailto:perl-beginner%40yahoogroups.com>, "ankit d" <ankit_dhebarin@>
      > > > wrote:
      > > > > >
      > > > > > I have a file which has 7 columns and is seperated by tabs. I have
      > > > to perform the following but not sure how to do it;
      > > > > > Need perl experts help on this ;
      > > > > >
      > > > > >
      > > > > > All of the columns should be 32 bit integers and Nulls are not
      > > > allowed.
      > > > > >
      > > > > > Perform the following on this file.
      > > > > >
      > > > > > 1) The file contains errors. Remove the bad lines. The description
      > > > of the file
      > > > > > above should tell you which lines are valid. The program should
      > > > remove the
      > > > > > lines and output them to the screen.
      > > > > >
      > > > > > 2) Find the number of distinct rows for column 2 in the corrected
      > > > file. Output
      > > > > > this number to the screen.
      > > > > >
      > > > >
      > > >
      > > >
      > >
      > >
      > >
      > > [Non-text portions of this message have been removed]
      > >
      >
      >



      --
      -----------------------------------------------------------------
      Shlomi Fish http://www.shlomifish.org/
      Apple Inc. is Evil - http://www.shlomifish.org/open-source/anti/apple/

      One thing I could never understand is why in Microsoft Word, it often happens
      that I press enter… and the font changes.

      Please reply to list if it's a mailing list post - http://shlom.in/reply .
    Your message has been successfully submitted and would be delivered to recipients shortly.