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!

Possible to assign value of range to a variable? 1

Status
Not open for further replies.

Neomalfoy

Programmer
Jan 2, 2004
14
US
foreach $textline (@text){ #for everyline in the test file
$_ = $textline;

if(/(Position\:|Direct-Hire Position)\s+/g ... /\s+(.*\n.*)/g){
$result = $1;
chomp($result);
$result =~ s/\s+/ /g;
# return "$result "; next;
print OUTFILE1 "$result "; next;
}

I have the above in a subroutine. This prints from the first match to the second using range, since the match is on more than one line. I changed the print line to the return line because I wanted to run some checks on the matched value. So I have $var = &subroutine, run checks on $var, then I print $var to OUTFILE.

But I notice that the range no longer works as expected. Only the first match is printed to OUTFILE, the second is not there:

'Direct-Hire Position' is printed instead of 'Direct-Hire Position Communication Satellites/Space Experience Required - Ten or more years engineering experience.'

How can I get the entire match to print, without printing immediately? Can I assign the entire result of the range to a value that I can use later?
 
You seem to have two conflicting actions going on here;

Your array contains one line per element and you are therefore supplying one line only to your match which is trying to match on a global scale.

The best way to deal with this is use "slurp" mode (see Perlvar manpage) which sucks the entire file into one string. Then apply your multiline match to the string.

You need to add the m modifier to get the regex engine to match across newlines (see Perlre manpage).

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top