in reply to Re^2: opening a file passed into sub as ref
in thread opening a file passed into sub as ref

$i is not a good name for a filehandle, it's easy to get confused with the file contents.

open (my $i, "+<", $name) or warn $!; ### FAILS HERE ### while (<$i>) { chomp $i; next if $i =~ /$regexp_2_skip/; next if $i !~ /$regexp_2_get/; ($i) =~ s/:/,/g; ($i) =~ s/\s+//g; print $csv "$i,\n"; print "$i,\n"; }

as Toolic said, you probably have line endings on $name from find. Try

sub _ce { print "IN CE SUB\n"; die "no parameter!\n" unless @_; my ($ce_ref) = @_; for my $name (@{ $ce_ref }) { chomp $name; @asof = +(split("/", $name, 0))[-3,-2,-4]; $lpname = +(split("/", $name, 0))[3]; print $csv "$lpname\n"; print $csv '*' x length($lpname),"\n"; print '*' x length($lpname),"\n"; print "$name\n"; open (my $fh, "+<", $name) or die "Could not open '$name' $!"; + ### FAILS HERE ### while (my $line = <$fh>) { chomp $line; next if $line =~ /$regexp_2_skip/; next if $line !~ /$regexp_2_get/; $line =~ s/:/,/g; $line =~ s/\s+//g; print $csv "$line,\n"; print "$line,\n"; } } print $csv "\n\nHost,Entitled CPU and RAM as of @asof,\n\n"; return; }
poj