read a directory

2005-02-28 Thread Carl Johnson
Hello group,
 
I'm trying to read the directory C:\GIS\wrapped_data and write record. My 
scripts is erroring with can't open directory: no such  file or directory. 
What am I missing?
 
$outfile = $infile.txt;
my $dir = C:\GIS\wrapped_data;
opendir(DIR,$dir) or die Can't open $dir directory: $!;
open (OUT, $outfile) or die Error, cannot open file: $outfile. $!; 
$record = ;
$index=0;
while ( $numbytes = read(DIR, $record, 1200) ) {
   $index++;
   if ($numbytes == 1200) {
  print OUT $record;
   } else {
  die File Read Error on record $index: $numbytes bytes read; Should be 
1200.\n; 
   }
}
close DIR;
close OUT;


 

Carl Johnson
Principal Consultant
214-914-9509 - P
214-242-2020 - F
[EMAIL PROTECTED]





RE: read a directory

2005-02-28 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Carl Johnson wrote:
 Hello group,
 
 I'm trying to read the directory C:\GIS\wrapped_data and write
 record. My scripts is erroring with can't open directory: no such 
 file or directory. What am I missing?  
 
 $outfile = $infile.txt;
 my $dir = C:\GIS\wrapped_data;
With double quotes, what perl is seeing is C:GISwrapped_data which is 
not what you wnat. Change to single quotes or switch / and it will work as you 
want.

Wags ;)
 opendir(DIR,$dir) or die Can't open $dir directory: $!;
 open (OUT, $outfile) or die Error, cannot open file: $outfile.
 $!; $record = ;
 $index=0;
 while ( $numbytes = read(DIR, $record, 1200) ) {
$index++;
if ($numbytes == 1200) {
   print OUT $record;
} else {
   die File Read Error on record $index: $numbytes bytes read;
Should be 1200.\n; }
 }
 close DIR;
 close OUT;
 
 
 
 
 Carl Johnson
 Principal Consultant
 214-914-9509 - P
 214-242-2020 - F
 [EMAIL PROTECTED]



***
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
***


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: read a directory

2005-02-28 Thread Mark Taylor
Hey Carl -
I got in a hurry and did some cut and paste without paying close enough 
attention.

The line should read
my $dir = 'C:\GIS\wrapped_data';
I apologize for the error.
Mark

got this error line 9 near = =
aborted due to compilation error
*/Mark Taylor [EMAIL PROTECTED]/* wrote:
  Hello group,
Hello.
 
  I'm trying to read the directory C:\GIS\wrapped_data and write
record. My scripts is erroring with can't open directory: no such
file or directory. What am I missing?
 
  $outfile = $infile.txt;
  my $dir = C:\GIS\wrapped_data;
  opendir(DIR,$dir) or die Can't open $dir directory: $!;
  open (OUT, $outfile) or die Error, cannot open file:
$outfile. $!;
  $record = ;
  $index=0;
  while ( $numbytes = read(DIR, $record, 1200) ) {
  $index++;
  if ($numbytes == 1200) {
  print OUT $record;
  } else {
  die File Read Error on record $index: $numbytes bytes read;
Should be 1200.\n;
  }
  }
  close DIR;
  close OUT;
 
Try this, my $dir = = 'C:\GIS\wrapped_data' instead.
HTH,
Mark


*Carl Johnson*
*Principal Consultant*
*214-914-9509 - P*
*214-242-2020 - F*
[EMAIL PROTECTED] mailto:[EMAIL PROTECTED]*

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: read a directory

2005-02-28 Thread John W. Krahn
Carl Johnson wrote:
Hello group,
Hello,
I'm trying to read the directory C:\GIS\wrapped_data and write record.
My scripts is erroring with can't open directory: no such  file or
directory. What am I missing?
 
$outfile = $infile.txt;
my $dir = C:\GIS\wrapped_data;
Perl's double quoted strings interpolate their contents so scalar and array
variables are expanded and escape (backslash-character) sequences are
converted to their special characters.  You should use forward slashes in file
paths.

opendir(DIR,$dir) or die Can't open $dir directory: $!;
Your error message should have printed out the contents of $dir which would
have hinted at the erroneous path name.
perldoc -q quoting

open (OUT, $outfile) or die Error, cannot open file: $outfile. $!; 
$record = ;
$index=0;
while ( $numbytes = read(DIR, $record, 1200) ) {
You cannot read from a directory handle with read().  Only functions with
'dir' in their names can use a directory handle.
perldoc -f opendir
perldoc -f readdir
perldoc -f rewinddir
perldoc -f seekdir
perldoc -f telldir
perldoc -f closedir

   $index++;
   if ($numbytes == 1200) {
Although you are telling read() that you want 1200 bytes that is only a
suggestion and read() could return anything from 1 to 1200 bytes and still be
valid.  By testing for exactly 1200 bytes you could miss some data.
perldoc -f read
[snip]
 Attempts to read LENGTH characters of data into variable SCALAR from
 
 the specified FILEHANDLE.  Returns the number of characters actually
^
 read, 0 at end of file, or undef if there was an error (in the
 
 latter case $! is also set).  SCALAR will be grown or shrunk so that
 the last character actually read is the last character of the scalar
 after the read.

  print OUT $record;
   } else {
  die File Read Error on record $index: $numbytes bytes read; Should be 1200.\n; 
   }
}
close DIR;
close OUT;

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response