RE: : Help with extracting text
From: Jim Halkyard (jim.halkyard_at_nectech.co.uk)
Date: 12/31/03
- Next message: Deb: "scripted piped system commands"
- Previous message: William Martell: "RE:: Help with extracting text"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To: "'William Martell'" <willmartell@yahoo.com>, beginners@perl.org, Zary Necheva <znecheva@mail.pratt.lib.md.us> Date: Wed, 31 Dec 2003 15:07:38 -0000
Hi Will,
Just a couple of comments on the script you sent.
This is your script with some minor changes.
$infile = "zary_necheva_data.txt";
open(INFILE, $infile) or die "Death $!";
while( $line = <INFILE> ){
$lpos = index($line,"|");
# Your line will capture the first five chars, but in the sample data 2 of
the rows had 6 chars before the first . or space and were truncated
#$first = substr($line, 0, 5); # Will's line
# I suggest using the value of $lpos you captured above
$first = substr($line, 0, $lpos); # My line
# This will replace one or more dots with nothing within the substring, not
quite what was requested
#$first =~ s/\.+//; # Will's line
# This will replace everything after the first dot or space in the substring
with nothing
$first =~ s/[\.\s].*//; # My line
$last = substr($line, $lpos);
print $first.$last;
}
You can also replace the while loop with
while(<INFILE>)
s/^(.*?)[\.\s].*?(\|.*)$/$1$2/;
print;
}
I am sure there are many other ways of doing this, many of them probably
shorter, quicker code, but both these appear to work exactly as requested.
Cheers,
Jim
-----Original Message-----
From: William Martell [mailto:willmartell@yahoo.com]
Sent: 31 December 2003 14:33
To: beginners@perl.org; Zary Necheva
Subject: RE:: Help with extracting text
Hi Zary,
I have attached a sample file with the data you offered and a perl script
which can be copied and pasted into the command line on win32.
Let me know if you have any problems.
HTH,
Will Martell
Dallas Texas
- Next message: Deb: "scripted piped system commands"
- Previous message: William Martell: "RE:: Help with extracting text"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|