in reply to "Global Symbol Requires Explicit Package Name" error

I'll elaborate a bit on his one more bug. Let's walk through your program ;)

use strict; use warnings; use win32::ole;
You should get used to write module names in the right case (here: Win32::OLE), or your programs will throw "module foo::bar not found in @INC..." errors if they are ever run on a case-sensitive file system.
my ($f_mfg_desk, $f_mfg_desk_output, $record,@wip_query, $wip_query, $ +opr_cd, @header, $header, %header, $x, $row, $row_array, @row_array, @rule_array, $ +BREAK, $year, $month, $day, $hour, $min, $sec, $run_time, $dtme, $local_outfile_timestamp, $remote_outfile_timestamp, $local_outfil +e_latest, $remote_outfile_web, $Oper_Cd, $Pick_Ref_Num, $Part_Id, @header_da +ta, $newrow, @newrow, $head);
ugh.
There's nothing wrong with globals if there are just a few and their use is justified. Blindly declaring all variables as globals begs for trouble. You should read about scoping.
# This gets the document from the server $f_mfg_desk = '//142.22.50.34/planning/logistics/programs/wip_query.tx +t';
This assigns a scalar and does not "get" anything. (cut & paste reduce problem fragment?)
... open (INFILE, '//163.10.50.33/planning/logistics/programs/chicago_wip_ +query.txt'); while (<INFILE>) { $record = $_; chomp($record); @newrow = split(/\t/,$record);
A good example of bad scoping. $record here is just used within the loop, so you'd better write that as
while (my $record = <INFILE>) {
Also, you are just using $record to chomp and split it, so after all your code would be smarter written
while (<INFILE>) { chomp; @newrow = split /\t/;
which is a bit shorter and more concise.
$header_data{$newrow[2]} = [$newrow[3], $newrow[4], $newrow[5], $n +ewrow[6], $newrow[7], $newrow[8], $newrow[9], $newrow[10], $newrow[11 +], $newrow[12], $newrow[13], $newrow[14], $newrow[15], $newrow[16], $ +newrow[17], $newrow[18]]; }
This also can be written with a bit less effort.
$header_data{$newrow[2]} = [@newrow[3..18]];


holli, /regexed monk/

Replies are listed 'Best First'.
Re^2: "Global Symbol Requires Explicit Package Name" error
by Portree (Novice) on Aug 09, 2005 at 21:03 UTC
    Hello All
    I have read over all of your comments, and I understand to an extent what you are saying. I am a lowly hacker trying to automate a report. Below is the updated code I have, but I am now getting a new error. Here is what I ultimately want to do, and if someone can point me to a straight forward source then I am happy to try as much on my own as I can.

    I have a tabe delimited file. I want to eliminate rows where the date in column "Cust Late Shp Dt" is greater than today. Then I want to sort the data by the same field. Then save the data and put it back in the same location as I got it from. Below is the code that I have so far, but if I need to start completely over I will, just so I can get this done. Once I have the template and understand it, I think I can then apply it to several other reports. Thank you in advance for all of your help.
    use strict; use warnings; use Win32::OLE; use Date::Calc; my ($f_mfg_desk, $f_mfg_desk_output, @wip_query, $opr_cd, @header, %header_data, @row_array, $BREAK, $Oper_Cd, @newrow, $start_time); # This gets the document from the server $f_mfg_desk = '//163.10.50.33/planning/logistics/programs/chicago_wip_ +query.txt'; @header = ("Oper_Cd","Pick_Ref_Num","Part_Id","Lot Qty","Order Id", "Order Lineitem Id","Order Lineline Id","Sublot Num", "Comm Invoice Num","Oper In Dt","Cust Early Shp Dt", "Cust Late Shp Dt","Current Date","Business Class Cd", "Action Expedite Flg","Required Ship Saleable", "Required Ship Inventory Transfer","Total Required Ships"); $start_time = time; open (INFILE, '//163.10.50.33/planning/logistics/programs/chicago_wip_ +query.txt'); while (<INFILE>) { chomp; @newrow = spli t /\t/; $header_data{$newrow[2]} = [$newrow[3..18]]; } close(INFILE)


    Once I have this done I then have figured out the email functionality and several other items that I need. The actual manipulation of the document is what eludes me right now. I know I am just at the start, defining the variables and getting the header information read into the program, so I understand I have a long ways to go.

    Oh, and I am using Activestate Komodo to write this program in, which is better than a free-ware I was using. Is this the best program for this type of activity, or is there one that is maybe a little more helpful in pointing out where an error is and how to fix it?

      I'd recommend you check out woolfy's Where and how to start learning Perl as there are some strange assumptions here, but a possible rewrite:

      use strict;
      use warnings; #good!
      use Win32::OLE;
      use Date::Calc; why load when you don't use it, or Win32::OLE?

      #having a few variable with a large lexical scope isn't #nessarily bad but in general use the smallest scope # This acutally assigns the file location to a scalar # doesn't get anything (as [holli] stated) my %header_data; my $f_mfg_desk = '//163.../chicago_wip_query.txt'; # Since you don't actually use @headers: I dropped it # If you needed it just say why and I'll go from there # "time" gives seconds after epoch which is proably not what you want, + see localtime* my ($sec, $min, $hour, $dayofmonth, $month, $year, $weekday, $day) = l +ocaltime(time); $month++; $year += 1900; open (INFILE, $f_mfg_desk); #if you do my $record = <INFILE> you'd need chomp($record);... or while (<INFILE>) { chomp; my @newrow = split /\t/; #missing the ]; here $header_data{$newrow[2]} = [ $newrow[3..18] ]; } close(INFILE); #to sort and reprint (proably want to copy a backup too) open (OUTFILE, ">$f_mfg_desk"); # see perldsc* and sort* for my $key (sort keys %header_data) { #see perlref* for @{} for my $a (@{$header_data{$key}}) { print OUTFILE "$a\t"; } print OUTFILE "\n"; }

      *:localtime, perldsc, sort, perlref

      "Cogito cogito ergo cogito sum - I think that I think, therefore I think that I am." Ambrose Bierce

        Hi Kutsu
        Thank you for the response, I really appreciate the time that you took to respond back. Some answers to your questions:

        I was using Date::Calc to get the current date and compare it to the date that I need to use as a cutoff for rows that I want to delete. If that is in error and I don't need it to do that, then I am fine to drop it.

        The next question, Win32::OLE, I have put that on as a standard to most of my programs, so I have to admit that was out of habit.

        Finally, even with your code, I still get an error uninitialized value in hash element..., and it points me to this section of code in line 29  $header_data{$newrow[2]} = [ $newrow[3..18] ];

        I appreciate the links to the documents, I will print those out and read them. Thank you very much again.
        Portree