On Tue, May 31, 2011 at 4:23 PM, John W. Krahn <jwkr...@shaw.ca> wrote:
> Just a couple of comments on some of your code.  :)
>
*snip*
>>     @lines = @lines[$start_line..$#lines];
>
> You are copying almost all of @lines to @lines when you should be using
> perl's built-in functions to just remove elements from @lines without the
> copying:
>
>       splice @lines, 0, $start_line;

I simply didn't know about splice and knew I could use a slice. :) I
certainly prefer the splice option though. Thank you for pointing it
out.

>>
>>             map { s{(.*)}{$directory/$1}; $_; }
>>                     @dirfiles[1..$#dirfiles];
>
> What is $_; returning a value to?  You are using map in a void context.

Good catch. I'm still pretty green with the use of map or grep, etc.
(basically anything that accepts a BLOCK like that) so as you can see
I'm rather clumsy when I use them. :) Thanks for pointing this out
too. :)

> That is better written as:
>
>               s{(.*)}{$directory/$1} for @dirfiles[ 1 .. $#dirfiles ];
>
> Or as:
>
>               $_ = "$directory/$_" for @dirfiles[ 1 .. $#dirfiles ];

I can't believe I opted for a substitution instead of simply
"interpolating" the string... :-X I'll have to blame sed/vim for that
instinctual reaction. :P I guess the way that Perl aliases things
still confuses me a little bit. :)

Thanks again.


-- 
Brandon McCaig <http://www.bamccaig.com/> <bamcc...@gmail.com>
V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl.
Castopulence Software <http://www.castopulence.org/> <bamcc...@castopulence.org>

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to