Wizards,
I'm trying to borrow a page from perl.com's "Perl Slurp-Eze" piece by Guttman (http://www.perl.com/lpt/a/2003/11/21/slurp.html). What I'm trying to do is adapt the following for my data:
my $text = read_file( $file );
my %config = $text =~ /^(\w+)=(.+)$/mg;
my data files consist of a header block of comments, followed by data lines (text followed by zero or more blanks, a '|' separator, and a number), followed by POD documentation (here's an abbreviated sample):
################################################################################
# - Copyright 2004, 2005, 2006 All Rights Reserved #
# #
# Name : AP_Tags_XP.lst #
# #
# Description : This is the tag (key/value set) file used by the project's #
# HTML-file update script for Windows XP machines only. #
# #
# . . . #
################################################################################
Date Column Updated |0
Software Release Number |1
Windows Type-Version (Build) |2
Service Pack |3
Anybodys Software – SomeProgram.exe |4
# Multiple labels for line 5:
ActiveState Tool Corp. - ActivePerl |5
ActiveState, a division of Sophos - ActivePerl |5
=pod
=head1
And here's the code I'm trying to use:
use strict;
use File::Slurp;
my $key_file = 'AP_Tags_XP.lst';
open my $LOG, '>', 'tsthash3.log';
my $text_of_file = read_file( $key_file );
print $LOG "--------------------------------------------------------------\n";
print $LOG "$text_of_file\n";
print $LOG "--------------------------------------------------------------\n\n";
my %key = $text_of_file =~ /^([\w|\s]+[\w])\s*\|(\d+)$/mg;
my $x = scalar( %key );
my $y = keys( %key );
print $LOG "for hash \%key: scalar = $x ($y elements)\n\n";
foreach my $k (sort {$key{$a} <=> $key{$b}} keys %key) {
print $LOG "$k: $key{$k}\n";
}
The dump of $text_of_file shows that the file read in fine, but I get 0 for the scalar(%key) and 0 for keys(%key). What am I doing wrong, anybody know? If it helps, each line in the dump ends in a 0x0d (little musical note) character...
Thanks,
Deane
_______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
