Re: Finally a better script!
- From: "A. Sinan Unur" <1usa@xxxxxxxxxxxxxxxxxxx>
- Date: Fri, 29 Apr 2005 21:41:07 GMT
Nikos <hackeras@xxxxxxxxx> wrote in news:d4u0m7$qjt$1@xxxxxxxxxxxx:
> You understand very quickly
Well, yes, I tend to, but who is this comment directed to?
> my ($data, @data);
Always declare variables in the smallest applicable scope. I am not sure
what you want to do with these variables.
See http://perl.plover.com/FAQs/Namespaces.html
> open(FILE, "<../data/text/$script.txt") or die $!;
> @data = <FILE>;
> close(FILE);
>
> $data = join('', @data);
1. Where did $script come from?
2. If you just want to slurp the file, then do so:
my $data;
{
my $fn = "/data/text/$script.txt";
open my $file, '<', $fn or die "Cannot open $fn: $!";
local $/;
$data = <$file>;
close $file or die "Cannot close $fn: $!";
}
$data will now contain the entire contents of /data/text/$script.txt.
Or, you can use the excellent File::Slurp module.
Sinan
--
A. Sinan Unur <1usa@xxxxxxxxxxxxxxxxxxx>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
.
- Follow-Ups:
- Re: Finally a better script!
- From: Nikos
- Re: Finally a better script!
- References:
- Finally a better script!
- From: Nikos
- Finally a better script!
- Prev by Date: Re: Can this be rewritten better?
- Next by Date: need module download location SNMP-v5.1.1/NetSNMP-v5.1.1
- Previous by thread: Re: Finally a better script!
- Next by thread: Re: Finally a better script!
- Index(es):
Relevant Pages
|
|