in reply to Re: Re: Re: Re: Passing an array to a subroutine
in thread Passing an array to a subroutine

Why would $hdr be empty? Two possibilities. First, it's a blank line. chomping it will remove the newline, leaving a possibly empty string. The second possibility is that the open failed. Here's a better error line:

open(FILE, $data) or die "Can't open ($data): $!";

That gives you the name of the file, surrounded by non-whitespace characters as a sanity check, along with the system error message. You'll have better luck if you let Perl help you.

Update: If it's not a file, don't open it. open works on files (in the Unix sense). If you have the data you want to munge already in an array or a scalar, use split or a regex to get at it. That's the problem.

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Passing an array to a subroutine
by gisrob (Novice) on Aug 01, 2001 at 00:25 UTC
    Ok - in the spirit of letting perl help me, how does open handle arrays that are not explicitly files? In my code, $data is just what I read in from @_, not a file. But when I run this (even in the debugger) all the contents of $data are written to STDOUT and the program terminates (not the desired output!). Update: I did what you suggested, and get the following error:
    ): File name too long at ocean_return2b.pl line 176, <STDIN> line 4. Debugged program terminated. Use q to quit or R to restart,
    line 176: open(FILE, $aref) or die "Cannot open: ($aref): $!"; It seems that it tries to open the entire contents of $aref, as that is what is returned to the screen.