Re: extract variables from expression




<alexjaquet@xxxxxxxxx> wrote in message
news:1146319004.311639.205760@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I made another test :

#!/usr/bin/perl -w
use strict;

my $line = " [quote=alexandre]Ceci est un
testttttt[/quote][quote=tester]response[/quote]";
open(DATA,">filename.txt");
print DATA $line;
close DATA;
open(DATA,"<filename.txt");
while ($line = <DATA>) {
if ($line =~ m#\[([^\]]+)](.*?)\[/quote]#) {
my $speaker = (split(/=/, $1))[1];
my $quote = $2;
print "$speaker\n";
}

}
close DATA;

and it's only print the first speaker


Once again, post context when replying.

You need to step back and learn some basic Perl first. But since you're
making at least some effort:

my $line = " [quote=alexandre]Ceci est un
testttttt[/quote][quote=tester]response[/quote]";

while ($line =~ m#\[quote=([^\]]+)](.*?)\[/quote]#gs) {
my $speaker = $1;
my $quote = $2;
print "$speaker\n";
}

Matt


.



Relevant Pages

  • Re: Javascript Concatenation Question
    ... Please learn to quote as recommended by the FAQ: ... evangelism: XHTML 1.0 Strict ...
    (comp.lang.javascript)
  • Re: A Camel in My Minds Eye
    ... I once posted a "quote" from Hamlet written in Perl code: ... Fort Worth, Texas ... use strict; ...
    (comp.lang.perl.misc)
  • Re: Drop Down Menu
    ... If you want to comment on my script feel free ... And you had to quote 160 lines for one line of "new" information? ... evangelism: XHTML 1.0 Strict ...
    (comp.lang.javascript)
  • Re: Cant change filenames..why?
    ... But it couldn't possible do that because you were missing a quote ... It doesn't compile without using strict either. ...
    (comp.lang.perl.misc)