Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^2: spliting a table into individual columns

by C_elegance (Initiate)
on Dec 21, 2007 at 13:29 UTC ( #658443=note: print w/replies, xml ) Need Help??

in reply to Re: spliting a table into individual columns
in thread spliting a table into individual columns

what I'm trying to do - it's to extract the data from the file that is not a table but arranged in 8 columns separated by space (which i can separate [split(' ',$_, 8)] the next step is to search "the type" array for certain information, select only those. from there- using id (different column) and the coordinates also different column, to fish that part of the data from another file containing many id with their data- including the ones i need so i want to find the type, select for this. then i have to select for other parameters in other columns in the same way, then match the id to the coordinates - hash (of start -end joined into one information by join subroutine, that will return the parameters as regular expression that can be matched)? search the other file for the same ids, select only those and then fish out the part of the data i need and select it before i go any further....

Replies are listed 'Best First'.
Re^3: spliting a table into individual columns
by naChoZ (Curate) on Dec 21, 2007 at 15:59 UTC

    As you are a beginner, I just wanted to point you to a valuable tool bundled right into perl, Data::Dumper. My pointing this out won't necessarily _solve_ your problem, but it will go a long way towards helping you _visualize_ it.

    All you need to do is put use Data::Dumper; in your script. Then you'll be able to use it to display the contents of your variables with a line like:

    print Dumper( $foo );

    So, you might use it in your script to display your @s array, or within your foreach loop to show the current value of your $line variable.

    Keep Data::Dumper in mind. It's helped me learn all sorts of things in perl because it makes it so easy to actually see what's happening in a script.


    Therapy is expensive. Popping bubble wrap is cheap. You choose.

Re^3: spliting a table into individual columns
by graff (Chancellor) on Dec 22, 2007 at 06:27 UTC
    i get: "Use of uninitialized value in concatenation (.) or string at line 22"

    ... the file ... is not a table but arranged in 8 columns separated by space...

    So, if you used the code as I posted it on the file that you describe, then yes, you would get that message about line 22 (the "print" statement) and no other output, because the split was based on /\t/ (as you had it in your original post), and with no tabs in the file, nothing would be assigned to $type. I gather you've gotten past that problem, and are moving on to the real job.

    But the rest of your description of the job is hard to follow. If you are having trouble working it out, you'll need to show us some sample data that will make it clear what you are trying to do. If you are using two or more input files, and trying to relate information across the files to get specific outputs, show us a few relevant lines from each input, and what the corresponding output should look like. Then show us the code you've tried so far.

    (Now that you've gotten past the issue of "splitting a table into individual columns", you might want this new information and question, about joining data from different inputs, to be the start of a new thread.)

      Thank you again for bothering with me, i don't know anyone, who knows Perl and i have an assignment to do. i don't know what are the rules of what's acceptable with asking questions on the fora... but I'm getting stuck on small things and can't move forward with bigger ones. I've managed to move pass this problem, but not much further than that.. as i was trying to organise other bits of my assignment. therefore i have a question, when you were a beginner, how did you cope, saved/organised your files? i've just realised that i have tones of files to go through at different stags of development and what worst, i've actually lost some bits, that were working... i find it so demoralising and would appreciate any helpful tips. thanks for now - will be back when next problem arises ... i.e. 5 min :)
        Don't be so hard on yourself, and don't panic. And don't get so wrapped up in self-pity that you ignore the suggestions being given. Programming is an intrinsically detail-oriented activity, so "getting stuck on little things" is a never-ending aspect of the job. Get used to it, and work on your skills for diagnosing, experimenting, and "reading the f***ing manual".

        (Yes, it is okay, and in fact highly recommended, to take an experimental approach to the questions and problems that come up when trying to write a program. It's the best way to learn, especially in areas where the documentation seems confusing or incomplete to you. Try things out and see what happens.)

        Don't just complain in general terms about how you aren't getting anywhere, because you can't get anywhere that way. Address the specific details that get in your way, and if you can't get past a particular problem, back up and look for another approach for accomplishing the overall task.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2019-02-17 10:35 GMT
Find Nodes?
    Voting Booth?
    I use postfix dereferencing ...

    Results (96 votes). Check out past polls.