>>>>> "AG" == Agnello George <agnello.dso...@gmail.com> writes:

  AG> use strict;

  AG> my $filename = $ARGV[0];

  AG> my (%tag,$dkey,$dval);

you don't use $dkey or $dval anywhere.

  AG> open(INPUT_FILE, $filename)  or die "cannot opnen file $!";

don't use bareword filehandles. this is said all the time here. use
lexical handles.

  AG> while (<INPUT_FILE>) {
  AG>   m/(\d+)\s+(\d+)$/;

you don't check if that regex succeeds or not.

and just for fun here is a one liner that works:

perl -MFile::Slurp -e '/(\d+)\s+(\d+)/ && push @{$h{$1}}, $2 for read_file 
\*STDIN; print map "$_ => @{$h{$_}}\n", sort keys %h'
1 2
3 4
1 9
4 8
3 00
2 4
27
1 4
1 => 2 9 4
2 => 4
3 => 4 00
4 => 8


input was ended with ^D.

i used file::slurp as that is best when reading from a file. it isn't
needed here as STDIN is already open.

uri

-- 
Uri Guttman  ------  u...@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to