Nick Chettle <mailto:[EMAIL PROTECTED]> wrote:
: Charles wrote: : Thanks for the help, but neither of the examples you gave seem to : work. <scolding> First thing. Stop replying to a post by placing all you comments at the top of the post. It is annoying and requires I do extra work (mainly scrolling up and down) to help you. I'm doing this for free. Stop thinking of yourself and what is convenient for you. Notice how I place my comments under the relevant parts of your message. I did the same thing last time. See how much easier it is to find the problem with the code in question right above the question? It is important to delete unneeded sections of the last message to cut down on bandwidth and ease reading. </scolding> : : #!/usr/bin/perl : : : : use strict; : : use warnings; : : : : print "Please enter an e-mail address: "; : : chomp( my $email = <STDIN> ); : : : : my $file = '/var/log/maillog'; : : open MAILLOG, $file or die qq(Cannot open "$file": $!); : : : : my %msgids; # <<<------- TYPO : : while (<MAILLOG>) { : : if (/$email/) { : : if (/([A-Z1-9]{8})/) { : : push @{ $msgids->{$1} }, $_; : : } : : } : : } : : : : close MAILLOG; : : : : foreach my $key (sort keys %{ $msgids } ) { : : print $msgids->{ $key }; : : } : : : : __END__ : The first errors with: : % ./1 : Global symbol "$msgids" requires explicit package name at ./1 line 15. : Execution of ./1 aborted due to compilation errors. There's a typo up there. It was written correctly in the example where I explained the code. The following will correct things. my $msgids; : : #!/usr/bin/perl : : : : use strict; : : use warnings; : : : : print "Please enter an e-mail address: "; : : chomp( my $email = <STDIN> ); : : : : my $file = '/var/log/maillog'; : : open MAILLOG, $file or die qq(Cannot open "$file": $!); : : : : my %msgids; : : while (<MAILLOG>) { : : if (/$email/) { : : if (/([A-Z1-9]{8})/) { : : push @{ $msgids{$1} }, $_; : : } : : } : : } : : : : close MAILLOG; : : : : foreach my $key (sort keys %msgids) { : : print $msgids{ $key }; : : } : : : : __END__ : : The second errors with: : : % ./2 : Please enter an e-mail address: [EMAIL PROTECTED] : ARRAY(0x8064318) : % That's not an error. You asked perl to print array references out and ARRAY(0x8064318) is an array reference. Did you read 'perlref' like I suggested? The Dumper() function may aid you in visualizing what a hash of arrays looks like. use Data::Dumper 'Dumper'; print Dumper \%msgids; : I've been thinking about it an wondering if it needs to be this : complex. Can't I just create a hash (With the message ID as the key) : and the line as data? I tried: Only if the message ids are unique. I have no idea what a mail log looks like, so I don't know if they are unique. my %msgids; while ( <MAILLOG> ) { if ( /$email/ && /([A-Z1-9]{8})/ { $msgids{$1} = $_; } } HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>