basename & dirname in Perl
sub basename($) { my $file = shift; $file =~ s!^(?:.*/)?(.+?)(?:\.[^.]*)?$!$1!; return $file; } sub dirname($) {my $file = shift; $file =~ s!/?[^/]*/*$!!; return $file; }
DZone Snippets > Minimiscience > directory
12374 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
sub basename($) { my $file = shift; $file =~ s!^(?:.*/)?(.+?)(?:\.[^.]*)?$!$1!; return $file; } sub dirname($) {my $file = shift; $file =~ s!/?[^/]*/*$!!; return $file; }
<?PHP $columns = 3; $im = glob("*.{gif,jpg,png}", GLOB_BRACE); $rows = ceil(count($im) / $columns); for ($i = 0; $i < $rows; $i++) { echo "\n<TR>"; for ($j = $columns*$i; isset($im[$j]) && $j - $columns*$i < $columns; $j++) { echo "<TD>$im[$j]<BR><IMG SRC='$im[$j]'></TD>"; } echo "</TR>"; } ?>