Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re^3: "Global Symbol Requires Explicit Package Name" error

by kutsu (Priest)
on Aug 09, 2005 at 22:30 UTC ( #482454=note: print w/replies, xml ) Need Help??

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

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

Replies are listed 'Best First'.
Re^4: "Global Symbol Requires Explicit Package Name" error
by Portree (Novice) on Aug 09, 2005 at 22:54 UTC
    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.

      I'd bet you can't open the '//163.../query.txt' file (I don't work with windows much but shouldn't / be \ instead), as that uninitialized value means $newrow[2] has nothing in it (might try a print "@newrow", "\n"; or use Data::Dumper; print Dumper @newrow; to check).

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

        The '//ip-address/folder/file' format works fine for me, here. Just as with all backslashes in Windows filenames, Perl does the right thing. (Thank goodness FAT*/NTFS/etc. disallow '/'s in filenames.) I did get an error, however, if I didn't log in to the SAMBA server at my test IP address before running the script. So, that might be something to consider.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://482454]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2021-02-28 20:10 GMT
Find Nodes?
    Voting Booth?

    No recent polls found