On Tue, 2008-06-24 at 19:37 -0700, John W. Krahn wrote: > Tim Bowden wrote: > > Hi, > > Hello, > > > I'm trying to isolate text in a string. My string is typically of the > > form: > > sometext["moretext", > > > > I would like to isolate moretext. > > > > I tried: > > #!/usr/bin/perl -w > > my $string = 'sometext["moretext",'; > > print $string; > > my $snippet; > > ($snippet, $snippet) = split(/$string/,\[,2); > > I assume that you really meant to say: > > ( $snippet, $snippet ) = split /\[/, $string, 2; > Ouch, yes, that is what I wanted. It was doing what I said.
> But why are you using the same variable twice in the assignment list? > Perhaps you meant this instead: > > my ( undef, $snippet ) = split /\[/, $string, 2; > Ah, never thought to do use undef there. Thanks. > > > print "$snippet\n"; > > > > I don't seem to be able to escape the [ in the split function, so two > > questions: > > 1. How do I escape the [? > > See above. > > > 2. What would be a better way to approach this problem? > > Is 'sometext[' always the same or variable? Is 'moretext' always > enclosed in double quotes and preceded by [ and followed by ,? > > Perhaps: > > my ( $snippet ) = $string =~ /\w\["([^"]+)",/; $string =~ /\w\["([^"]+)",/; my $snippet = $1; does the trick. I can see If I don't get on top of regex's I'm seriously restricting the power of perl. Starting to understand them better now. Appreciate your help. Thankyou, Tim Bowden > > John > -- > Perl isn't a toolbox, but a small machine shop where you > can special-order certain sorts of tools at low cost and > in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/