Welcome to WebProNews Breaking eBusiness and Search News
Advertise | Newsletter | Sitemap | News Feeds News Feed 
 WebProNews Search Part of the iEntry network iEntry inc. 

Perl Loop Causes Strange Read-only Error

A.P. Lawrence
Expert Author
Published: 2006-10-24

WebProNews RSS Feed


Ok, folks: I don't understand this. It must have something to do with anonymous arrays in Perl (no, it doesn't, I realize now), but I don't grok the connection.

I ran into this in attempting a seemingly simple change in some customer's code; it wasn't hard to fix, but I simply do not understand why this happened.

Well, that's not precisely true: it happened because I went ahead in a hurry and added something "quick". It was just a new loop around some existing code. Ordinarily I would have written it like this:

@foo=qw(foo ba);
foreach $loopvar (@foo) { ..


But for some reason I did this instead:

#!/usr/bin/perl -w
# no problem here
caroomba("first");

@dayval=qw(foo ba);
foreach $dayval (@dayval) {
# no problem here
caroomba($dayval);
}

foreach $dayval ("foo2","ba2") {
# no problem here either
caroomba($dayval);
}

foreach ("foo3","ba3") {
# doesn't like this
$dayval=$_;
caroomba($dayval);
}

sub caroomba {
my $p=shift;
print "Caroomba called $p\n";
open(I,"./t");
while (<I>) {
# stuff..
}
close I;
}


When run, that produces:

Caroomba called first
Caroomba called foo
Caroomba called ba
Caroomba called foo2
Caroomba called ba2
Caroomba called foo3 Modification of a read-only value attempted at ./t.pl line 23, <I> line 23.


Why? Dude, werent you listening? I do not comprehend why. Some person with more brains than I currently have will have to explain that one to both of us.

*Originally published at APLawrnece.com

View All Articles by A.P. Lawrence



Receive Our Daily Email of Breaking eBusiness News


About the Author:
A.P. Lawrence provides SCO Unix and Linux consulting services http://www.pcunix.com

WebProNews RSS Feed

More Expert Articles Articles

Contact WebProNews
Advertisement





TOP NEWS

Targeted Information for Business
WebProNews is part of the iEntry network

Internet Business: Marketing: Small Business:
WebProNews MarketingNewz SmallBusinessNewz
WebProWorld AdvertisingDay PromoteNews
EcommNewz SalesNewz EntrepreneurNewz

Software: Search Engines: Web Design:
WebMasterFree Jayde B2B DesignNewz
NetworkingFiles SearchZA FlashNewz
SecurityConfig SearchNewz WebSiteNotes

Developer: IT Management: Security:
DevWebPro ITManagement SecurityProNews
DevNewz SysAdminNews SecurityConfig
TheDevWeb NetworkingFiles NetworkNewz

The iEntry Network consists of over 100 web publications reaching millions of Internet Professionals. Contact us to advertise.
eBUSINESS RESOURCES






 Advertise | Contact Us | Corporate | Newsletter | Sitemap | Submit an Article | News Feeds
 WebProNews is an iEntry, Inc. ® publication - $line) { echo $line ; } ?> All Rights Reserved
WebProWorld
Ten most recent posts.

WebProBlog
The official blog of WebProNews.

Go to WebProBlog

SearchBrains.com
NetworkingFiles
Featured Software


About WebProNews
WebProNews is the number one source for eBusiness News. Over 5 million eBusiness professionals read WebProNews and other iEntry business and tech publications.

WebProNews provides real-time coverage of internet business.

Free Email Newsletters:
WebProNews SearchNewz
WebProWorld DevWebPro
Marketing SecurityNews
Plus over 100 other newsletters!

Send me relevant info on products and services.




iEntry.com WebProWorld RSS Feed WebProWorld Contact WebProNews Print Version Email a friend Bookmark us SearchBrains.com SearchBrains RSS Feed