in reply to Tutoring for beginner?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Tutoring for beginner?
by poj (Abbot) on Mar 07, 2015 at 16:41 UTC | |
poj | [reply] [d/l] |
by Halbird (Novice) on Mar 07, 2015 at 17:08 UTC | |
| [reply] |
by AppleFritter (Vicar) on Mar 07, 2015 at 17:41 UTC | |
It makes a difference because with the added quotes, you're splitting on a literal string rather than a regular expression. If you want to split along tab characters, then the following are equivalent:
But the following is not:
as that splits on a slash followed by a tab followed by another slash, rather than just a slash. Here's a quick demonstration that may be instructive:
This outputs:
EDIT: posting the above script converted tab characters to spaces in the __DATA__ section, so you'll have to change those back before running the script to get the correct output. | [reply] [d/l] [select] |
by Discipulus (Canon) on Mar 07, 2015 at 18:18 UTC | |
PS I was very newbie too and with no scientific background too: now I approach my problem with Perl with easy with the help of PerlMonks. welcome! L*
There are no rules, there are no thumbs.. Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS. | [reply] [d/l] |
|
Re^2: Tutoring for beginner?
by eyepopslikeamosquito (Archbishop) on Mar 08, 2015 at 00:01 UTC | |
Programs often start out small and evolve into more complex beasts. Not unlike species. First, to make it easier for others to run, here is my test file, Mammal.txt, with each field separated by a single TAB character:
Running my program below on this input file produces the following output: which has essentially the same data as yours but with minor (cosmetic) differences in formatting. I show below how I would have written your program. I hope that you find it useful and that it may serve as motivation for you for further study to improve your Perl skills.
That is a first cut only. You might like to think further about your input file format. For example, if you add more species properties (in addition to Latitude and Longitude) how easy would it be to adjust your program? Is the input file format convenient? I would at least think about a different input file format with named properties (so you can easily add new ones without affecting existing properties), and with fields separated by any white space rather than a TAB char (for convenience and to allow vertical whitespace alignment when editing), and with a comment character to allow you to comment out lines. For example: Of course, if you did that, your code would need to change in step ... which might be a useful training exercise. It would be good training for you to write the code to read the species properties file as a subroutine, taking a file name as input and returning an appropriate data structure of species properties as output. | [reply] [d/l] [select] |