Expand|Select|Wrap|Line Numbers
- ### Load and parse a datafile, slurping the contents into the %pool hash
- sub LoadDataFile {
- my $file = shift;
- $file = SafeFile( $file ) if $cgi_mode;
- open IN, $file or die "Error opening $file... $!\n";
- local $/ = '';
- SECTION: while( <IN> ) {
- my( @temp ) = split /\n/, $_;
- my $key = shift @temp;
- $pool{$key} = [ @temp ];
- }
- close IN;
- }
Expand|Select|Wrap|Line Numbers
- my( @temp ) = split /\n/, $_;
Expand|Select|Wrap|Line Numbers
- my $key = shift @temp;
Expand|Select|Wrap|Line Numbers
- $pool{$key} = [ @temp ];
What would helpme is a way to look at the contents of $pool after the while loop is done, but I don't know how to do that in perl. print $pool; doesn't work.
While this function works fine in the whole scipt, I tried to put it in a separate file to examine how it works. So my whole file would be
Expand|Select|Wrap|Line Numbers
- #!/usr/bin/perl
- use strict;
- use CGI;
- my $q = new CGI;
- open(INFILE, "test.data") or die "Can't open input.txt: $!";
- # print header and start the markup output
- print $q->header( "text/html" ),$q->start_html( "hello from perl cgi!" );
- while (<INFILE>) { # assigns each line in turn to $_
- print $q->p("Just read in this line: $_");
- my( @temp ) = split /\n/, $_;
- print $q->strong("temp = @temp<br />");
- my $key = shift @temp;
- print $q->strong("key = $key<br />");
- #$pool{$key} = [ @temp ];
- }
- print $q->end_html;
I hope anybody roughly understands what I mean and what I'd like to know. I know my english is bad and so it's very hard to write about a script language that I don't understand either ;-)