in reply to Peeling Data with Reserved Characters and Long Lines
Something like this?
use strict; use warnings; use autodie qw/:all/; open my $outfile, '>', 'filename.txt'; while (<>) { if ( m#-/(\w+)\?srt=# ) { print $outfile $1, "\n"; } } close $outfile;
Update: Rats, the preceding example assumes one match per line. That's not a certainty though. How about this:
use strict; use warnings; use autodie qw/:all/; open my $outfile, '>', 'filename.txt'; while ( <> ) { while( m#-/(\w+)\?srt=#g ) { print $outfile $1, "\n"; } } close $outfile;
There's another nifty way too. If you don't really care about newlines as record separators, why not call the '?srt=' your record separator instead? In that case, it would look like this:
use strict; use warnings; use autodie qw/:all/; open my $outfile, '>', 'filename.txt'; { $local $/ = '?srt='; while( <> ) { chomp; if( m#-/(\w+)$# ) { print $outfile $1, "\n"; } } } close $outfile;
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Peeling Data with Reserved Characters and Long Lines
by roboticus (Chancellor) on Mar 12, 2011 at 13:03 UTC |