Let me ask for forgiveness right from the get-go. I am a newbie to Perl and found that it would be a beneficial tool for my line of profession and I am trying to teach myself with on-line resources.
My question to the community, and I've seen variations on what I am trying to achieve, is the following scenario:
I have a comma-delimited text file (metadata_output.txt) saved in a given directory (eg \usr\home\project\dump)
The format has for argument's sake, 4 fields:
ssnumb, name_last, name_first, ratios
I now want to open the file and have my script go through each entry line by line and print only the 4th "ratio"field or [3].
Up to this point I have seen variations on how to do this. such as:
-
#!/usr/home/bin/perl
-
use strict;
-
use warnings;
-
-
open(META, "<\usr\home\project\dump\metadata_output.txt>"
-
-
while(<META>)
-
-
{
-
chomp($_);
-
my @line = split(/,/, $_);
-
-
print ("line[3]\n");
-
-
}
-
What I am seeking is a way of :
1) taking these outputed fields parsed from the original metadata_output.txt file and create an entirely NEW file (eg. new_file.txt)with this stripped out data to keep my original data untouched.
2) Is it possible with a sub query within the same script to perform mySQL-like functions such as padding the new_file.txt's records to conform to a standard pattern.
eg. my new file would have the following record examples for its sole ratio field :
12/12/12
3:3
0:0/1
33:33:34
Is it then possible to have it do something like a RTrim? but have it recognize that it is to take only up to the first two integers and stop when arriving at non-integer character?
Of course all of this would be overwriting the new_file.txt which I would then like to append as a new field in original metadata_output.txt
Comments ./ direction would be appreciated.
Nick