Re: Perl on the Pocket PC - Easy!

From: Paul Lalli (mritty_at_gmail.com)
Date: 11/22/04


Date: Mon, 22 Nov 2004 21:41:13 GMT


<ioneabu@yahoo.com> wrote in message
news:1101103239.151520.159670@z14g2000cwz.googlegroups.com...

Just some very basic constructive criticism . . .
> #!/usr/bin/perl

would strict and warnings adversely affect your ability to get this
thing to a size proper for the Pocket PC? I know nothing about it, so
that's an honest question. If not, put them in.

> use File::Slurp;
> @a = read_dir('\\oldpts\\');
> foreach(@a)

No real reason for the intermediary variable there.
foreach (read_dir('\\oldpts\\')) {

> {
> @b = ();
> @b = read_file("\\oldpts\\$_");

Almost never any reason to initialize an array to (). Definately no
reason if you then immediately assign it to a different value.

(If this was meant to 'clear' @b before the next loop, simply properly
scope the variable:)

my @b = read_file("\\oldpts\\$_);

> if (not (grep /^total/, @b))
> {
> $c = 0;
> map
> {
> /^(\d+)\s/;
> $c += int $&;

1) $& is generally a Bad Thing. It slows down all regexps in the
program (though not as much as in previous versions)
2) You're using capturing parentheses without using the captured value.
3) You're using values determined from a regular expression without
determining whether that pattern match succeeded. Maybe you're really
really confident about the format of your files, but that's not a good
pattern to fall into:

$c += $1 if /^(\d+)\s/;

> } @b;

map() should almost never be used in a void context. Use map when you
want to obtain a list of modified values from an existing list. If
you're not using the modified values (or in this case, not even
modifying them), use a foreach loop instead:

for (@b) {
    $c += $1 if /^(\d+)\s/;
}

> push @b, "total: $c";
> write_file("\\oldpts\\$_",@b);
> }
> }
>
> I know it is not entirely efficient, but it worked. I couldn't
believe
> how fast it ran. One second to compile and no time to process dozens
> of files. Now I just need the portable keyboard :-)

> wana (now using map and grep a little :-)

Knowing how to use them is a good step in the right direction. Knowing
*when* to use them is a better step. :-)

Paul Lalli

>



Relevant Pages

  • Re: Meyerss preference for vectors over maps
    ... >contiguity of vector elements in memory ensure ... I will a container of objects that are much ... >Reason is what I'm trying to understand better. ... >of vector vs. map very unclear. ...
    (comp.lang.cpp)
  • Re: Good Dungeon Mapping e-Tool?
    ... Kyle Wilson wrote: ... elements to create a map is that they change sizes as you zoom, ... Lots of very cool open source projects have died because ... a reason to pick one particular interesting off-side ...
    (rec.games.frp.dnd)
  • It must be a shared world
    ... That is the reason these groups exist. ... no obligation to read my posts or any other ... Personal attacks with no legit ... reason are not proper.. ...
    (alt.support.diabetes)
  • Re: The Vinland Maps Ink
    ... > think that's one reason some folks, including Seaver, considered ... that the forger's (assuming for argument's sake that it is a forgery) ... OR he/she who was forced to make the map, ... The germans did not know writing or latin ...
    (sci.archaeology)
  • Re: Why reply at the bottom of posts?
    ... >>> documented methods for something that has history of being done a ... >> have to worry about the reason why some people aren't conformists. ... > No freedom is lost by posting properly. ... The freedom to choose what is proper for one's self. ...
    (microsoft.public.windowsxp.general)

Loading