473,383 Members | 1,789 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Smaller code

Trying to reduce alot of my codes size and am having no joy with this
code. How can I get this smaller?

// Block
$prefix_length = strlen( PREFIX_BLOCKS );

$block_dir = @opendir($root_path . 'modules/modules_blocks');
while( false !== ($dir_name = readdir($block_dir)) )
{
if( $dir_name != "." && $dir_name != ".." )
{
if ( substr( $dir_name, 0, $prefix_length ) == PREFIX_BLOCKS
)
{
if( is_dir( $root_path . 'modules/modules_blocks/' .
$dir_name))
{
$mod_list_blocks[] = $dir_name;
}
}
}
}
@closedir( $block_dir );

// Page
$prefix_length = strlen( PREFIX_PAGES );

$page_dir = @opendir($root_path . 'modules/modules_page');
while( false !== ($dir_name = readdir($page_dir)) )
{
if( $dir_name != "." && $dir_name != ".." )
{
if ( substr( $dir_name, 0, $prefix_length ) == PREFIX_PAGES
)
{
if( is_dir( $root_path . 'modules/modules_page/' .
$dir_name))
{
$mod_list_page[] = $dir_name;
}
}
}
}
@closedir( $page_dir );

// Admin
$prefix_length = strlen( PREFIX_ADMIN );

$admin_dir = @opendir($root_path . 'modules/modules_admin');
while( false !== ($dir_name = readdir($page_dir)) )
{
if( $dir_name != "." && $dir_name != ".." )
{
if ( substr( $dir_name, 0, $prefix_length ) == PREFIX_ADMIN
)
{
if( is_dir( $root_path . 'modules/modules_admin/' .
$dir_name))
{
$mod_list_admin[] = $dir_name;
}
}
}
}
@closedir( $admin_dir );
big thanks
Nov 11 '08 #1
2 1348
Tree*Rat wrote:
Trying to reduce alot of my codes size and am having no joy with this
code. How can I get this smaller?

// Block
$prefix_length = strlen( PREFIX_BLOCKS );

$block_dir = @opendir($root_path . 'modules/modules_blocks');
while( false !== ($dir_name = readdir($block_dir)) )
{
if( $dir_name != "." && $dir_name != ".." )
{
if ( substr( $dir_name, 0, $prefix_length ) == PREFIX_BLOCKS
)
{
if( is_dir( $root_path . 'modules/modules_blocks/' .
$dir_name))
{
$mod_list_blocks[] = $dir_name;
}
}
}
}
@closedir( $block_dir );

// Page
$prefix_length = strlen( PREFIX_PAGES );

$page_dir = @opendir($root_path . 'modules/modules_page');
while( false !== ($dir_name = readdir($page_dir)) )
{
if( $dir_name != "." && $dir_name != ".." )
{
if ( substr( $dir_name, 0, $prefix_length ) == PREFIX_PAGES
)
{
if( is_dir( $root_path . 'modules/modules_page/' .
$dir_name))
{
$mod_list_page[] = $dir_name;
}
}
}
}
@closedir( $page_dir );

// Admin
$prefix_length = strlen( PREFIX_ADMIN );

$admin_dir = @opendir($root_path . 'modules/modules_admin');
while( false !== ($dir_name = readdir($page_dir)) )
{
if( $dir_name != "." && $dir_name != ".." )
{
if ( substr( $dir_name, 0, $prefix_length ) == PREFIX_ADMIN
)
{
if( is_dir( $root_path . 'modules/modules_admin/' .
$dir_name))
{
$mod_list_admin[] = $dir_name;
}
}
}
}
@closedir( $admin_dir );
big thanks
What's wrong with the code (other than using '@'? Clarity is MUCH more
important than size.

The only change I would make is to put the left braces on the same like
as the if or while statement, i.e.

if( $dir_name != "." && $dir_name != ".." ) {

but that's only a matter of style.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 11 '08 #2
On Nov 11, 9:22*am, "Tree*Rat" <tree....@googlemail.comwrote:
Trying to reduce alot of my codes size and am having no joy with this
code. How can I get this smaller?

// Block
$prefix_length = strlen( PREFIX_BLOCKS );

$block_dir = @opendir($root_path . 'modules/modules_blocks');
while( false !== ($dir_name = readdir($block_dir)) )
{
* * * * if( $dir_name != "." && $dir_name != ".." )
* * * * {
* * * * * * * * if ( substr( $dir_name, 0, $prefix_length) == PREFIX_BLOCKS
)
* * * * * * * * {
* * * * * * * * * * * * if( is_dir( $root_path . 'modules/modules_blocks/' .
$dir_name))
* * * * * * * * * * * * {
* * * * * * * * * * * * * * * * $mod_list_blocks[] = $dir_name;
* * * * * * * * * * * * }
* * * * * * * * }
* * * * }}

@closedir( $block_dir );

// Page
$prefix_length = strlen( PREFIX_PAGES );

$page_dir = @opendir($root_path . 'modules/modules_page');
while( false !== ($dir_name = readdir($page_dir)) )
{
* * * * if( $dir_name != "." && $dir_name != ".." )
* * * * {
* * * * * * * * if ( substr( $dir_name, 0, $prefix_length) == PREFIX_PAGES
)
* * * * * * * * {
* * * * * * * * * * * * if( is_dir( $root_path . 'modules/modules_page/' .
$dir_name))
* * * * * * * * * * * * {
* * * * * * * * * * * * * * * * $mod_list_page[] = $dir_name;
* * * * * * * * * * * * }
* * * * * * * * }
* * * * }}

@closedir( $page_dir );

// Admin
$prefix_length = strlen( PREFIX_ADMIN );

$admin_dir = @opendir($root_path . 'modules/modules_admin');
while( false !== ($dir_name = readdir($page_dir)) )
{
* * * * if( $dir_name != "." && $dir_name != ".." )
* * * * {
* * * * * * * * if ( substr( $dir_name, 0, $prefix_length) == PREFIX_ADMIN
)
* * * * * * * * {
* * * * * * * * * * * * if( is_dir( $root_path . 'modules/modules_admin/' .
$dir_name))
* * * * * * * * * * * * {
* * * * * * * * * * * * * * * * $mod_list_admin[] = $dir_name;
* * * * * * * * * * * * }
* * * * * * * * }
* * * * }}

@closedir( $admin_dir );

big thanks
The size of a piece of PHP code has no bearing on its performance.
Keeping code readable is far more important. If you hare having
performance issues that would suggest you have picked an incorrect
algorithm or have implemented it in a suboptimal way. If this is the
case then there is far more to be gained by looking into what your
code is doing and how it works rather than how it is written.
Nov 15 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Gregory | last post by:
Hello, I've managed to build two web pages, one that can display images with associated text data in a table, and one that can resize and display images without the text. I'd like to resize the...
1
by: Andreas | last post by:
Hi: I am writing an ASP webpage that is supposed to export data from a DataGrid to Excel. I have a link Button on the page that is supposed to Redirect to the page that load the data. Now on...
5
by: serge | last post by:
Is it generally or almost always better to have multiple small SPs and functions to return a result set instead of using a single big 1000+ lines SP? I have one SP for example that is 1000+...
22
by: petermichaux | last post by:
Hi, I'm curious about server load and download time if I use one big javascript file or break it into several smaller ones. Which is better? (Please think of this as the first time the scripts...
8
by: Janelle.Dunlap | last post by:
My database is linked to external data from a single Excel spreadsheet. I currently have it so that the entire spreadsheet exports into one table, but really for the purpose of my database it will...
2
by: Casey Hawthorne | last post by:
Currently PyPy is working toward compiling to C a restricted subset of Python, called RPython. Would it be possible for PyPy to "compile" the full subset of Python by also using a lot smaller...
1
by: JayDog | last post by:
I have a large data file that I split into smaller more manageable chunks (went from a 12.86 GB file to 500 MB - 1.6 GB chunks). I now want to add to the PERL script and go back through those more...
3
by: Brian | last post by:
I have a windows forms project done in vb.net. One of the forms creates graphs based on the data supplied to it. I want to take multiple graphs and paste them into a larger Image object. I...
4
by: coldy | last post by:
Hi, I have a large txt file (1GB) which I need to break into smaller files based on the contents of a column in the file. The values in the column of intrest starts low, then increases, then...
1
by: z1 | last post by:
hi- i wrote a program with java using eclipse and i think i remember it used 70,000k in the process list in windows in task manager. i understand that there is some eclipse runtime overhead...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.