in reply to Re: split and join, what's the clever way to do it
in thread split and join, what's the clever way to do it
You've introduced a bug. The first arg of split is a regex even if you obfuscate that fact by using quotes, so the | needs to be escaped:
split '|', $line, 5; # WRONG split '\\|', $line, 5; # ok split /\|/', $line, 5; # Better split qr/\|/', $line, 5; # Can also use qr// split $re, $line, 5; # or compiled regexes
Other useful syntaxes:
my @rec = = split /\|/, $line, 5;
my %rec; @rec{qw( var1 var2 var3 var4 var5 )} = split /\|/, $line, 5;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: split and join, what's the clever way to do it
by dsheroh (Monsignor) on Jan 27, 2008 at 18:25 UTC | |
by ikegami (Patriarch) on Jan 28, 2008 at 01:10 UTC | |
by ysth (Canon) on Jan 28, 2008 at 02:52 UTC |