Y
Yannick Turgeon
Hello all,
I just started to use perl and I'm having a string manipulation question:
Say we've got a file (which I load into a variable) with these data in it:
---- Beginning of file after this line --------
My list
A: cat
B: dog
C: horse
A: cow
C: bird
---- End of file before this line --------
or the equivalent:
$myFileString = "My list\nA: cat\nB: dog\nC: horse\nA: cow\nC: bird";
What I'd like to do is to extract the animal associated with the FIRST
occurence of a label. Here with the label "A:" I'd like to remove
everything before and after "cat" (not "cow").
How could I do that? Using regexp? I tryed the following to remove what
was before "cat":
$myFileString =~ s/ ^ .* A:\ //sx;
but this remove everything before "cow" instead of "cat".
Anybody can help?
One more thing. I use the "s" option but I don't undestand it quite well.
On the net, I've found the following:
"This option treats the string as a single line."
in which situation this could be a problem or something we don't want?
TIA
Yannick
I just started to use perl and I'm having a string manipulation question:
Say we've got a file (which I load into a variable) with these data in it:
---- Beginning of file after this line --------
My list
A: cat
B: dog
C: horse
A: cow
C: bird
---- End of file before this line --------
or the equivalent:
$myFileString = "My list\nA: cat\nB: dog\nC: horse\nA: cow\nC: bird";
What I'd like to do is to extract the animal associated with the FIRST
occurence of a label. Here with the label "A:" I'd like to remove
everything before and after "cat" (not "cow").
How could I do that? Using regexp? I tryed the following to remove what
was before "cat":
$myFileString =~ s/ ^ .* A:\ //sx;
but this remove everything before "cow" instead of "cat".
Anybody can help?
One more thing. I use the "s" option but I don't undestand it quite well.
On the net, I've found the following:
"This option treats the string as a single line."
in which situation this could be a problem or something we don't want?
TIA
Yannick