I have a string like
$number="1234567";
and i want to extract substring out of it , but i am not getting proper results with substr function.
If i execute
substr $number ,0,1 ;
i get 1 as output but it should be 12.
To get 12, you need:
substr $number, 0, 2
The syntax for substr is:
substr $var, OFFSET, LENGTH
So when you do:
substr $number ,0,1
the OFFSET will be 0 and LENGTH will be 1.
perl is zero-indexed i.e. the indexing starts at 0, and the length of the substring you have picked is 1, so you would only get 1 in the output expectedly.