develooper Front page | perl.beginners | Postings from February 2002

RE: Uninitialized Value Error

Thread Previous | Thread Next
From:
Grant $ Sandra Hansen
Date:
February 25, 2002 16:50
Subject:
RE: Uninitialized Value Error
Message ID:
LMEGICLNNFHEEIDLCKJNIENGCCAA.slhgkh5@attbi.com
Thanks for all your help, I got working.

Thanks again.

-----Original Message-----
From: Luke Bakken [mailto:luke_bakken@yahoo.com]
Sent: Monday, February 25, 2002 6:11 PM
To: Lyon, Justin
Cc: 'luke_bakken@yahoo.com'; 'slhgkh5@attbi.com'; beginners@perl.org
Subject: RE: Uninitialized Value Error


use strict;
my $field1;

while (<>) {
    $field1 = $_;
    write STDOUT;
}

format STDOUT =
---------------
@<<<<<<<<<<<<<<
$field1
...

How does the above "not work"?

On Mon, 25 Feb 2002, Lyon, Justin wrote:

> Nope, that won't work because "my" by definition is only good in the
current
> scope.  format is outside of your scope, no matter what you do, so you'll
> have to use something other than "my".
>
>  Of course, you can always put the format code inside the scope of "my",
and
> then it should be fine (don't forget to get rid of the "my" qualifiers in
> the format variables:
>
> ....
>
> #unlink glob "/usr/local/scripts/security/sybase/user/*.txt";
> exit;
> format OUT_TOP =
> ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
>
> Company Name
> first column        second column              Third Column
> _____________________________________________________
> ..
> format OUT =
> @<<<<<<<<<<<<<< @<<<<<<<<<<<<<< @<<<<<<<<<<<<<<
> $field1, $field2, $field3
> ..
> }  # Just move this bracket, and get rid of the my's on the line above
>
>
> -----Original Message-----
> From: Luke Bakken [mailto:luke_bakken@yahoo.com]
> Sent: Monday, February 25, 2002 1:09 PM
> To: Lyon, Justin
> Cc: 'slhgkh5@attbi.com'; beginners@perl.org
> Subject: RE: Uninitialized Value Error
>
>
> Predeclare all of the variables you're using in your format at the top of
> the script with my:
>
> my ($field1, $field2, $field3);
>
> this way you can still keep the benefits of use strict
>
>
> On Mon, 25 Feb 2002, Lyon, Justin wrote:
>
> > Hmmmm.  Well, I think the problem is that you're using too strict
> > guidelines.  "my" will restrict you from using a variable outside the
> > current scope, so you won't be able to access it come time to format.
The
> > quickest way arround that is to get rid of your "use strict;" line, and
> then
> > get rid of all the "my" declarations.  Then you'll be using all global
> > variables, and it should run fine.  If you want to use a less global
> style,
> > try using a different scope identifier (but not "my").
> >
> > Justin
> >
> > -----Original Message-----
> > From: slhgkh5@attbi.com [mailto:slhgkh5@attbi.com]
> > Sent: Monday, February 25, 2002 10:15 AM
> > To: beginners@perl.org
> > Subject: Uninitialized Value Error
> >
> >
> > When I run the following script, I get the following
> > error.  Being new to perl, I am having trouble
> > identifying where the error is at.
> >
> > Thanks for your help.
> >
> > Error:
> > Use of uninitialized value at user_access1.pl line 43,
> > <F_ACCESS> chunk 29.
> >
> > Here is the code:
> >
> > #!/usr/bin/perl -w
> >
> > use strict;
> >
> > use constant PATH
> > => "/usr/local/scripts/security/sybase/user/";
> > use constant GROUPS => "group_files.doc";
> > use constant ACCESS => "user_access_all.doc";
> >
> > open F_GROUPS, PATH.GROUPS    or die "Can't open:  $!";
> >
> > while (<F_GROUPS>) {
> >     chomp(my @field = split /:/);
> >     my $field1 = $field[0];
> >     my $field2 = $field[1];
> >     my $field3 = $field[2];
> >
> >     open OUT, ">$field[1]"  or die "Can't open:  $!";
> >     open F_ACCESS, PATH.ACCESS    or die "Can't open:
> > $!";
> >
> >     while (<F_ACCESS>) {
> >         chomp ();
> >         my $user = $_;
> >         if (/$field[0]/) {
> >             write OUT;}
> >            }
> >     close OUT                   or die "Can't close:
> > $!";
> >     close F_ACCESS              or die "Can't close:
> > $!";
> >
> >
> > #unlink
> > glob "/usr/local/scripts/security/sybase/user/*.txt";
> > exit;
> > }
> >
> > format OUT_TOP =
> > |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> > |||||||||||
> >
> > Company Name
> > first column        second column               Third
> > Column
> > _____________________________________________________
> > ...
> > format OUT =
> > @<<<<<<<<<<<<<< @<<<<<<<<<<<<<< @<<<<<<<<<<<<<<
> > my $field1,          my $field2,                     my
> > $field3
> > ...


--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About