Thanks for assistance Rob. By adding the parentheses in the split I get the expected results. Yes I do need to cleanup the code. The lines that are indented are only for debugging, so I am going to delete them anyways. I will keep your suggestions in mind for my next post. Is commenting the closing brackets really a bad thing? I think it makes it easier for debugging. I don't have real comfort level yet with using hashes so I am sure I will have further questions.
-----Original Message----- From: Rob Dixon [mailto:[EMAIL PROTECTED] Sent: Monday, June 09, 2008 5:31 PM To: beginners@perl.org Cc: Johnson, Reginald (GTS) Subject: Re: splt and hash problem Johnson, Reginald (GTS) wrote: > > I am trying to split and entry from hash and keep getting the following > warning "Use of implicit split to @_ is deprecated at ./chargeback line > 34." > I'm not sure how to correct this. What I want the code to do is take the > input file and get a hash of the node names. I did this to eliminate > duplicates. > Then I use "if exist" to get the sumbytes for each node. My final > output should be the nodename and the total bytes for the node. > > I read the perldoc -f on split but it didn't give that "ahh" moment for > what I am doing wrong. > > My input > tsmpa1,2008-06-05 09:00:03.000000,2008-06-05 > 09:00:05.000000,BACKUP,35453,MPTELCLTS001,Tcp/Ip,,MPLTTALTS001_2HOUR,138 > ,2,0,400180,0,0,1,YES,,,,,0, > tsmpa1,2008-06-05 09:00:04.000000,2008-06-05 > 09:00:10.000000,BACKUP,35455,MPLTTALTS001,Tcp/Ip,,MPLTTALTS001_2HOUR,210 > 8,2,0,873337,1,0,1,YES,,,,,0, > tsmpa1,2008-06-05 10:00:23.000000,2008-06-05 12:20:01.000000,STGPOOL > BACKUP,295,DIR_DISK -> > DIR_COPY_TE,,,DIR_DISK_BKUP,36865,36865,0,60157952,0,25,1,YES,,,, > ,0, > tsmpa1,2008-06-05 10:26:36.000000,2008-06-05 > 10:29:37.000000,BACKUP,35696,MPLTTABUSADM01,Tcp/Ip,,,0,1,0,754280,0,0,1, > YES,,,,,180, > tsmpa1,2008-06-05 10:29:41.000000,2008-06-05 > 10:30:06.000000,BACKUP,35705,MPLTTABUSDAT02,Tcp/Ip,,,0,1,0,46088500,0,0, > 1,YES,,,,,22, > tsmpa1,2008-06-05 10:29:42.000000,2008-06-05 > 10:29:47.000000,BACKUP,35708,MPLTTABUSDAT10,Tcp/Ip,,,0,1,0,47606106,0,0, > 1,YES,,,,,3, > tsmpa1,2008-06-05 10:29:42.000000,2008-06-05 > 10:29:58.000000,BACKUP,35707,MPLTTABUSDAT01,Tcp/Ip,,,0,1,0,45704386,0,0, > 1,YES,,,,,14, > tsmpa1,2008-06-05 10:29:42.000000,2008-06-05 > 10:29:58.000000,BACKUP,35709,MPLTTABUSDAT01,Tcp/Ip,,,0,1,0,46011159,1,0, > 1,YES,,,,,13, > tsmpa1,2008-06-05 10:29:42.000000,2008-06-05 > 10:30:04.000000,BACKUP,35711,MPLTTABUSDAT04,Tcp/Ip,,,0,1,0,46056905,0,0, > 1,YES,,,,,19, > tsmpa1,2008-06-05 10:29:42.000000,2008-06-05 > 10:30:04.000000,BACKUP,35706,MPLTTABUSDAT05,Tcp/Ip,,,0,1,0,56903405,0,0, > 1,YES,,,,,20, > tsmpa1,2008-06-05 10:29:42.000000,2008-06-05 > 10:30:05.000000,BACKUP,35710,MPLTTABUSDAT09,Tcp/Ip,,,0,1,0,45471886,1,0, > 1,YES,,,,,20, > tsmpa1,2008-06-05 10:29:43.000000,2008-06-05 > 10:29:58.000000,BACKUP,35725,MPLTTABUSDAT03,Tcp/Ip,,,0,1,0,46047982,2,0, > 1,YES,,,,,10, > tsmpa1,2008-06-05 10:29:43.000000,2008-06-05 > 10:29:59.000000,BACKUP,35722,MPLTTABUSDAT09,Tcp/Ip,,,0,1,0,45182840,2,0, > 1,YES,,,,,13, > tsmpa1,2008-06-05 10:29:43.000000,2008-06-05 > 10:30:00.000000,BACKUP,35714,MPLTTABUSDAT09,Tcp/Ip,,,0,1,0,46098890,0,0, > 1,YES,,,,,15, > tsmpa1,2008-06-05 10:29:43.000000,2008-06-05 > 10:30:01.000000,BACKUP,35726,MPLTTABUSDAT03,Tcp/Ip,,,0,1,0,46155077,0,0, > 1,YES,,,,,14, > ~ > Code > > #!/usr/bin/perl > use strict; > use warnings; > > &open_files; > #*********************************************************************** > ******** > sub open_files { > open(SUMMARY, "<", "/home/johnsre/sum_file" ) or > die "Summary file could not be opened: $!"; > my %nodename_Hash=(); > my $total_for_node = 0; > while (<SUMMARY>) { > my ($sumdate,$sumactivity,$sumnode,$sumbytes) = (split > /,/)[1,3,5,12]; > print "$sumdate,$sumactivity,$sumnode,$sumbytes\n"; > chomp($sumnode); > $nodename_Hash{ $sumnode} = "$sumnode,$total_for_node"; > } #end while > my ($key,$value); > for $key (keys %nodename_Hash) { > $value = $nodename_Hash{$key}; > print "$key => $value\n" > }#for > close(SUMMARY); > open(SUMMARY, "<", "/home/johnsre/sum_file" ) or > die "Summary file could not be opened: $!"; > my $temp_value=0; > while (<SUMMARY>) { > my $temp_node; > my ($sumdate,$sumactivity,$sumnode,$sumbytes) = (split > /,/)[1,3,5,12]; > if (exists $nodename_Hash{$sumnode} ) { > my $line; > $line=$nodename_Hash{$sumnode}; > # > $temp_node,$temp_value=split(/,/,$nodename_Hash{$sumnode}); > $temp_node,$temp_value=split(/,/, $line); > print "$sumnode exists sumbytes=$sumbytes > temp_value=$temp_value temp_node=$temp_value $line\n"; > my $new_bytes=0; > $new_bytes =$temp_value+$sumbytes; > $nodename_Hash{$sumnode}= "$sumnode,$new_bytes"; > } > } #end while > for $key (keys %nodename_Hash) { > $value = $nodename_Hash{$key}; > print "$key => $value\n" > }#for > > > close(SUMMARY); > } #close summary There are a few problems with your code, but the error is because the line $temp_node,$temp_value=split(/,/, $line); should read ($temp_node,$temp_value) = split(/,/, $line); It is hard to know how to improve what you ahve written as you have several variables that are unused, and the subroutine is clearly unfinished. But I would suggest the following: - You subroutine open_files() is way too long - It doesn't open files - it opens one file, twice, and reads the data - Your indenting needs looking at - you shouldn't need to comment closing braces - Try to declare variables closer to where they are used. For instance my ($key,$value); for $key (keys %nodename_Hash) { $value = $nodename_Hash{$key}; print "$key => $value\n" }#for should be for my $key (keys %nodename_Hash) { my $value = $nodename_Hash{$key}; print "$key => $value\n" } Once you have tidied your code a little I'm sure we will be able to help you further. HTH, Rob -------------------------------------------------------- This message w/attachments (message) may be privileged, confidential or proprietary, and if you are not an intended recipient, please notify the sender, do not use or share it and delete it. Unless specifically indicated, this message is not an offer to sell or a solicitation of any investment products or other financial product or service, an official confirmation of any transaction, or an official statement of Merrill Lynch. Subject to applicable law, Merrill Lynch may monitor, review and retain e-communications (EC) traveling through its networks/systems. The laws of the country of each sender/recipient may impact the handling of EC, and EC may be archived, supervised and produced in countries other than the country in which you are located. This message cannot be guaranteed to be secure or error-free. This message is subject to terms available at the following link: http://www.ml.com/e-communications_terms/. By messaging with Merrill Lynch you consent to the foregoing. -------------------------------------------------------- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/