Fellow monks,
Having used __DATA__ at the bottom of scripts for a while, I'm a bit frustrated. Instead of reading the <DATA> filehandle in the main:: package, I am wanting to read it in the current package (in this case package States, but I'm struggling with having it read even a single line of __DATA__.
While searching for information on this topic, I often came across code snipplets that read from this special filehandle in other packages. I'm not planning on changing the data anytime soon, so I'd rather just read it from the bottom of my object declaration.
Here is what I have so far:
######################## FILE 1 ####################### use strict; use warnings; use States; my $s = States->new(); ######################## FILE 2 ####################### package States; use CGI qw(:standard); use strict; use warnings; use Switch; use diagnostics; sub new { my ($class) = @_; print "Hello\n"; my @states; while (<DATA>) { chomp; print "$_\n"; # only for debugging purposes # prints nothing currently my ($code, $abbr, $proper, $state) = split /\t+/; push @states, { CODE => $code, ABBR => $abbr, PROPER => $proper, STATE => $state, } } return bless \@states; } 1; __DATA__ 01 AL 1 Alabama 50 AK 1 Alaska 02 AZ 1 Arizona 03 AR 1 Arkansas 04 CA 1 California 05 CO 1 Colorado 06 CT 1 Connecticut 07 DE 1 Delaware
I'm using v5.8.0 on Solaris 9. The output is the following (printed from the constructor, only for debugging reasons):
Hello
Any thoughts?
In reply to problems with reading __DATA__ from current package by perlguy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |