我应该如何组织许多Perl模块?

编程入门 行业动态 更新时间:2024-10-28 18:33:16
本文介绍了我应该如何组织许多Perl模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

考虑一下,我在12个目录中有100个Perl模块.但是,查看主要的Perl脚本,它看起来像100 use p1 ; use p2 ;等.解决此问题的最佳方法是什么?

Consider that I have 100 Perl modules in 12 directories. But, looking into the main Perl script, it looks like 100 use p1 ; use p2 ; etc. What is the to best way to solve this issue?

推荐答案

在我看来,您不太可能直接在主程序中直接use全部100个模块.如果您的程序使用模块A中的一个函数,然后从模块B中调用一个函数,但是主程序本身未引用模块B中的任何内容,则该程序应仅use A.除非它直接从模块B调用任何内容,否则不应该use B.

It seems unlikely to me that you're useing all 100 modules directly in your main program. If your program uses a function in module A which then calls a function from module B, but the main program itself doesn't reference anything in module B, then the program should only use A. It should not use B unless it directly calls anything from module B.

另一方面,如果您的主程序确实确实直接与所有100个模块进行通讯,那么它可能实在太大了.在程序中标识不同的功能分组,并将每个分组分为各自的模块.这样做的主要原因是,它可以使代码更易于维护,灵活和可重用,但同时也具有减少主程序直接与之通信的模块数量,从而减少代码数量的令人欣慰的副作用.减少了任意一个地方所需的use语句的数量.

If, on the other hand, your main program really does talk directly to all 100 modules, then it's probably just plain too big. Identify different functional groupings within the program and break each of those groups out into its own module. The main reason for doing this is so that it will result in code that is more maintainable, flexible, and reusable, but it will also have the happy side-effect of reducing the number of modules that the main program talks to directly, thus cutting down on the number of use statements required in any one place.

(而且,是的,我的确意识到100可能是一个夸张,但是,如果您对代码正在被use d的模块数量感到不满意,则通常可以很容易地看出其中的代码问题是试图在一个地方做太多事情,应该分解为一组模块.)

(And, yes, I do realize that 100 was probably an exaggeration, but, if you're getting uncomfortable about the number of modules being used by your code, then that's usually a strong indication that the code in question is trying to do too much in one place and should be broken down into a collection of modules.)

更多推荐

我应该如何组织许多Perl模块?

本文发布于:2023-07-12 07:29:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1096865.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模块   组织   Perl

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!