in reply to handling erronous input
What i need is for my code to only accept input of 1 digit before the decimal place and 5 after , a space, a comma.. then an 8 character time using : as a seperator that will ignore any data on the same line after the seconds.You seem to know what you want, so it's just a case of following your spec...
my @data = split /\n/, <<EOS; 1.57163 ,17:29:57 Simple Dealin 1.57163 ,17:29:57 1.57163 ,17:29:57 1.57163 ,17:29:57 1.57163 ,17:29:57 1.57163 ,17:29:57 1.57163 ,17:29:57 1.571 ,17: 1.57172 ,17:30:08 1.57176 ,17:30:10 EOS for ( @data ) { if ( my ( $quote, $time, $comment ) = m{ ^ # start of string (\d\.\d{5}) # a digit, dot and 5 more digits \s, # a space and a comma (\d\d:\d\d:\d\d) # an 8 character time \s* # some spaces (.*) # everything else's a commment $ # end of string }x ) { print "$quote / $time", $comment ne '' ? " / $comment" : '', "\n"; } }
Output:
1.57163 / 17:29:57 / Simple Dealin 1.57163 / 17:29:57 1.57163 / 17:29:57 1.57163 / 17:29:57 1.57163 / 17:29:57 1.57163 / 17:29:57 1.57163 / 17:29:57 1.57172 / 17:30:08 1.57176 / 17:30:10
Update:
See perlre and perlretut for the details
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: handling erronous input
by Conal (Beadle) on Apr 06, 2008 at 22:23 UTC | |
by FunkyMonk (Bishop) on Apr 06, 2008 at 22:57 UTC | |
by GrandFather (Saint) on Apr 06, 2008 at 23:35 UTC | |
by Conal (Beadle) on Apr 06, 2008 at 23:50 UTC | |
by ww (Archbishop) on Apr 07, 2008 at 02:55 UTC | |
by apl (Monsignor) on Apr 07, 2008 at 12:06 UTC |