in reply to regexp problem

You just have to make parts of the regex optional, and ensure you capture the right parts.To get the captured values as return values, you need to use the /g flag.

#!/usr/bin/perl while( <DATA> ) { chomp; my( $year, $julian, $hour, $minute, $second ) = m/ (\d{4}) # year (?: # group the day - time portions -? # optional hyphen (\d{1,3}) # julian day (?: # group the time portions \s+ # one or more whitespace (\d\d) # hour : (\d\d) # minute : (\d\d) # second )? # time is optional )? # day - time is optional /xg; print <<"HERE"; For input [$_] Year: $year Julian: $julian Hour: $hour Minute: $minute Second: $second HERE } __END__ 2005-100 10:12:01 2005100 10:12:01 2005-100 2005100 2005
--
brian d foy <brian@stonehenge.com>
Subscribe to The Perl Review