On Saturday 05 Feb 2011 00:23:50 Conor Walsh wrote:
> On 2/4/2011 2:04 PM, Asa Martin wrote:
> > I was told that "predeclaring" the variables outside the loop saved on
> > memory allocation, and that using @rules instead of four named variables
> > was also more efficient. I had never considered that this could be the
> > case, and said I didn't think this was true, but didn't really know.
> >
> > Any thoughts on this? We're using perl 5.10.0
>
> Hi Asa,
>
> If that has a performance impact at all, it's extremely minor. This is
> more a code clarity/consistency issue than it is a performance issue.
>
> If performance is an issue to that degree, you should be using C and
> strtok(), not Perl and split().
>
While C may be a good recommendation for such cases, I would strongly
recommend against using strtok. Its Linux man page used to read "Never use
this function" and now there is this bugs section:
[quote]
BUGS
Be cautious when using these functions. If you do use them, note that:
* These functions modify their first argument.
* These functions cannot be used on constant strings.
* The identity of the delimiting character is lost.
* The strtok() function uses a static buffer while parsing, so it's not
thread safe. Use strtok_r() if this matters to you.
[/qoute]
What I normally do is use strchr and strstr and copy strings incrementally (or
set the characters to '\0' if I am allowed to write to it.).
Regards,
Shlomi Fish
> Thanks,
> Conor
>
> _______________________________________________
> Boston-pm mailing list
> [email protected]
> http://mail.pm.org/mailman/listinfo/boston-pm
--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
Optimising Code for Speed - http://shlom.in/optimise
Chuck Norris can make the statement "This statement is false" a true one.
Please reply to list if it's a mailing list post - http://shlom.in/reply .
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm