Re: Perl on the Pocket PC - Easy!
From: Paul Lalli (mritty_at_gmail.com)
Date: 11/22/04
- Next message: Leon: "Re: Can I run Perl on Palm Pilot?"
- Previous message: Paul Lalli: "Re: Get list of files."
- In reply to: ioneabu_at_yahoo.com: "Perl on the Pocket PC - Easy!"
- Next in thread: ioneabu_at_yahoo.com: "Re: Perl on the Pocket PC - Easy!"
- Reply: ioneabu_at_yahoo.com: "Re: Perl on the Pocket PC - Easy!"
- Reply: wana: "Re: Perl on the Pocket PC - Easy!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
>
- Next message: Leon: "Re: Can I run Perl on Palm Pilot?"
- Previous message: Paul Lalli: "Re: Get list of files."
- In reply to: ioneabu_at_yahoo.com: "Perl on the Pocket PC - Easy!"
- Next in thread: ioneabu_at_yahoo.com: "Re: Perl on the Pocket PC - Easy!"
- Reply: ioneabu_at_yahoo.com: "Re: Perl on the Pocket PC - Easy!"
- Reply: wana: "Re: Perl on the Pocket PC - Easy!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|