Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regex subroutine/files in dir

Status
Not open for further replies.

Neomalfoy

Programmer
Jan 2, 2004
14
US
I have two problems

a) I am trying to apply a subroutine to each file in a dir, and the subroutine only prints the result for the first file in the dir for all the files.

rfiles/msg00068.txt Location: TX Title: Analog IC Engineer - PLL BiCMOS Salary: $90k - $135 + bonus + stock opt's
rfiles/msg00069.txt Location: TX Title: Analog IC Engineer - PLL BiCMOS Salary: $90k - $135 + bonus + stock opt's
..... etc.

I Know that TX etc. is not the same value for all the files.

b) In the subroutine I am using a switch contruct so that if the first regex doesn't find anything, goto the second etc. This isn't working how I expected it to and my default which should print no match if the different regexs find nothing, doesn't happen. I tested the switch subroutines using one file at a time, and sometimes it works and other times it doesn't, I know the regexs work because if I try matching with the regex patterns that apply only to a particular file, I get the data I want. But since the pattern will be different in several files, I tried the switch structure.

I need help on how to fix this script. Thanks.

#!/usr/bin/perl
sub location{
local($result) = '';
print " Location: ";
SWITCH: {
# location match 1
(~ /(\_\_subject\_\_\:\s(US\s|US)\-\s(\w\w)\s(.*|\-\s(.*))\n)/ig) && do{
$result = $3;
print "$result ";
last SWITCH;
};
# location match 2
(~ /((Location\:|Location)\s+((.*)*)\n)/g) && do{
$result = $3;
print "$result ";
last SWITCH;
};

# location match 3
(~ /(\_\_subject\_\_\:\s)((\w+\s)*)/ig) && do{
$result = $2;
print "$result ";
last SWITCH;
};

print "no match ";
} # end of CASE block
}
sub title{
local($result) = '';
print " Title: ";
SWITCH: {
# title match 1
(~ /((title\:|title)\s+(.*))\n/ig) && do{
$result = $3;
print "$result ";
last SWITCH;
};
# title match 2
(~ /(\_\_subject\_\_\:\s(.*)\n)/ig) && do{
$result = $2;
print "$result ";
last SWITCH;
};

print "no match ";
} # end of CASE block
}

sub salary{
local($result) = '';
print " Salary: ";
SWITCH: {
# salary match 1
(~ /((salary\srange\:|salary\:|salary)\s+(\$\d.*))\n/ig) && do{
$result = $3;
print "$result ";
last SWITCH;
};
# salary match 2
(~ /(^(salary\srange\:|salary\:|salary)\s+.+(\$\d.*))\n/ig) && do{
$result = $2;
print "$result ";
last SWITCH;
};
# salary match 3
(~ /(salary\s\-\s).+(\$\d.*)/ig) && do{
$result = $2;
print "$result ";
last SWITCH;
};

print "no match";
} # end of CASE block
}

my $dir = 'rfiles';
my $pattern = '.txt$';
#Filenames ending in .txt
opendir DIR, $dir or die "Cannot readdir $dir:$!\n";
my @files = grep /$pattern/,(readdir DIR);
closedir DIR;
for (@files) {
my $file = "$dir/$_";
open IN, $file or die "Cannot open $file:$!\n";

while (<IN>) {
# do stuff with the contents of $file
$text .= $_; #reads the text and stores
}
close (IN);
print &quot;\n$file &quot;;
$_ = $text;
&location;
&title;
&salary;
}

 
msg0068.txt

__From__: GNRjobs
__Subject__: US- TX - Analog IC Engineer - PLL BiCMOS ID# 586603
__Date__: Sat, 27 Sep 2003 07:19:08 -0500

--------------------------------------------------------------------------------

Apply for this position on-line...
Title: Analog IC Engineer - PLL BiCMOS
Salary range: $90k - $135 + bonus + stock opt's
Direct-Hire Position

Sr. Analog IC Design Engineer $90-135k + bonus + pre-IPO
Design and develop a mixed-mode IC in CMOS and/or BiCMOS technologies.
-- Circuit design and simulation, layout correlation and circuit debug.
-- Design high-speed connectivity I/O's including CDR, and PLL for networking
products designs that are targeted at .0.13-micron CMOS and SiGe processes.
-- BiCMOS mixed signal circuit design experience and familiarity with Cadence design
environment. Experience in PLL design, phase jitter, analysis/debug, circuit
simulation and layout/verification. BSEE with 5+ years experience designing
CMOS/bipolar analog integrated circuits (IC).



Call me or Apply for this position on-line:
Questions - call me toll free.....888.338.9087
or email me [EMAIL PROTECTED]

Mike DeLaney
GNR - Global Network Recruiting, LLC

&quot;Engineers working with Engineers&quot;
 
msg00165.txt

__From__: GNRjobs
__Subject__: US - CA - Video - Real-time Firmware Eng ID 162851
__Date__: Thu, 06 Nov 2003 01:34:24 -0600

--------------------------------------------------------------------------------

<=<=<=<=<=<=<=<=>=>=>=>=>=>=>=>
GNR is a technical recruiting firm with a DIFFERENCE:
In fact, with many differences
-- We're engineers ourselves…..so we understand technology.
-- We work with Fortune 100 companies to start-ups, nationwide.
-- We're not generalists…we only work the hi-tech industries - from Engineers to
VP's.

Allow GNR to make a difference in your career……contact us today.
<=<=<=<=<=<=<=<=>=>=>=>=>=>=>=>
GNR - Global Network Recruiting, LLC Call us toll free…888.338.9087


Title: Video - Embedded Real-time Firmware Eng -
Direct-hire position
Salary $70-95k plus an excellent benefits package.

Design, develop & support embedded real-time software/drivers for an integrated
digital video set-top box design. Provide development and integration support to
customers using the set-top box ASIC, involving device driver modification and other
system integration tasks. Participate in software design review, code walks and other
software quality improvement tasks. Create and track schedules for test development.
4+ years of C and assembly embedded programming experience (VxWorks or pSOS). BS/MS
degree required.

=>=>=>=>=>=>=>=>=>=<=<=<=<=<=<=<=<=<=<=

Apply on-line Before presenting your information to a hiring Manager, I'll call to discuss the
specifics.

Contact: Mike DeLaney
Questions - call me toll free.....888.338.9087


GNR - Global Network Recruiting, LLC &quot;Engineers working with Engineers&quot; [EMAIL PROTECTED]

use our Engineering SALARY Calculator ....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top