Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: How can I deal with those big table data?

by Trimbach (Curate)
on May 19, 2002 at 20:10 UTC ( [id://167700]=note: print w/replies, xml ) Need Help??


in reply to How can I deal with those big table data?

Besides lots of other weird things in your code, you're missing a closing bracket (}) for your do_hash sub.

Some other comments:

  • You're not doing anything at all my %MYHASH (it never gets populated) so the print in your while will never get executed.
  • my ($Name, $Data)=(split)[0,1]; is better written my ($Name, $Data)= split, 1;

Gary Blackburn
Trained Killer

Replies are listed 'Best First'.
Re: Re: How can I deal with those big table data?
by Anonymous Monk on May 19, 2002 at 21:02 UTC

    Thank you for your help!
    I am a beginner for perl, sorry for all my silly mistake!
    I need to read in two files, the first part works good.The second part,now I fixed a little bit, and test it, it can give me only one letter of the data, but my data should be the whole sequence, and my hash does not print out anything either. Please help!
    #!/usr/bin/perl -w
    use strict;
    my ($file_list, $file_data)=@ARGV;
    my %MYHASH;
    #create hash
    sub do_hash {
    my $filename=shift;
    open(FH, $filename) or die "Can't open $filename: $!\n";
    while(<FH>){
    my ($Name, $Data)=split,1;
    while (my ($key, $value)=each (%MYHASH)){
    rint $Name,"=>",$Data," ";
    }
    }
    close FH;
    }
    do_hash('file_data');
    exit;
      There's still nothing in %MYHASH. Yes, you're declaring scope for %MYHASH and everything but just because %MYHASH is declared doesn't mean anything is in it. You have to assign some value or another into it in order for a while to work. Until there's something in your hash your while will never get executed and nothing will get printed.

      You probably want something like this:

      #!/usr/bin/perl -w use strict; my ($file_list, $file_data)=@ARGV; my %MYHASH; #create hash sub do_hash { my $filename=shift; open(FH, $filename) or die "Can't open $filename: $!\n"; while(<FH>){ my ($Name, $Data)=split,2; $MYHASH{$Name} = $Data; } close FH; } do_hash('file_data'); foreach my $key (keys %MYHASH) { print "$key => $MYHASH{$key}\n"; } exit;
      Note the fact that %MYHASH is assigned a whole bunch 'o data from the file, and after do_hash is completed (and %MYHASH has stuff in it) THEN all the data is printed out. And BTW, it should've probably been split, 2 not split, 1.

      Gary Blackburn
      Trained Killer

        Thanks, You are right, I make it today.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2024-04-24 11:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found