On Tuesday, September 24, 2002, at 08:18  AM, darren chamberlain wrote:

> I'd do it a little differently:
>
>   local $/;
>   my $mileage;
>   my @milage = split /    /, <DATA>; # <-- the string with your data
>
>   for (@milage) {
>       if (m/(\d+\.\d{1,2})$/) {
>           $mileage += $1;
>       }
>   }

Oho!  Good idea -- I had forgotten that <FH> can be used in split() (it 
evaluates to a list, after all, right?).  That's a great way to do it.

But I'm curious why you use "local $/" at the top -- it doesn't seem to 
be needed in this version.


Thanks,

Erik

PS: I'm trying to think of an elegant and simple way to read <STDIN> if 
there is any standard input and read <DATA> if not.  Yes, I could just 
test for <STDIN> != "" or something and use "if" statements, but that 
would basically mean repeating the same chunk of code with a different 
file handle inside the <>.  Any good ideas that let me just use the 
same block in either case?






--
Erik Price                                   (zombies roam)

email: [EMAIL PROTECTED]
jabber: [EMAIL PROTECTED]

_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to