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

Re: [PBML] Newbie Help

Expand Messages
  • Raghu Ram Murthy
    Mmmmmmmm, big code. I didn t read at all. But you can try following regular expression match to find whether a string is numeric my $num = ; die Not a
    Message 1 of 2 , Dec 29, 2004
    • 0 Attachment
      Mmmmmmmm, big code. I didn't read at all.

      But you can try following regular expression match to
      find whether a string is numeric

      my $num = <STDIN>;
      die "Not a number\n" if $num !~ /\d+/;

      This doesn't take care of float and exponential
      values, but you can write corresponding regular
      expression to check those.

      Thanks
      -Raghuram

      --- Erich Ho <erichho91@...> wrote:

      >
      > The following is my code:
      >
      > #####Account Object Listing####
      >
      > package account;
      >
      > ##### audit method
      > sub audit{
      > #Purpose: To write all banking transactions to an
      > audit file
      > #
      > # Input: Account object, audit message
      > # Output: Account object
      >
      > my($self) = $_[0]; #shift returns $_[0] in its
      > first
      > call
      >
      > $activity = $_[1]; #get audit message
      > and stores in a
      > $activity variable
      >
      > open LOG, ">>audit" #Open audit file or error out
      > or die "Can't open: $!";
      >
      > print LOG $activity; #print the message
      > close LOG; #close the file
      > return ($self); #return the object
      > }
      >
      > #####Constructor Method
      > sub new
      > {
      > #Purpose: To create an object with the name of the
      >
      > account
      > # and establish the opening balance
      > # this object will store name and the ending
      > balance
      > #
      > # Input: Name, opening amount
      > # Output: Account object
      >
      > my($type) = $_[0] ; #shift returns $_[0] in its
      > first call
      > my $self= {}; #reference to anonymous hash
      >
      > $self->{'name'} = $_[1] ; #get name and store in
      > the
      > name variable in account object
      > $self->{'oriamt'} = $_[2] ; #get opening and
      > store in
      > the opening amount variable in account object
      > $self->{'amt'} = $_[2] ; #copy the opening balance
      > and store in the amt variable in account object
      >
      > $name=$self ->{'name'}; #get the name of the
      > person
      > from object
      > $balance=$self ->{'amt'}; #get the amount from
      > object
      >
      > print "Hello, ".$name.", your bank account with us
      > is opened
      > with an opening balance of ".$balance.". \n\n";
      > #Acknowlegde to the user that the account has been
      > opened
      > and report opening balance
      >
      > $aud= $name." opened a checking account with a
      > opening
      > balance of ".$balance.". \n";
      > # compose a message for audit file
      > &audit($ne, $aud); # write message to audit file
      >
      > bless($self, $type); #make refernce into
      > class 'account'
      > return $self; #return the object
      >
      > }
      >
      > #####View Balance Method
      > sub viewbal{
      > #Purpose: Serve as a quick function to report the
      > current balance
      > #
      >
      >
      > #Input: Name of object
      > #Output: Return current balance
      > #
      >
      > my($self) = $_[0]; #shift returns $_[0] in its
      > first call
      > return $self ->{'amt'}; #Return the current
      > balance
      >
      > }
      >
      > #####View Name Method
      > sub viewnm{
      > #Purpose: Serve as a quick function to report the
      > name
      > # (As per bank's policy, you need to address
      > the customer by name)
      > #Input: Name of object
      > #Output: Return current balance
      > #
      >
      >
      > my($self) = $_[0] ; #shift returns $_[0] in its
      > first call
      > return $self ->{'name'}; #return the vaule lof
      > pname
      > }
      >
      > #####Adjust amount Method
      > sub adjustamt{
      > #Purpose: To add or deduct the current balance by
      > a
      > specified Amount
      > #
      > #Input: Name of object
      > # Amount -> Amount of $ to be added or deducted
      > # Sign -> Determine where its a deposit
      > (denoted as a 1)
      > # or withdrawl( denoted as a 2)
      > #
      > #Output: Return current balance
      >
      >
      >
      > my($self) = $_[0] ; #shift returns $_[0] in its
      > first call
      > $amt = $_[1] ; #get the amount to be added
      > or deducted from the calling funtion
      > $sign = $_[2] ; #Get 1 or 2 from the
      > program ;determine whether it's a deposit(1) or
      > withdrawl (2)
      >
      > $nm=&viewnm($ne); #Get the name of the account
      > using the viewne function
      > $msg=""; #reset the user's
      > acknowledgment
      > $aud=""; #reset audit message
      >
      > if ($sign==2) #If a withdrawl action is
      > taken, execute this block of code
      > {if ($amt > &viewbal($ne)) # Check whether the the
      >
      > withdrawl amount is less
      > # the balance
      >
      > {
      > print "Sorry, but you don't have the
      > necessary fund to make that kind of withdrawl.\n"
      > } # Tells the user that they don't
      > have funds to make this withdrawl
      > #Bows out to main program
      >
      >
      >
      > else #So they have enough money to
      > withdraw
      > {
      > $auth= 0 -$amt; # Makes the authorized withdrawl
      >
      > amount a negative number
      > # suppose $amt is 25, $auth will
      > be -25
      > $aud= $name." has withdraw the amount
      > of ".$balance.". \n";
      > # write an audit message
      > $msg = "Hello, ".$nm.", the withdraw of ".$amt."
      > has
      > been deducted to your account. \n";
      > # stores the appropriate message in $msg
      >
      >
      > }}
      > else #assume it a deposit
      > {
      >
      >
      > $auth = $amt; # Authorized the deposit, since
      > this
      > is an add, do not change the sign
      > $aud= $name." has made a deposit of ".$balance.".
      > \n";
      > #write an audit msg
      > $msg= "Hello, ".$nm.", the deposit of ".$amt." has
      >
      > been debited to your account. \n";
      > # stores the appropriate message in $msg
      > }
      >
      >
      > if ($msg ne ""){ # check if there is a user's
      > message. if $msg is "", bow out
      >
      >
      === message truncated ===


      =====
      ----------------------------------------------
      P.Raghu Ram Murthy, M-tech (Computer Science),
      Member, Information Technology,
      D E Shaw India Software Private Limited,
      6-3-879 & 879/B
      Begumpet, Hyderabad 500 016
      Andhra Pradesh
      India

      Mobile: (+91) 98852 17928
      ----------------------------------------------

      If it doesn't work, you're not hitting it with a big enough hammer



      __________________________________
      Do you Yahoo!?
      The all-new My Yahoo! - What will yours do?
      http://my.yahoo.com
    Your message has been successfully submitted and would be delivered to recipients shortly.