Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2004
    Posts
    25

    Exclamation Unanswered: Global symbol $lockstatus

    When I run my script I get Error Global symbol "$lockstatus" requires explicit package name
    what I need to do that the print OUTFILE to print
    "$fields[6]:$fields[8]:$lockstatus\n";
    Surly the strict function causing the problem but I must use it.

    use strict;
    ........
    ........
    my $filecsv = "data.txt";
    open(ALLDATA,"<$filecsv") or die "open failed: $!\n";
    my @fields = ();

    while($_ = <ALLDATA> ) {
    @fields = split ':';
    my $D_system = lc($fields[0]);
    my($D_cust_1, $D_cust_2) = split(/\W/, lc($fields[1]));
    my($D_os_1, $D_os_2) = split(/\W/,lc($fields[4]));

    if(($fields[9]=~ /false/) || ($fields[7]=~ /false/)){
    my $lockstatus = "Locked";
    }
    else {
    my $lockstatus = "";
    }
    my $outfile = "$tmpdestdir\\$fields[1]\\$fields[4]\\$D_system";
    open(OUTFILE, ">>$outfile");
    print OUTFILE "$fields[6]:$fields[8]:$lockstatus\n";

    }
    close (ALLDATA);

  2. #2
    Join Date
    Jan 2004
    Location
    Germany
    Posts
    167
    You declare the variable $lockstatus within a if-else-block, so it is not known outside this block.

    Declare it before the block and it should run:
    Code:
    my $lockstatus = "";
    if(($fields[9]=~ /false/) || ($fields[7]=~ /false/)){
      $lockstatus = "Locked";
    }
    board.perl-community.de - The German Perl-Community

  3. #3
    Join Date
    Feb 2004
    Posts
    25
    Thank you.

Posting Permissions

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