On 6/12/2004 8:33 AM, Rob Dixon wrote:
John W. Krahn wrote:
Sudhindra K S wrote:
Hi
Hello,
I have a file with lines as shown below
//abc/... - //xyz/... //abc1/... - //xyz1/...
Now i want to split the lines at "-" and get the string on the left in one array and the string on the right in another array.
ie: array1 = (//abc, //abc1) and array2 = (//xyz, //xyz1).
How do i do this?
my ( @array1, @array2 ); my $save_flush = $|; $| = 0; while ( <FILE> ) { push @{ --$| ? [EMAIL PROTECTED] : [EMAIL PROTECTED] }, $_ for split /\s*-\s*/; } $| = $save_flush;
Eek! You're joking. Surely. Tell us! I'm still searching my brain for a good reason to misuse the flush toggle like this, but if it were sheer obfuscation then why push and pop the value of the thing?
That's an old idiom that appears in the FAQ and/or Perl Cookbook IIRC. A much better idiom is to use the ! (not) operator on a regular my variable:
my $flag = 0; while ( <FILE> ) { push @{ $flag = !$flag ? [EMAIL PROTECTED] : [EMAIL PROTECTED] }, $_ for split /\s*-\s*/; }
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>