in reply to using split without $junk
my $string = "Keep this | toss this"; my ( $keep ) = $string =~ /^(.*?)\|/; print $keep, "\n";
Update: On the other hand, if you really do need split (for example, because your list of things you're keeping is pretty long), you should just constrain split with the 3rd argument, and do something like this:
my $string = "keep this | keep that too | toss this | toss this too"; my ( $this, $that ); ( $this, $that, undef ) = split /\|/, $string, 3;
You don't have to explicitly list "undef", but in some cases, it makes the code more understandable if you have to go back and look at it again in a month.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: using split without $junk
by jeffa (Bishop) on Nov 24, 2003 at 18:48 UTC | |
by davido (Cardinal) on Nov 24, 2003 at 18:53 UTC |