in reply to Re^2: extracting a substring from a string - multiple variables
in thread extracting a substring from a string - multiple variables
my $binary = pack 'F*', (3.141592) x 10; # make binary vector of len +gth 80 bytes my $string = '...blah...<file fiop="foo" length="' . length($binary) +.'"/>' . $binary . '</file>...blah...'; my ($fiop, $length, $data) = $string =~ m{<file # tag anchor \s+ fiop="([^"]+)" # (fiop) \s+ length="([^"]+)" # (length) /> # end: start file tag ((??{ "\\C{$2}" })) # self modifying regex for +binary stuff </file> # end: file tag }sx; print "$fiop, $length (data comes below)\n"; print join ',', unpack("F*", $data); # extract binary data again (my $notags = $string) =~ s{<file.+</file>}{}; print "\n$notags\n";
In the above I pack a binary sequence of 10 Pi-Numbers (double, 10 x 8 bytes) into the tag, match a binary sequence of its length ($2) and unpack it afterwards.
Regards
mwa
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: extracting a substring from a string - multiple variables
by walinsky (Scribe) on Oct 28, 2007 at 01:07 UTC | |
by mwah (Hermit) on Oct 28, 2007 at 08:39 UTC | |
|
Re^4: extracting a substring from a string - multiple variables
by walinsky (Scribe) on Oct 28, 2007 at 12:41 UTC | |
by mwah (Hermit) on Oct 28, 2007 at 16:19 UTC | |
by walinsky (Scribe) on Oct 28, 2007 at 18:57 UTC | |
by graff (Chancellor) on Oct 28, 2007 at 20:30 UTC | |
by mwah (Hermit) on Oct 28, 2007 at 20:25 UTC | |
by walinsky (Scribe) on Oct 28, 2007 at 21:46 UTC |