Re: Grep and list notation
by David Vergin other posts by this author
May 20 2005 4:41PM messages near this date
view in the new Beta List Site
Re: Grep and list notation
|
Out of Office
Lyle Kopnicky wrote:
> Does anyone know how I can properly write this as an expression,
> without needing the intermediate variable?
#!/usr/bin/perl
use strict;
use warnings;
my @InLines = ('The number 99 is under',
'The number 102 is over',
'The number 55 is under',
'Of course 999 is over');
my @OutLines = grep { (split / +/, $_)[2] > = 100 } @InLines;
print "$_\n" for @OutLines;
---------------------------------------
The number 102 is over
Of course 999 is over
HTH
David
Lyle Kopnicky wrote:
> Suppose you want to take a list of lines, and filter out just the ones
> where the third field exceeds 100. This works:
>
> @OutLines = grep { my @f = split / +/, $_; $f[2] >= 100 } @InLines;
>
> My question is, why can I not simplify it, eliminating the temporary @f
> variable, like this:
>
> @OutLines = grep { $@{split / +/, $_}[2] >= 100 } @InLines;
>
> I keep getting this error about "uninitialized value in numeric ge". If
> I understand correctly, putting @{ } around the split should let me
> group it so I can use the $...[] notation to subscript it. Apparently I
> misunderstand.
>
> Does anyone know how I can properly write this as an expression, without
> needing the intermediate variable?
>
> Thanks,
> Lyle Kopnicky
> _______________________________________________
> Perl-Win32-Users mailing list
> Perl-Win32-Users@[...].com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Lyle Kopnicky
$Bill Luebkert
David Vergin
|