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]