ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I always need to print out the 8th field. So in this case donkey. Here is what I have so far:
Code:
#!/usr/bin/perl
use strict;
use warnings;
open (F, "data.pl") || die "Could not open data.pl: $!\n";
my @test = <F>;
close F;
my @values = split('|', @test);
foreach my $val (@values) {
print "$val\n";
}
exit 0;
Even more specifically, did you carefully line #4 of 'perldoc -f split' ?
In my case the line is:
Code:
4 split Splits the string EXPR into a list of strings and returns that list. By default, empty leading fields are preserved, and empty trailing ones are deleted.
5 (If all fields are empty, they are considered to be trailing.)
Last edited by Sergei Steshenko; 05-17-2010 at 05:09 PM.
When I run that script on the data that I provided I only get the number 4. I want it to display donkey, because it is the 8th spot. I need this to run on a file full of patterns like the one I provided. I did read through the perldoc, just not understanding it.
When I run that script on the data that I provided I only get the number 4. I want it to display donkey, because it is the 8th spot. I need this to run on a file full of patterns like the one I provided. I did read through the perldoc, just not understanding it.
Tarken
No, it's not that you do not understand 'perldoc', it is that you do not analyze the text properly.
So, here is a simpler task for you - first an English sentence to be analyzed:
Jack climbs a high mountain.
The sentence in italics contains the following items:
an entity performing an action;
an entity describing the action;
an entity over/on which the action is performed.
So, first of all, which are the three entities ?
Last edited by Sergei Steshenko; 05-17-2010 at 08:21 PM.
Good (almost). Though, strictly saying, not "the man", but "Jack", and not "climbing", but "climbs". Now, what kind/type of mountain the man climbs ?
And after answering that question perform the same analysis of already quoted here
Code:
4 split Splits the string EXPR into a list of strings and returns that list. By default, empty leading fields are preserved, and empty trailing ones are deleted.
line, including answer to the
what kind of the entity on/over which the action is performed ?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.