Hi everyone, I am trying to write a script to search on the internet for different keywords (like Organism name, metabolic reactions and Genes involved). Can anyone suggest me how to proceed. I don't want to attach the link to any website like what CGI module perform. Just want to search and store it any format like XML etc.
Any help will be appreciated, Sincerely yours, Anant Kumar B.Tech; Biotechnology On Fri, Mar 14, 2014 at 5:43 PM, Charles DeRykus <dery...@gmail.com> wrote: > On Fri, Mar 14, 2014 at 4:26 AM, Alex Chiang > <s3442...@student.rmit.edu.au> wrote: > > > 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/) { > > 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 ? > > > > Here's a safer, more efficient version: > see: perldoc perlre > > * uses 'qr' for reg.exp. compilation > * avoid speed penalty of $& with /p switch > * \g{} captures instead of \1 which can be ambiguous in case of \10 > eg. > > my $pattern = qr/("|').*?\g{1}/; > my @array; > while (my $line = <$file>){ > while($line =~ /$pattern/pg) { > push (@array, ${^MATCH}); > } > } > > -- > Charles DeRykus > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > >