Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

How can I deal with those big table data?

by Anonymous Monk
on May 19, 2002 at 19:54 UTC ( #167695=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear All,

I am trying to make a hash using a table data, the data part is really big:

#!/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)[0,1]; while (my ($key, $value)=each (%MYHASH)){ print "$Name=>$Data, ";} } } do_hash('file_data'); close FH; exit;
and my data looks like: 38x11     N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N T - C T T C - - - G T G - A A A - C C T C T G C T G G A A T A C A C A C A C G C T C A G T A C A C T A G T T G G T A C A T G A A T C T A A T G A A G T C A G G G A A A G A G T A C T A A T T T T C G C G A G T A A A G G G A A G G C T G G A T C C T T T T T A G G C C C G T T C C A A T C T C G C G A G A T A A A C T T T A G C A G C T T T T T T T A A G C T A C T T T T A G C T A T T T G T A A T C T A A A C A G G A G A T C T A A T T G T G A T A A T T G A A G T T A A A C T T T A G C A C T T T A A T T C A T A T A G C T A A A G T T T A G C A G G A A G C T A A A G T T T ....
when I run it, it gives me:
"Bareword found where operator expected at dsilk_data line 1, near "11 N"
(Missing operator before N?)"
What does it mean and how can i get rid of it?

Edit by tye

Replies are listed 'Best First'.
Re: How can I deal with those big table data?
by Trimbach (Curate) on May 19, 2002 at 20:10 UTC
    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


      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

Re: How can I deal with those big table data?
by graff (Chancellor) on May 19, 2002 at 20:18 UTC
    The error message makes it look as though the data is part of the script file. Is it?

    What is "$file_list" for? Why do you have it this value as a command line arg when it isn't used in the script?

    Why do you open a file handle in a subroutine, but then close it in "main" (why not close it in the subroutine, too?)

    If the script file does not contain a __DATA__ portion, and the data you mention is actually in another file, have you tried checking the syntax of the script by itself first, without running it on the data? Like so:

    perl -cw your_script.pl
    Is that "bareword" complaint really the only thing that comes out when you try to run it? (Are there no other errors?)

    Try to get your indentation right -- any good editor should make this easy, and it will help.


      Thank you for your help! BR>I am a beginner for perl, sorry for all my silly mistake! You are right. I need to read in two files, the first part
      works good, the second part does not work. 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;

        Okay, nice to hear things are improving. Now, regarding this line:
        my ($Name, $Data)=split,1;
        You need to look at "perldoc -f split", because the above is probably not doing what you intend. You also need to make sure that your reading logic matches the structure of the input file.

        I think what you're intending there is something like:

        my ($Name, $Data) = split( /\s+/, $_, 1 );
        which means that, even though the line contains lots of space-separated tokens, just the first space on each line will be split, the part before it becomes $Name, and everything after it becomes $Data.
Re: How can I deal with those big table data?
by DamnDirtyApe (Curate) on May 19, 2002 at 20:16 UTC

    Could you please post a sample of the data you are trying to process? It's rather tough to fix what's coming out without knowing what's going in. :-)


    _______________
    D a m n D i r t y A p e
    Home Node | Email

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2021-12-09 08:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (36 votes). Check out past polls.

    Notices?