Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: oh boy!

by ok (Beadle)
on Mar 27, 2001 at 02:37 UTC ( #67362=note: print w/replies, xml ) Need Help??


in reply to oh boy!

An example script to pull this data would be nice. Anyone up for the challenge?

Is that what the professor said?

Replies are listed 'Best First'.
Re: Re: oh boy!
by qball (Beadle) on Mar 27, 2001 at 02:44 UTC
    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
Node Status?
node history
Node Type: note [id://67362]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (2)
As of 2018-07-21 23:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (450 votes). Check out past polls.

    Notices?