Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Re: oh boy!

by qball (Beadle)
on Mar 27, 2001 at 02:44 UTC ( [id://67363]=note: print w/replies, xml ) Need Help??


in reply to Re: oh boy!
in thread oh boy!

urgh..it's not homework...here's my example script...please help...

#!/usr/bin/perl ##BILLING PROGRAM## use strict; my(@data,@data2); ##open needed files to use in program open(FILE, "../Counts/newdata.txt") or die "Can't open file: $!\n"; open(FILE2, "../Counts/info.csv") or die "Can't open file: $!\n"; ##throw files into arrays and define arrays chomp(@data = <FILE>); chomp(@data2 = <FILE2>); ##define hash my ($id,$name,$srid); my %keyhash = ( $id => { NAME => $name, SRID => $srid, CSV => [] } ); ##populate arrays: foreach ( @data ) { ##define variables my ($id,$name,$srid) = split /,/; # Add some error checking to make sure the # hash key $id does not already exist $keyhash{$id} = { NAME => $name, SRID => $srid, CSV => [], } } ##print unused ids from csv file print "\n\nUnused ids from csv file\n"; print "--------------------------\n"; foreach ( @data2 ) { my ($id,$name,$srid) = split /,/; # Warn and do nothing if a record is found for which the # $name is not already in %keyhash unless ( defined( $keyhash{$name} ) ) { warn "No such record $id!\n"; next; } push @{$keyhash{$id}{CSV}}, [ $name, $srid ]; } ##Finally, extract the number of records for each customer ##print column headers print "\n\n"; print "Customer #of docs\n"; print "-------------------------\n"; # A little something to get the plurality correct foreach ( keys %keyhash ) { my $num = @{$keyhash{$_}{CSV}}; printf "%s %d\n", $keyhash{$_}{NAME}, $num, } ##just formatting by adding a couple returns at the end of the printou +t print "\n\n"; ##my choice of data structures ( hashes instead of arrays ) is dependa +nt ##on how we want to use the data later. ##close files close (FILE); close (FILE2); ##exit program exit;


Here it is. Thanks for beating me up :) ..

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://67363]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-04-23 08:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found