Substract numeric from a string.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hon Seng Phuah

    Substract numeric from a string.

    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.
  • Joe Smith

    #2
    Re: Substract numeric from a string.

    Hon Seng Phuah wrote:
    [color=blue]
    > 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.[/color]

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

    -Joe

    Comment

    • Hon Seng Phuah

      #3
      Re: Substract numeric from a string.

      Joe Smith <Joe.Smith@inwa p.com> wrote in message news:<0p__b.119 117$jk2.516335@ attbi_s53>...[color=blue]
      > Hon Seng Phuah wrote:
      >[color=green]
      > > 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.[/color]
      >
      > $input = '$line = RVW-30 {';
      > ($search_result ) = $input =~ /-(\d+)/;
      > print $search_result, "\n";
      >
      > -Joe[/color]


      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

      Comment

      • Joe Smith

        #4
        Re: Substract numeric from a string.

        Hon Seng Phuah wrote:
        [color=blue]
        > Joe Smith <Joe.Smith@inwa p.com> wrote in message news:<0p__b.119 117$jk2.516335@ attbi_s53>...
        >[color=green]
        >>$input = '$line = RVW-30 {';
        >>($search_resu lt) = $input =~ /-(\d+)/;
        >>print $search_result, "\n";
        >>
        >> -Joe[/color]
        >
        > Thank Joe for your suggestion. Although it works for RVW-30, it does
        > not work for RVW-3 and RVW-4.[/color]

        The code I posted works perfectly find with "RVW-3" and "RVW-4".
        [color=blue]
        > It gives me this error message:
        > Argument "" isn't numeric in lt at test.pl[/color]

        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.

        Comment

        Working...