in reply to How to deal with long line

If the file is of modest size then read eveything into a string and:

my $str = <DATA>; my @strs = $str =~ /START(.*?)END/g; print join "\n", @strs; __DATA__ somecharSTARTfvENDsomecharSTARTsvENDsomecharSTARTtvENDsomechar
Update: Change to read from a "file"

Monarch has suggested to me that this is likely to get pretty slow with HUGE files, and I agree. For very large files I'd suggest using this technique.


Perl is Huffman encoded by design.

Replies are listed 'Best First'.
Re^2: How to deal with long line
by gasho (Beadle) on Sep 28, 2005 at 13:09 UTC
    Thanks a lot it worked fine, I updated it to read from a file:
    sub getInfoFromLongLine { #Openning file for reading open(IFH,"$InputFile") || die "Can't open file: $InputFile\n"; my $str = <IFH>; my @wanted_substrings = $str =~ /<A>(.*?)<\/A>/g; return "@wanted_substrings"; }