Substract numeric from a string.

H

Hon Seng Phuah

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.
 
J

Joe Smith

Hon said:
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
 
H

Hon Seng Phuah

Joe Smith said:
Hon said:
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
 
J

Joe Smith

Hon said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top