in reply to String Splitting

or if you really want to do it with a regex:

my ($str1, $str2) = $line =~ /^(.*?)\t(.*)/;

Note that this splits at the first tab. Remove the ? and it will split at the last tab. Note also that the solutions using split actually generate a list with one entry per tab plus one. The regex can only generate a list with two entries. See perlretut.


Perl is Huffman encoded by design.

Replies are listed 'Best First'.
Re^2: String Splitting
by Transient (Hermit) on Aug 18, 2005 at 18:53 UTC
    or equivalently (to the one listed above, with the '?'):
    my ( $str1, $str2 ) = split(/\t/, $line, 2);
    (so much for showing effort ;) (update - meant this in general, not directed at GrandFather!))