the reason to this being you need to append "my" to declare each variable
before use..
my $file;
my $in_dir;
my $tstopen;
etc..
try phrase it like this:
#!/usr/bin/perl
use strict;
use warnings;
# Open Files
my $in_dir;
opendir(IN_DIR, "/opt/crxml/tstdir") or die "directory does not exist";
# Read Directory
while (my $file = readdir(IN_DIR)) {
next if $file =~ /^\.\.?$/;
print "$file found in $in_dir\n";
chomp $file;
#Open Files
open (FH, "< $file") or die "could not open $file";
my $tstopen = <FH>;
chomp $tstopen;
print "$tstopen\n";
while (<FH>) {
my @fields1 = split /:/, $tstopen;
print "$fields1[0]\n";
print "$fields1[1]\n";
print "$fields1[2]\n";
print "############## End of Test Open ############\n\n";
}
}
maybe that'll work. the "use strict" forces declaration of all variables
using my() before use. i can't remember the perldoc command to see more info
on this, although i know there is one.
dan
"Chuck Belcher" <[EMAIL PROTECTED]> wrote in message
000d01c26c0a$f5a4b480$1901a8c0@haley">news:000d01c26c0a$f5a4b480$1901a8c0@haley...
> I added the use strict and use warnings now I get the following...
>
> Global symbol "$file" requires explicit package name at crxml.pl line 8.
> Global symbol "$in_dir" requires explicit package name at crxml.pl line
> 10.
> Global symbol "$tstopen" requires explicit package name at crxml.pl line
> 15.
> Global symbol "@fields1" requires explicit package name at crxml.pl line
> 19.
> Execution of crxml.pl aborted due to compilation errors.
>
> Code..
>
> #!/usr/bin/perl
> use strict;
> use warnings;
> # Open Files
> opendir(IN_DIR, "/opt/crxml/tstdir") or die "directory does not exist";
>
> # Read Directory
> while ($file = readdir(IN_DIR)) {
> next if $file =~ /^\.\.?$/;
> print "$file found in $in_dir\n";
> chomp $file;
>
> #Open Files
> open (FH, "< $file") or die "could not open $file";
> $tstopen = <FH>;
> chomp $tstopen;
> print "$tstopen\n";
> while (<FH>) {
> @fields1 = split /:/, $tstopen;
> print "$fields1[0]\n";
> print "$fields1[1]\n";
> print "$fields1[2]\n";
> print "############## End of Test Open ############\n\n";
> }
> }
>
> -----Original Message-----
> From: nkuipers [mailto:[EMAIL PROTECTED]]
> Sent: Friday, October 04, 2002 7:49 PM
> To: Chuck Belcher
> Cc: [EMAIL PROTECTED]
> Subject: RE: Will not read line and split.
>
>
> Put
>
> use strict;
> use warnings;
>
> at the top of most programs you ever write. As for failing calls to
> open(),
> phrase the call like this:
>
> open FH, "< $file" or die "Could not read $file: $!";
>
> Once the handle is opened successfully, iterate through the file line by
> line
> like this:
>
> while (<FH>) { ... } #in this block, $_ holds contents of current line
>
> See if cleaning things up a bit like this helps. :)
>
> Regards,
>
> Nathanael
>
>
> >===== Original Message From "Chuck Belcher" <[EMAIL PROTECTED]>
>
> >===== I can now get the first part to open and read a file, however, It
>
> >still does not work when I am reading the directory. The print $file
> >found in $in_dir does work it displays a list of files in the
> >directory. The open (IN1, "<$file"); does not appear to open the files.
>
> >I am loosing hair by the minute.
> >
> >#!/usr/bin/perl
> ># Input Files
> >$in_dir = "/opt/crxml/tstdir";
> ># Open Files
> >opendir(IN_DIR, "$in_dir");
> ># Read Directory
> >while ($file = readdir(IN_DIR)) {
> > next if $file =~ /^\.\.?$/;
> > print "$file found in $in_dir\n";
> > chomp $file;
> >#Open Files
> > open (IN1, "< $file");
> > $tstopen = <IN1>;
> > chomp $tstopen;
> > print "$tstopen\n";
> > @fields1 = split /:/, $tstopen;
> > print "$fields1[0]\n";
> >
> >chuck
> >
> >-----Original Message-----
> >From: Mark Anderson [mailto:[EMAIL PROTECTED]]
> >Sent: Friday, October 04, 2002 7:09 PM
> >To: Chuck Belcher
> >Subject: RE: Will not read line and split.
> >
> >
> >What errors are you getting? Are you using strict and warnings? I
> >would change your open statement in the first example to: open (IN,
> >"/opt/crxml/tstdir/updt1.dat") or die "file failed to open $!";
> >
> > /\/\ark
> >
> >-----Original Message-----
> >From: Chuck Belcher [mailto:[EMAIL PROTECTED]]
> >Sent: Friday, October 04, 2002 3:59 PM
> >To: [EMAIL PROTECTED]
> >Subject: Will not read line and split.
> >
> >
> >My goal is to spit a file or files that are in a specific directory.
> >My problem is that I can't read the file.
> >
> >Attempt to read file:
> >#!/usr/bin/perl
> >open (IN, " < /opt/crxml/tstdir/updt1.dat");
> >until (eof IN) {
> > $line = <IN>;
> > chomp $line;
> > print $line;
> > @fields = split /:/, $line;
> > print "$fields[0]\n";
> >}
> >
> >Same attempt but with directory read
> >#!/usr/bin/perl
> ># Input Files
> >$in_dir = "/opt/crxml/tstdir";
> ># Open Files
> >opendir(IN_DIR, "$in_dir");
> ># Read Directory
> >while ($file = readdir(IN_DIR)) {
> > next if $file =~ /^\.\.?$/;
> > print "$file found in $in_dir\n";
> > chomp $file;
> >#Open Files
> > open (IN1, "< $file");
> > $tstopen = <IN1>;
> > chomp $tstopen;
> > print "$tstopen\n";
> > @fields1 = split /:/, $tstopen;
> > print "$fields1[0]\n";
> >
> >Does anyone have any idea what I am doing wrong .. OS is solaris 8.
> >
> >Chuck
> >
> >
> >--
> >To unsubscribe, e-mail: [EMAIL PROTECTED]
> >For additional commands, e-mail: [EMAIL PROTECTED]
>
> "Ain't no blood in my body, it's liquid soul in my veins" ~Roots Manuva
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]