Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: opened file being overwritten

by 2teez (Priest)
on Dec 13, 2012 at 20:30 UTC ( #1008716=note: print w/ replies, xml ) Need Help??

in reply to opened file being overwritten

"..why isnt the filehandle FILE4 being printed out.."

Because when the subroutine finishes the filehandle also closes. Please also check that this in your code open FILE4,"$_[3]" || die "could not open $_[3]"; which has no ">" like the others.
bart you are right, I missed that.
Simply using strict and warnings would have indicated the problems.

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me

Comment on Re: opened file being overwritten
Download Code
Replies are listed 'Best First'.
Re^2: opened file being overwritten
by bart (Canon) on Dec 13, 2012 at 20:38 UTC
    That is just so wrong. FILE1...FILE4 are globals, meaning they won't be closed when the sub exits.
Re^2: opened file being overwritten
by perishowl (Initiate) on Dec 13, 2012 at 20:50 UTC

    still not working :(

    #!/bin/Perl use warnings; if (@ARGV < 4) { print ("you need to provide 4 arguments\n\t4th argument is file to + parse"); exit; } $fh = pop(@ARGV); openfile(@ARGV); sub openfile { open FILE1,">$_[0]" || die "could not open $_[0]"; open FILE2,">$_[1]" || die "could not open $_[1]"; open FILE3,">$_[2]" || die "could not open $_[2]"; open FILE4,">$fh" || die "could not open $fh"; while (my $line = <$fh>) { print $line; } }
      i get the warning readline() on unopened filehandle at line 21. so that would be my while loop while (<$fh>) { print $line; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1008716]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2015-11-27 14:34 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (729 votes), past polls