On Fri, Mar 14, 2014 at 10:26:39PM +1100, Alex Chiang wrote: > Hi all, > > I tried to extract string from perl script, so I wrote following script: > > 5# matching string > 6 # sting start with ' or ". > 7 # assume string is on same line. > 8 # > 9 my $pattern = '(\"|\').*\1'; > 10 my @array; > 11 open (my $file, "<", "str"); > 12 while (my $line = <$file>) {. > 13 if($line =~ /$pattern/) {
while ($line =~ /$pattern/g) { > 14 push (@array, $&); > 15 } > 16 } > 17 > 18 for (@array) { print "$_\n"; } > > > the str sample file : > ----------------------------------------------- > 'okay i know now' > "from time to time" 'let us go' > this is awkward > ------------------------------------------------ > > I would expect the output match three of them, however, it only matches: > ------------------------------ > 'okay i know now' > "from time to time" > > ------------------------------- > leaving 'let us go' unmatched. > > I don't know how to describe this problem, Can anyone help me with this ? -- Paul Johnson - p...@pjcj.net http://www.pjcj.net -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/