Substract numeric from a string.

Discussion in 'Perl' started by Hon Seng Phuah, Feb 25, 2004.

  1. Hi all,

    I have a problem and have someone can help me.

    I want to substract a numerica from a string.

    For example:

    A string is:
    $line = RVW-30 {

    I want to get 30 and store it into the $search_result.

    I have code written as:

    $search_result = ($line =~ /[-]([\d]+)/

    I get this error message:

    Use of uninitialized value at test.pl.

    Any idea how to solve my problem. Thanks.
    Hon Seng Phuah, Feb 25, 2004
    #1
    1. Advertising

  2. Hon Seng Phuah

    Joe Smith Guest

    Hon Seng Phuah wrote:

    > A string is:
    > $line = RVW-30 {
    >
    > I want to get 30 and store it into the $search_result.
    >
    > I have code written as:
    >
    > $search_result = ($line =~ /[-]([\d]+)/
    >
    > I get this error message:
    >
    > Use of uninitialized value at test.pl.


    $input = '$line = RVW-30 {';
    ($search_result) = $input =~ /-(\d+)/;
    print $search_result,"\n";

    -Joe
    Joe Smith, Feb 25, 2004
    #2
    1. Advertising

  3. Joe Smith <> wrote in message news:<0p__b.119117$jk2.516335@attbi_s53>...
    > Hon Seng Phuah wrote:
    >
    > > A string is:
    > > $line = RVW-30 {
    > >
    > > I want to get 30 and store it into the $search_result.
    > >
    > > I have code written as:
    > >
    > > $search_result = ($line =~ /[-]([\d]+)/
    > >
    > > I get this error message:
    > >
    > > Use of uninitialized value at test.pl.

    >
    > $input = '$line = RVW-30 {';
    > ($search_result) = $input =~ /-(\d+)/;
    > print $search_result,"\n";
    >
    > -Joe



    Thank Joe for your suggestion. Although it works for RVW-30, it does
    not work for RVW-3 and RVW-4. It gives me this error message:

    Argument "" isn't numeric in lt at test.pl

    Any idea how to solve it? Thanks.
    -HS Phuah
    Hon Seng Phuah, Feb 25, 2004
    #3
  4. Hon Seng Phuah

    Joe Smith Guest

    Hon Seng Phuah wrote:

    > Joe Smith <> wrote in message news:<0p__b.119117$jk2.516335@attbi_s53>...
    >
    >>$input = '$line = RVW-30 {';
    >>($search_result) = $input =~ /-(\d+)/;
    >>print $search_result,"\n";
    >>
    >> -Joe

    >
    > Thank Joe for your suggestion. Although it works for RVW-30, it does
    > not work for RVW-3 and RVW-4.


    The code I posted works perfectly find with "RVW-3" and "RVW-4".

    > It gives me this error message:
    > Argument "" isn't numeric in lt at test.pl


    The code I posted does not have any "<" or "lt" operators.
    You've obviously changed something.
    We cannot debug your code without seeing it.
    Make sure you copy-and-paste your code; do not retype by hand.
    -Joe

    Please note: Followups have been redirected to comp.lang.perl.misc where
    this discussion belongs.
    Joe Smith, Feb 26, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. CBN Media

    DateTime Substract

    CBN Media, Mar 2, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    13,257
    CBN Media
    Mar 2, 2004
  2. Damien
    Replies:
    5
    Views:
    1,082
    Larry Coon
    Dec 10, 2003
  3. Jean-Christophe Michel

    stack values in xsl or substract element from tree

    Jean-Christophe Michel, Dec 24, 2003, in forum: XML
    Replies:
    4
    Views:
    428
    Dimitre Novatchev
    Jan 5, 2004
  4. Replies:
    5
    Views:
    911
    X-Centric
    Jun 30, 2005
  5. Francois Grieu

    Is it conformant to substract two pointer-to-void ?

    Francois Grieu, Mar 12, 2008, in forum: C Programming
    Replies:
    10
    Views:
    587
    Gordon Burditt
    Mar 14, 2008
Loading...

Share This Page