So I have an ID range for pages in a document that I need to loop to compare values. My problem is the ID’s are strings and not number so when I try and loop the range with Perl it doesn’t work. Here is an example of my range loop, and an example of my data.
foreach($begID..$endID){
print $_;
}
A data example would be
$begID = ABC-ABC-00001;
$endID = ABC-ABC-00100;
My problem is I cannot loop these values. I know I could split the data based on the “-” and get the 00001 and 00100 values, but the problem with that is the data can vary on different files I am working with.
Is there any other way that someone could suggest to go about this?
UPDATE
Until I can post my own answer (in another 7 hours due to being under 100 rep) here is what I came up with:
Okay here is what I did as a solution. I can regex out the numbers starting from the end until it hits an alpha character.
($start) = $begID =~ m/(\d+)$/;
($end) = $endID =~ m/(\d+)$/;
Then create the loop from there.
“data can vary” how?
If by having a fixed string prefix + the number, you can split off the prefix: