Cannot read file 
Author Message
 Cannot read file

Dear Perl Specialist,

    I have installed ActivePerl 5.6 into my Win98, and it works with my
Personal Web Server.

    All Perl script run very well, but it cannot read data file.

    However, it can read the data file from DOS.

    Is it a bug or something I miss?  Could you advis me.

    The following is my script.

=========================================
print "Content-type:text/html\n\n";

# open(INF,"data.db") or dienice("Can't open data.db: $! \n");
$input="data.txt";
print $input;

close(INF);
..........
=========================================
(the DATA.DB is placed in the same directory)

Eddie Chu



Sun, 29 Sep 2002 03:00:00 GMT  
 Cannot read file

Quote:
>> On Wed, 12 Apr 2000 23:25:18 +0800,

> (the DATA.DB is placed in the same directory)

In the same directory as what?

The same directory as the file containing your perl
program, or in the same directory that the program is
actually running?

    use Cwd;
    print cwd;

may be illuminating.

hth
tony

PS comp.lang.perl is dead.



Sun, 29 Sep 2002 03:00:00 GMT  
 Cannot read file

Quote:
> > (the DATA.DB is placed in the same directory)

> In the same directory as what?

The DATA.TXT and DATA.DB are in the same directory.  I don't see you
printing the file out at any time.  Is DATA.DB a text file or a binary file?

Quote:
> PS comp.lang.perl is dead.

Visit dead places often?


Sun, 29 Sep 2002 03:00:00 GMT  
 Cannot read file
[snipped & cleaned up]

Quote:

> Dear Perl Specialist,
>     I have installed ActivePerl 5.6 into my Win98, and it works with my
> Personal Web Server.
>     All Perl script run very well, but it cannot read data file.
>     However, it can read the data file from DOS.
>     Is it a bug or something I miss?  Could you advis me.
>     The following is my script.
> open(INF,$input) or dienice("Can't open data.txt: $! \n");

I would be interested in what $! is telling you.  I'm not familiar with
PWS, but I would imagine that it writes error logs of some variety.  I
don't think this would apply so much on Win98, but the script may be
running into a permissions problem...ie when you run it as one user from
the command line, you have permission to view the file, but when you run
through the web server you may be running as a different user with lower
permissions.  Again, I'm not familiar enough with Win98 to be sure, but
if you were on *nix, that would be my first guess.

Also, I would try using the full path to the file instead, ie:

$input = "C:/web/data/data.txt";
open (INF, $input) || die "Couldn't open $input: $!";

Matt

--
Matthew Leonhardt
Programmer/Analyst

Starkmedia | for the web
219 N. Milwaukee Street
Milwaukee, WI  53202

p 414.226.2710
f 414.226.2705

w http://www.starkmedia.com



Sun, 29 Sep 2002 03:00:00 GMT  
 Cannot read file
Dear Perl Gurus,
In the routine below, the $dif can make the hour be as much as 35. I need to
keep the hours in military (up to 23). So I use the "if" thing.



Quote:
}

But this doesn't work...
Help!
#########
$test_hour = ($hour + $dif);
  if($test_hour eq 24){
$test_hour = "0";
Quote:
}

if($test_hour eq 25){
$test_hour = "1";
Quote:
}

etc....
###########


Sun, 29 Sep 2002 03:00:00 GMT  
 Cannot read file

Quote:

> Dear Perl Gurus,
> In the routine below, the $dif can make the hour be as much as 35. I need to
> keep the hours in military (up to 23). So I use the "if" thing.
> Is there a prettier way? Like...




> }
> But this doesn't work...
> Help!
> #########
> $test_hour = ($hour + $dif);
>   if($test_hour eq 24){
> $test_hour = "0";
> }
> if($test_hour eq 25){
> $test_hour = "1";
> }
> etc....
> ###########

#!/usr/bin/perl -w

use strict;

my $whour = 35;
my $rhour = &convert($whour);

print "$rhour\n";

sub convert {  
    my $hour = $_[0];

    if ($hour >= 24) {
        $hour %= 24;
    }

    return $hour;

Quote:
}

__OUTPUT__
11

anm
--
Andrew N. McGuire            43rd Law of Computing:

Evanston, Illinois           fortune: Segmentation violation -- Core dumped



Sun, 29 Sep 2002 03:00:00 GMT  
 Cannot read file


Quote:

> > Dear Perl Gurus,
> > In the routine below, the $dif can make the hour be as much as 35. I
need to
> > keep the hours in military (up to 23). So I use the "if" thing.
> > Is there a prettier way? Like...
[...]
> sub convert
>     my $hour = $_[0];
>     if ($hour >= 24) {
>         $hour %= 24;
>     }
>     return $hour;
> }

Why the "if"? Evaluating the "if" costs more time than simply doing the
modulo

sub norm{
    return $_[0] % 24;

Quote:
}

jue


Sun, 29 Sep 2002 03:00:00 GMT  
 Cannot read file

[ snip of my inefficient example ]

Quote:
> Why the "if"? Evaluating the "if" costs more time than simply doing the
> modulo

> sub norm{
>     return $_[0] % 24;
> }

And right you are, dont know why I put that "if" in there really.

#!/usr/bin/perl -w

use strict;
use Benchmark;

timethese (100000, {
       'test1' => '&convert(35)',
       'test2' => '&norm(35)'

Quote:
});

sub convert {  
    my $hour = $_[0];

    if ($hour >= 24) {
        $hour %= 24;
    }

    return $hour;

Quote:
}

sub norm {
    return $_[0] % 24;

Quote:
}

__END__
Benchmark: timing 100000 iterations of test1, test2...


Yours is indeed a better, simpler and faster way.

Regards,

anm
--
Andrew N. McGuire            43rd Law of Computing:

Evanston, Illinois           fortune: Segmentation violation -- Core dumped



Sun, 29 Sep 2002 03:00:00 GMT  
 Cannot read file

Quote:

> Dear Perl Gurus,
> In the routine below, the $dif can make the hour be as much as 35.
> I need to keep the hours in military (up to 23). So I use the "if"
> thing.
> Is there a prettier way? Like...




> }
> But this doesn't work...

Because it's... well, junk. Just toss that. You're making things much
harder on yourself than you need to.

Quote:
> $test_hour = ($hour + $dif);
>   if($test_hour eq 24){
> $test_hour = "0";
> }
> if($test_hour eq 25){
> $test_hour = "1";
> }
> etc....

This is ugly too. You're doing math: use numbers, not strings. Get
thyself a good introductory Perl book and learn the difference between
eq and ==, 1 and "1", etc.

$test_hour = $hour + $dif;
if ($test_hour > 23) {
    $test_hour -= 24;

Quote:
}

But what about the full day of difference? Does it matter to you? This
is more robust:

while ($test_hour > 23) {
    $day++;
    $test_hour -= 24;

Quote:
}

BTW, comp.lang.perl is a zombie. Let it rest in peace and bring your
general Perl questions to comp.lang.perl.misc.

-mjc



Sun, 29 Sep 2002 03:00:00 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Cannot read file

2. BUG? Cannot Read 5.004 .db file with 5.005

3. Newbie Question: cannot read data from .pl

4. suid script cannot read from <DATA>

5. DB_FILE: cannot read the database

6. ghostscript cannot read canvas->postscript output

7. Explicit file handling: Cannot update file (Perl for OS/2)

8. Posted data to a shtml file with SSI but cannot read it from the perl file?

9. [question: cannot delete the last line of a file]

10. Cannot open large files (>2GB) on Solaris 2.8

11. Cannot delete temp file using system() cmd

12. Cannot seem to dup2(FILE, 3)...

 

 
Powered by phpBB® Forum Software