>    1. Re: Strange opendir()/readdir() behavior... (-alpha-)
>    2. Re: Strange opendir()/readdir() behavior... (John W. Kennedy)
> 
> 
> ----------------------------------------------------------------------
> 
> Message: 1
> Date: Wed, 1 Mar 2006 12:32:13 +0200
> From: -alpha- <[EMAIL PROTECTED]>
> Subject: Re: Strange opendir()/readdir() behavior...
> To: [email protected]
> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset="iso-8859-1"
> 
> Yes, now I see... tried -f test on these "objects", it failed. <*> also
> ignores them. A question is -- how to get a list of IE cache? Maybe some
> Win32::OLE / WMI needed here (though i'm not very familiar with the 
second
> one.)
> 
> $Bill Luebkert wrote:

it could be the way MS is attempting (horribly) to protect you from 
detrimental scripts.

> 
> >Try dropping all the &&'s - what are you some kinda shell programmer ? 
;)
> I just like things I could test via perl -e "..." (with some minor 
changes
> in this case)
> 
> John W. Kennedy wrote:
> 
> >Never, ever, ever use '\' to separate directories
> 
> But why? On mswin filesystems, '\' is default delimiter AFAIK. Un *nix 
i'll
> use '/'.
> 

portability and compatibility

also, the && in your original code is done in a way that makes it harder 
to read. EVERYTHING John said i would consider basics of good code 
writing. this has SEVERAL implications, among them:
-easier for others to help you
-easier for future maintenance

grabbing your original code, i would suggest transforming it to look more 
like this:

#! /usr/bin/perl

###
# the first line is purely for portability
# since you seem to be writing exclusively for windows
###
# the next two lines just make good sense to use during development
# the second is good to comment out when it's working but to use
# during maintenance reviews and alterations
###

use strict;
use warnings;

# declare variables and use those. makes more robust code
# also allows you to reuse a location easier
my $dir='C:/install/_import/Temporary Internet Files';
my $output='';

# separate the commands too. it cuts down on confusion.
# just because perl can condense 30 lines to 3 does not
# mean that is always a good idea.
opendir DH, $dir or die "Cannot open $dir $! $^E";
# i used the variable to easily add a failure case

while($dir_item = readdir(DH)){
  # while there is an item being read
  $output.="$dir_item\n";
}

# nicely close the handle
closedir DH;

# print what was found
print $output;
__END__

is that not much easier for the maintenance person in the future?
you could also do something like checking to see if the item is
a file or directory quite easily. you could create a sub-routine
or such and iterate easily too.
as a refresher, here's what you wrote:
opendir(DH,'C:\install\_import\Temporary Internet Files') && (@d =
readdir(DH)) && closedir(DH) && print join("\n",@d);


-----------------------------------------
PLEASE NOTE: 
SeaChange International headquarters in Maynard, MA is moving!
Effective March 1, 2006, our new headquarters address will be:

SeaChange International 
50 Nagog Park 
Acton, MA 01720 USA 

All telephone numbers remain the same: 
Main Corporate Telephone: 978-897-0100 
Customer Service Telephone: 978-897-7300

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to