Hi Rob,

Just'd like to add my $0.02 to the brilliant solutions you offered. )

You can access the anonymous arrays from @desc using
>
>  foreach my $rest (@desc) {
>    print "@$rest\n";
>  }
>
> Or just...
  say "@$_" for @desc;
... if one prefers conciseness - and is able to use 5.010, of course. )

But there is no need to split the thrid field in the first place.

Even more, it may produce slightly incorrect results: blocks of whitespace
in @rest will collapse into single space when quote-printed (print
"@rest"). Tabulations will be reduced to a simple space symbol as well.


> You have two options: first to split on more than a single space with
> my ( $lat, $lon, $rest ) = split /\s{2,}/;
>
This solution will work correctly only if 'remainder' part of phrase won't
have spacings longer than 1 symbol. Otherwise the rest of phrase will be
omitted - without any warnings whatsoever.

and secondly to limit the number of fields that split() divides the record
> into
>  my ( $lat, $lon, $rest ) = split ' ', $_, 3;
>
And this solution will work correctly all the time, which (in my opinion)
makes it preferable. ) Besides, it should work a bit faster.

Be aware that both of these techniques will leave the newline on the end
> of the last field, so a call to chomp() will be necessary as the first
> line of the while loop.
>
Or then again, we may just chomp the $rest if necessary.

-- iD

Reply via email to