Readline question

  • Thread starter mauro papandrea
  • Start date
M

mauro papandrea

cat dati
line1
line2
line3
line4

This simple program ( an oversimplified version of my original one for
sake of simplicity ) works:

#!/bin/perl
open (FILE, "dati");
while ( <FILE> ) {
$line = readline(FILE);
print "$. $line";
}
close(FILE);

this is its output:

2 line2
4 line4

However, this oneliner gives a weird error:
perl -ne '$line = readline; print "$. $line"; ' dati

Modification of a read-only value attempted at -e line 1.

What am I missing?

Thank you

Regards

Mauro
 
W

Wolf Behrenhoff

line1
line2
line3
line4

However, this oneliner gives a weird error:


Modification of a read-only value attempted at -e line 1.

What am I missing?

Seems to be a bug in older Perl versions. I can reproduce this behaviour
with 5.8.8, however it works without any problem in 5.10.1.

- Wolf
 
M

mauro papandrea

Seems to be a bug in older Perl versions. I can reproduce this behaviour
with 5.8.8, however it works without any problem in 5.10.1.

- Wolf


Thank you very much.
As a matter of fact, I was using 5.8 version ( I apologize for not
having posted that ).

Have a nice day

Mauro
 
S

Steve C

Seems to be a bug in older Perl versions. I can reproduce this behaviour
with 5.8.8, however it works without any problem in 5.10.1.

It's not a bug. In perl 5.8.8 the parameter to readline had no default to ARGV.
The documentation is clear.
 
U

user

It's not a bug. In perl 5.8.8 the parameter to readline had no default
to ARGV.
The documentation is clear.

Great!
Thank you very much.
I had read documentation but it was for 5.10, not for 5.8
and that was probably what I missed

Have a nice day

Mauro
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top