|No such thing as a small change|
Re: Processing words in a file.by kcott (Abbot)
|on Feb 12, 2013 at 07:24 UTC||Need Help??|
Welcome to the monastery.
Providing a little more context to your question would have been preferable. I'm assuming the first three fields are: month day hours:minutes:seconds. I'll leave you to extrapolate from there.
Perl has different operators for string and numerical comparisons. '==' is the numerical equality operator; 'eq' is for strings. See perlop for all the different operators; perlop - Equality Operators specifically discusses '==' and 'eq'.
How you go about breaking up your line for comparison will depend on how much detail you want (e.g. do you want to look at 'yy:yy:yy' as a whole or are you interested in the subfields). I see two main options you might pursue: using the split function or using a regular expression.
Using split can be as simple as:
The problem with this level of simplicity is when further down your code you hit $fields and have to backtrack to determine which field index 7 refers to. Ways around this include giving symbolic names to the indices or capturing each field into a meaningfully named variable:
If you want to get at the subfields, then a regular expression solution might be better:
All of those parts in parentheses are called Capture Groups. The link I've provided discusses these (as well as Named Capture Groups which I'll leave you to research if you're interested).