in reply to Re^2: "Global Symbol Requires Explicit Package Name" error
in thread "Global Symbol Requires Explicit Package Name" error

Hello All
OK a few questions to help me understand. In my code below (as is familiar already) I have sections of the code that I have used, but I am really not quite sure what they do. I have played around with it and if someone could help me to understand better I would appreciate it.

I have buried my questions in the code below, removing all comments that were there already, that way my questions are clear. Thanks again for the help

Portree
use strict; use warnings; #good! use Win32::OLE; use Date::Calc; use diagnostics; my %header_data; my $f_mfg_desk = '//163.10.50.33/planning/logistics/programs/chicago_w +ip_query2.txt'; my $f_mfg_desk2 = '//163.10.50.33/planning/logistics/programs/chicago_ +wip_query3.txt'; my ($sec, $min, $hour, $dayofmonth, $month, $year, $weekday, $day) = l +ocaltime(time); $month++; $year += 1900; open (INFILE, $f_mfg_desk); ($record);... or while (<INFILE>) { chomp; my @newrow = split /\t/; # What does this below statement acutally mean? $header_data{$newrow[2]} = [ $newrow[3..18] ]; } close(INFILE); open (OUTFILE, ">$f_mfg_desk2"); # If I am sorting by this data, why does it delelte most of # the data +? # Which data field is actually being used to sort? for my $key (sort keys %header_data) { for my $a (@{$header_data{$key}}) { print OUTFILE "$a\t"; } print OUTFILE "\n"; }

Replies are listed 'Best First'.
Re^4: "Global Symbol Requires Explicit Package Name" error
by runrig (Abbot) on Aug 10, 2005 at 21:48 UTC
    # What does this below statement acutally mean? $header_data{$newrow[2]} = [ $newrow[3..18] ];

    You are creating an array of the 4th through 19th elements of the @newrow array and associating it to the 3rd element of @newrow in the %header_data hash array (i.e. you are using the 3rd element as a key and setting the value to a reference to an array of the 4th through 19th elements -- remember arrays start at index zero).

    If there are duplicates of the 3rd elements in the data, then only the last row will be saved (maybe that's why you're "losing data"?).

    # Which data field is actually being used to sort? for my $key (sort keys %header_data)
    Each 3rd element that came from @newrow above.
Re^4: "Global Symbol Requires Explicit Package Name" error
by Portree (Novice) on Aug 10, 2005 at 22:58 UTC
    Hi Kutsu

    I couldn't reply on your thread so I thought I would just add to this one. I can actually open the file, so that is not a problem. The problem is totally in my lack of understanding on how the process works and gettng a bit of information here and there. I am a visual basic programmer, so Perl is very new to me and doesn't always seem as logical.

    For instance, these are the values that are at the top row of my tab delimited file (if you think of it as an Excel spreadsheet this is line one):

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

    I want to sort the data on the file by "Cust Late Shp Dt" (Bold Highlight). Then I want to eliminate all rows of data where the the date is greater than today's date (such as tomorrow or the next day). In VB this is a very easy task, but this alludes me in Perl.

    I have read the document on sorting, but to me it is not clear as to what is the proper code to use to sort by one segment of a header file. If someone could please explain this in plain english (I know, I am still learning the jargon of Perl) then I would be extremely grateful.

    Portree
Re^4: "Global Symbol Requires Explicit Package Name" error
by Portree (Novice) on Aug 11, 2005 at 16:19 UTC
    Hi runrig,
    Thanks for stoping by. If you don't mind, could I ask another question. You have said that you understand why I am loosing data. How do I prevent this? How do I take a header element and just sort by it without loosing my data? I have read all of the documentation that I can get my hands on but I just can't get it to work. I need to delete whole rows with certain data, and then sort the rest. Can you assist?

    Regards
    Portree
      I don't understand why you are losing data, I'm just guessing at the reason why you think you are losing data. If I'm right, then maybe you shouldn't be using a hash array, maybe you should just be using a regular array (of arrays), and then you can just sort on the element that you're currently putting in the key of the hash arrays. But since I'm not sure what you're trying to accomplish in the end, I can't be sure. Posting a small but complete example of what you're trying to do would help, instead of posting something that opens files with data that we can't see. You can post examples of reading in data using the DATA handle, e.g.:
      my @lines; while (<DATA> { my @array = split; # Don't save first two fields push @lines, [ @array[2..5] ]; } # Sort 3 field from input for my $line (sort { $a->[0] cmp $b->[0] } @lines) { for my $value (@$line) { print "$value\t"; } print "\n"; } __DATA__ a b c d e f a b c d e f g h i j k l