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

RE: Uninitialized Value Error

Thread Previous | Thread Next
Timothy Johnson
February 25, 2002 13:27
RE: Uninitialized Value Error
Message ID:

Getting rid of 'my' is not your only option.  Among other things, you can
put the code for getting info from filehandles in a subroutine and pass the
variable by reference or return the value so that you can still have it to
use for your format command.

Example 1:
my $var;
$var = &mysub($var);
do something with $var...

sub mysub{
   $subvar = $_[0];  #$subvar now has the value of $var
   do something...
   return $subvar;   #$var will now have the value of $subvar

Example 2:
my $var;

sub mysub{
   do something to ${$_[0]};   #dereference the first argument

-----Original Message-----
From: Lyon, Justin []
Sent: Monday, February 25, 2002 12:53 PM
Subject: RE: Uninitialized Value Error

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


-----Original Message-----
From: []
Sent: Monday, February 25, 2002 10:15 AM
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.

Use of uninitialized value at 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:  
glob "/usr/local/scripts/security/sybase/user/*.txt";

format OUT_TOP =

Company Name
first column        second column               Third 
format OUT =
@<<<<<<<<<<<<<< @<<<<<<<<<<<<<< @<<<<<<<<<<<<<<
my $field1,          my $field2,                     my 

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

This email may contain confidential and privileged 
material for the sole use of the intended recipient. 
If you are not the intended recipient, please contact 
the sender and delete all copies.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About