RE: : Help with extracting text

From: Jim Halkyard (jim.halkyard_at_nectech.co.uk)
Date: 12/31/03


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



Relevant Pages

  • Re: Best computer PC/network inventory software
    ... Neither program does everything you want, but you can usually work around things that they don't - for example, creating a script and running that script remotely on all systems to add Asset Tag info. ... Automatically capture PC info over the network, ...
    (microsoft.public.windows.server.general)
  • Re: Video and perl
    ... I have been using your script to capture images from my webcam. ... When i run my serial script it uses 100% of my CPU. ...
    (perl.beginners)
  • Re: [PHP] ob_start: Capturing STDOUT and STDERR
    ... to capture the output of a shell script and place it into a log file. ... This will capture the output buffer until the shell terminates when the ...
    (php.general)
  • ob_start: Capturing STDOUT and STDERR
    ... to capture the output of a shell script and place it into a log file. ... This will capture the output buffer until the shell terminates when the ...
    (php.general)
  • Re: programmatically capture web page as internet archive (MHT)
    ... > set stream = message.GetStream ... >> We have some ASP pages on the corporate intranet that report various ... We would like to capture a snapshot of these ... >> each night about midnight by running a scheduled script. ...
    (microsoft.public.scripting.wsh)