Thanks for the reply Chris.
I didn't manage to get it to work. It throws the error "Wrong format",
probably got something to do with the checking of white space?
Yanto
On Fri, Jun 20, 2008 at 4:50 PM, Chris Henry <[EMAIL PROTECTED]> wrote:
> On Fri, Jun 20, 2008 at 7:45 AM, Chris Henry <[EMAIL PROTECTED]> wrote:
>> On Fri, Jun 20, 2008 at 7:43 AM, Chris Henry <[EMAIL PROTECTED]> wrote:
>>> #/usr/bin/perl
>>>
>>> var result = 0;
>>> open(FILE, '...') || die 'Can't open file';
>>>
>>> while ( <FILE> ) {
>>> chomp;
>>> if ($_ =~ /(t=\d+\s)(\d+)/) {
>>> $result += $2;
>>> print $1, $result;
>>
>> Sorry, this line should be print $1, $result, "\n";
>>
>>> } else {
>>> die 'File format is wrong.';
>>> }
>>> }
>>>
>
> Ignore, too many syntax error, haven't used Perl for too long, here is
> a tested and working version:
>
> #!/usr/bin/perl
>
> $result = 0;
> $filename = shift || die 'No file is specified.';
> open(FILE, $filename) || die 'Could not open file.';
>
> while ( <FILE> ) {
> chomp;
> if ($_ =~ /(t=\d+\s+)(-?\d+)/) {
> $result += $2;
> print $1, $result, "\n";
> } else {
> die 'Wrong format.';
> }
> }
>
>
>>
>>
>> --
>> Chris
>> [EMAIL PROTECTED]
>> [EMAIL PROTECTED]
>>
>
>
>
> --
> Chris
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]
>
_______________________________________________
Slugnet mailing list
[email protected]
http://wiki.lugs.org.sg/LugsMailingListFaq
http://www.lugs.org.sg/mailman/listinfo/slugnet