Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. #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...
    2. 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...
    3. 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...
    4. 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...
    5. #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...
  3. #2

    Default Re: Default VAriable

    On Tue, 3 Feb 2004, r huber wrote:
    > 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
    This behaviour is normal and is documented on the Web at:

    [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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139