shabird has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks! I have a file which i read and extract information from it, the file contents is as follows:
DATA Numbers five; Crystal; Reliable chromo; Onion; Apple; Salt. CHEM Synechocystis sp. PCC 6803 substr. Kazusa NAMES Synechocystis sp. PCC 6803 substr. Kazusa Bacteria; Cyanobacteria; Synechococcales; Merismopediaceae +; Synechocystis; unclassified Synechocystis.
I am extracting only DATA and its corresponding values. For this i wrote the following program.
open(FH, "/Users/Desktop/file.txt") or die; my $content = join("", <FH>); close(FH); my @matches = $content =~ /DATA\s+([A-Za-z\W]+)\n/g; print "Data:@matches\n";
Now everything works file but i want to use a subroutine for this task, where the subroutine takes as input argument the content of the file and returns all data (DATA) from the file. In the return argument only the DATA should be included and nothing else.
How can i achieve this? any inputs will be appreciated a lot :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Function for reading file
by hippo (Archbishop) on Mar 25, 2020 at 09:43 UTC | |
by shabird (Sexton) on Mar 25, 2020 at 09:54 UTC | |
|
Re: Function for reading file
by davido (Cardinal) on Mar 25, 2020 at 15:15 UTC | |
by shabird (Sexton) on Mar 28, 2020 at 13:11 UTC | |
by davido (Cardinal) on Mar 28, 2020 at 23:36 UTC | |
by AnomalousMonk (Archbishop) on Mar 29, 2020 at 01:42 UTC |