Thread: Bonny1989

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    31
    Rep Power
    2

    Bonny1989


    Hi All,
    I have one more question,
    suppose a variable is
    $array[0]=[31:15];
    Now I want to find the difference between two numbers...
    here, (31-15)
    please guide me.

    PS: this variable will be assigned different values at different time, i.e [15:0], [7:0], [127:0], [127:15] etc...
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    832
    Rep Power
    496
    You can try something like this:

    Code:
    my ($num1, $num2) = $array[0] =~ /(\d+):(\d+)/;
    my $diff = $num1 - $num2;
    print $diff, "\n";

    Comments on this post

    • bonny1989 agrees : Great!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,940
    Rep Power
    1225
    $array[0]=[31:15];
    That will generate a syntax error and compilation error preventing your script to run.

    Please post your real code.

    Comments on this post

    • bonny1989 agrees : Thanks. :)
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    832
    Rep Power
    496
    Originally Posted by FishMonger
    That will generate a syntax error and compilation error preventing your script to run.
    Yes, this is certainly not going to compile, but from the context (the sentence immediately before), it would seem that Bonny really wants to say that the content of $array[0] is "[31:15]".
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    31
    Rep Power
    2
    @Laurent_R, @FishMonger Sorry I meant, $array[0] = "[31:15]".

    But still Laurent_R.... it was a great help.
    Really I am very very thankful to you.
    Thank you so much!
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    31
    Rep Power
    2
    Also thanks to FishMonger as well...for making me aware of that error!

IMN logo majestic logo threadwatch logo seochat tools logo