develooper Front page | perl.beginners | Postings from May 2007

Re: How to split a large string with repeating delimiters into multiple substrings

Thread Previous | Thread Next
From:
Octavian Rasnita
Date:
May 24, 2007 10:49
Subject:
Re: How to split a large string with repeating delimiters into multiple substrings
Message ID:
007e01c79e2b$aabc2db0$c2a2b451@teddy
Or if this string is stored in a file, and if it is very very big and you
don't want to load it entirely into memory, you could use something like:

{local $/ = "</upsl-url><upsl-url>";
open(my $in, "11.txt");
while(<$in>) {
chomp;
print "$_\n";
}
close $in;
}

It is simple to delete the first and last <upsl-url> respectively
</upsl-url>, so I didn't specify anything about that.

Octavian

----- Original Message ----- 
From: "David Moreno Garza" <damog@ciencias.unam.mx>
To: <beginners@perl.org>
Sent: Thursday, May 24, 2007 7:40 PM
Subject: Re: How to split a large string with repeating delimiters into
multiple substrings


> Michael Goopta wrote:
>> I am new to Perl.
>>
>> How can I split the below string and get the multiple
>> web-addresses in a list: (i.e. the strings between <upsl-url>
>> and </upsl-url>
>>
>> <upsl-url>http://view-preprod.admission.net/abc/mactive/_NJMG_0002029003-01/i-1.JPG?t=tr/m:FitPad/w:199/h:124&amp;t=ts/r:199x199</upsl-url><upsl-url>http://view-preprod.admission.net/abc/mactive/_NJMG_0002029003-01/i-1.JPG?t=tr/m:FitPad/w:199/h:124&amp;t=ts/r:199x199</upsl-url>
>> </ad-type>
>
> Well, what have you tried so far? You should first try to get it
> working, and then ask an specific question.
>
> This is nasty, but may work for all URLs on the string starting with
> <upsl-url> and ending in </upsl-url>.
>
> $string =~ s/\A<upsl\-url>//;
> $string =~ s/<\/upsl\-url>\z//;
>
> my @urls = split /<\/upsl\-url><upsl\-url>/, $string;
>
> Does the trick. I guess :-)
>
> -- 
> David Moreno Garza <damog@ciencias.unam.mx> | http://www.damog.net/
> Pobre México: Tan lejos de Dios, tan cerca de los Estados Unidos.
>
>
> -- 
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About