Re: Finally a better script!



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
.



Relevant Pages

  • Re: "use CGI " hangs "CGI time out "
    ... Brian Wakem wrote: ... > A. Sinan Unur wrote: ... >> You should always declare variables in the smallest applicable scope, ...
    (comp.lang.perl.misc)
  • Re: "use CGI " hangs "CGI time out "
    ... Sinan Unur wrote: ... You should always declare variables in the smallest applicable scope, and name them so they are readable. ... It's also worth pointing out that when using strict, 4 errors will occur in the above two lines as the my only applies to the first variable in each case. ...
    (comp.lang.perl.misc)
  • [OT] Re: "use CGI " hangs "CGI time out "
    ... >>> You should always declare variables in the smallest applicable ... >>> scope, and name them so they are readable. ... > int a,b,c; ... Sinan Unur ...
    (comp.lang.perl.misc)
  • Re: Games.pl again
    ... Sinan Unur wrote: ... > comp.lang.perl.misc guidelines on the WWW: ... Fort Worth, Texas ... Prev by Date: ...
    (comp.lang.perl.misc)
  • Re: use of CSS in CGI generated docs, Impossible ?
    ... I had incorrectly assumed that the names in:standard ... Sinan Unur ... comp.lang.perl.misc guidelines on the WWW: ... Prev by Date: ...
    (comp.lang.perl.misc)