Don't ask to ask, just ask | |
PerlMonks |
Re^4: Extracting full digits from a rangeby davido (Cardinal) |
on Aug 04, 2012 at 16:56 UTC ( [id://985444]=note: print w/replies, xml ) | Need Help?? |
Well here are the problems. First, you can't chomp a filehandle. When you try, you will get the following compile-time error:
Let's assume for a minute that you can chomp a filehandle. You're seeking to assign the return value of chomp, which will return the number of input record separators it chomped, not the target string. So if it could compile, it would return 1 (assuming there's a newline at the end of the target line). Let's assume that you fixed all that and managed to put 293F into $start, and 2945 into $end. You still have the problem that the .. range operator can only expand ranges composed of non-empty strings that match /^[a-zA-Z]*[0-9]*\z/. So you don't get any auto-incrementing behavior. Your code:
Attempts to use the range operator on a string that is incompatible with its wiring. According to perlop, if the string doesn't match /^[a-zA-Z]*[0-9]*\z/, then only the left operand will be returned. So after we fix the issues in line that chomps a filehandle and returns '1' to split, we're still left with the fact that the range operator won't even work here. The simplest solution is to convert those hex strings into numeric values, perform the range expansion, and then convert the expanded range back to a hex representation. Dave
In Section
Seekers of Perl Wisdom
|
|