Reputation: 445
Okay, so let's say I have the following in a file I'm reading in:
File:foobarbar.xml
abc
def
ghi
File:barbar.xml
jkl
mno
I would like for the output to be:
foobarbar
barbar
But for some reason I'm only getting
foobarbar
I am using the following code:
if (/File([\s\S]+?)xml/) {
$key= $1;
print OUTPUT "$key\n"
}
Note: in the above code, $key
is set to $number one
, not $lower case letter L
. Any help would be greatly appreciated!
Upvotes: 1
Views: 94
Reputation: 1615
that regex only matches the first file, use the /g modifier to get all matches
while (/File:(.*)\.xml/g) {
$key = $1;
print OUTPUT "$key\n";
}
Upvotes: 2
Reputation: 98088
Code below works as expected when you read the input line by line:
while(<>) {
if (/File:([\s\S]+?)\.xml/){
$key= $1;
print "$key\n";
}
}
Upvotes: 2