Link to home
Start Free TrialLog in
Avatar of Tolgar
Tolgar

asked on

How to catch the number in a line in Perl?

Hi,
How can I catch the number in a line which look like the following:

The example input is:

33c33

Open in new window


The expected output for this example is:

33

Open in new window


Thanks
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tolgar
Tolgar

ASKER

Can you also tell me how I can tell if the line has this format:

33c33 

Open in new window


which is:

$numberc$number

Open in new window


I try to catch this line and then capture the number in it as you told me in the previous post.

So it will be something like this:

my $catch = 0
foreach my $line (@fileContent){

if($line STARTS WITH diff){
   $catch = 1;
}

if ($catch =1 AND $line =~ SOME REGULAR EXP TO CATCH IF LINE HAS THE EXPECTED FORMAT){
    ($number) = ($LINE =~ /(\d+)/);
}

}

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial