Ask a Question related to PERL Beginners, Design and Development.
-
R Huber #1
Default VAriable
Greeting:
When I execute the following:
<>;
print;
I get the error message "Use of uninitialized value in
print"
but when I exectue:
while (<>) {
print;
}
I get what I type in echoed back to my screen.
Why does the first snippet of code get an error
message and the second not?
Thanks,
rj
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
[url]http://webhosting.yahoo.com/ps/sb/[/url]
R Huber Guest
-
#39251 [NEW]: variable variable class array property is read only
From: taskfreak at gmail dot com Operating system: mac os PHP version: 5.1.6 PHP Bug Type: Class/Object related Bug... -
problem with setting up a default value for a datetime variable
OK, I am using MySQL Administrator 1.1.9 and MySQL 5.0.19 on Windows XP Pro. I am setting up a table which I will routinely populate by uploading... -
Need help setting a default variable
I have a query that results in one field for one unique record (Time_ID)...it is an integer. What I need to do is grab that one value at the... -
Setting index.cfm as the default document??? Yes, it hasbeen added as a default document in IIS.
I am having trouble getting IIS to recognize the default index.cfm document, and I was wondering if anyone could give me some guidance. I created a... -
#22237 [Com]: PHP crashes when class references property using variable variable
ID: 22237 Comment by: rep at devdomain dot com Reported By: peter at globalvision dot com dot au Status: Closed... -
John McKown #2
Re: Default VAriable
On Tue, 3 Feb 2004, r huber wrote:
This behaviour is normal and is documented on the Web at:> Greeting:
>
> When I execute the following:
>
> <>;
> print;
>
> I get the error message "Use of uninitialized value in
> print"
>
> but when I exectue:
>
> while (<>) {
> print;
> }
>
> I get what I type in echoed back to my screen.
>
> Why does the first snippet of code get an error
> message and the second not?
> Thanks,
> rj
[url]http://www.perldoc.com/perl5.8.0/pod/perlop.html#I-O-Operators[/url]
It says (quoting)
<quote>
Ordinarily you must assign the returned value to a variable, but there is
one situation when an automatic assignment happens. If and only if the
input symbol is the only thing inside the conditional of a while
statement (even if disguised as a for(;;) loop), the value is
automatically assigned to the global variable $_, destroying whatever was
there previously. (This may seem like an odd thing to you, but you'll use
the construct in almost every Perls script your write.) The $_ variable is
not implicitly localized. You'll have to put a local $_; before the loop
if you want that to happen.
</quote>
The above site is very handly to have up in your browser while writing
Perl code. At least, it is for me!
--
Maranatha!
John McKown
John McKown Guest



Reply With Quote

