Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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

by graff (Chancellor)
on May 19, 2002 at 20:18 UTC ( [id://167704]=note: print w/replies, xml ) Need Help??


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

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.

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

    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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-04-19 20:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found