Problem with Printing an array 
Author Message
 Problem with Printing an array

I'm working on the llama book, chapter 3.  I'm running it on a windows 98
platform.  I can't get this program, which is typed directly from the book
to print the output.  There are no compile errors.  Here's the code

srand;


Pretty straightforward.  Anyhow.  I enter all the strings.  Then I Control-Z
to send the EOF.  Then it prints a blank line, then exits the program.  Any
ideas?



Sat, 04 Aug 2001 03:00:00 GMT  
 Problem with Printing an array

Quote:

> I'm working on the llama book, chapter 3.  I'm running it on a windows 98
> platform.  I can't get this program, which is typed directly from the book
> to print the output.  There are no compile errors.  Here's the code

> srand;


> Pretty straightforward.  Anyhow.  I enter all the strings.  Then I Control-Z
> to send the EOF.  Then it prints a blank line, then exits the program.  Any
> ideas?

This might not be it, but have you run this test multiple
times? If so, do you get only a blank line each time? It
does not print the "Answer: " string?

If it prints the "Answer: " followed by a newline, then I
would guess that you are getting a blank line in as part
of your input (maybe even the line with the Ctrl-Z?), and
then it is getting selected randomly. But this should not
reproduce reliably unless the "srand" function is broken
under Win98.

If you don't even get "Answer: " printed out, you have
something more fundamental wrong. The above three lines
behave as it is supposed to under Solaris 2.5.1 and
Perl 5.00502. Are you using ActivePerl Build 509? If not,
go get it from the ActiveState site:

    http://www.activestate.com/ActivePerl/

--
Mike Arms

When cryptography is outlawed, bayl bhgynjf jvyy unir cevinpl.



Sun, 05 Aug 2001 03:00:00 GMT  
 Problem with Printing an array
Dear Mike & others,

I have encountered this problem before.  Typing CTRL-Z to
end standard input screws up programs writing a single line
to standard output.  I don't know why, but it does.  I've
only seen it on Windows 98.

The easiest fix is to add a couple of newlines before the
actual text.

Regards,

Mick



Mon, 06 Aug 2001 03:00:00 GMT  
 Problem with Printing an array

Typing CTRL-Z to end standard input

On unix, ^Z typically suspends the process, which keeps the script from
running.

Could it also do this under windoze ?



Mon, 06 Aug 2001 03:00:00 GMT  
 Problem with Printing an array

Quote:

> On unix, ^Z typically suspends the process, which keeps the script from
> running.

> Could it also do this under windoze ?

No: under Windows, ^Z marks the end of file.  This works at the
keyboard, but it also works (infuriatingly) in disk files.  It's common
for programs developed under Unix to fail under Win32 because their
authors haven't used 'binmode' after opening some file or other.

Suppose I use the following program to create a file containing a ^Z:

        open BIN, '>bin.txt' or die "Can't create bin.txt:\n$!";
        print BIN "a\n\x1A\nb\n";

If I run it through the following (even shorter) program --

        print <>;

then I get the following output:

        a

Is there anything I can do to make this script work properly?  I've
tried starting the script with

        binmode ARGV;

but it doesn't make any difference.  Do I really need to open the files

Markus

--
Delete the 'delete this bit' bit of my address to reply



Mon, 06 Aug 2001 03:00:00 GMT  
 Problem with Printing an array

Quote:

>Is there anything I can do to make this script work properly?  I've
>tried starting the script with

>    binmode ARGV;

>but it doesn't make any difference.  Do I really need to open the files


Yes, AFAIK.    The problem is that the binmode() must be done between
the open and the read, but these both occur within the same call of <>.

I thought you might be able to do some tricks with eof(), but all I
discovered is that eof() (or its documentation) is broken.

Mike Guy



Wed, 08 Aug 2001 03:00:00 GMT  
 Problem with Printing an array
[A complimentary Cc of this posting was sent to M.J.T. Guy


Quote:
> >       binmode ARGV;

> >but it doesn't make any difference.  Do I really need to open the files

> Yes, AFAIK.    The problem is that the binmode() must be done between
> the open and the read, but these both occur within the same call of <>.

See the discussion of $^B variable on p5p.  But somebody needs to
implemente it first...

Ilya



Thu, 09 Aug 2001 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Please help: Problem printing a string from an array to a file

2. Array of arrays, stack & print layout

3. Printing a vertical table from a hash of arrays

4. Printing many arrays to a file.

5. DOS print of associative arrays?

6. array quiz: how print only certain elements?

7. Printing Arrays urgent help required!!!Please help!!!

8. how to print out every second value of an array

9. printing an array

10. array not printing what I want

11. Odd 'print @array' behavior with 4.035

12. Strange behaviour of associative array in print string

 

 
Powered by phpBB® Forum Software