Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Readline question

Reply
Thread Tools

Readline question

 
 
mauro papandrea
Guest
Posts: n/a
 
      03-03-2011
> 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
 
Reply With Quote
 
 
 
 
Wolf Behrenhoff
Guest
Posts: n/a
 
      03-03-2011
On 03.03.2011 12:23, mauro papandrea wrote:
> > cat dati

> line1
> line2
> line3
> 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?


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
 
Reply With Quote
 
 
 
 
mauro papandrea
Guest
Posts: n/a
 
      03-03-2011
On 03/03/2011 16.01, Wolf Behrenhoff wrote:
> On 03.03.2011 12:23, mauro papandrea wrote:
>> > cat dati

>> line1
>> line2
>> line3
>> 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?

>
> 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
 
Reply With Quote
 
Steve C
Guest
Posts: n/a
 
      03-03-2011
On 03/03/2011 10:01 AM, Wolf Behrenhoff wrote:
> On 03.03.2011 12:23, mauro papandrea wrote:
>> > cat dati

>> line1
>> line2
>> line3
>> 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?

>
> 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.


 
Reply With Quote
 
user@domain.invalid
Guest
Posts: n/a
 
      03-04-2011
On 03/03/2011 16.55, Steve C wrote:
> On 03/03/2011 10:01 AM, Wolf Behrenhoff wrote:
>> On 03.03.2011 12:23, mauro papandrea wrote:
>>> > cat dati
>>> line1
>>> line2
>>> line3
>>> 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?

>>
>> 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.
>
>


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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
compiling python 3.1.2 with local readline fails to get readline - help! gavino Python 4 09-20-2010 05:17 AM
Beginner's question re: using the readLine() method Dave Java 3 02-12-2008 02:35 AM
Getting application ReadLine and Perl debugger ReadLine to cooperate Andrew DeFaria Perl Misc 1 01-30-2008 11:46 PM
Readline::readline() blocking all other threads Jean-Michel Ruby 0 12-22-2007 01:00 AM
GNU Readline question (needed for tintin++ modifications) Jason C Programming 1 10-18-2003 05:07 AM



Advertisments