ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-win32-users
perl-win32-users
Re: Grep and list notation
by $Bill Luebkert other posts by this author
May 20 2005 5:08PM messages near this date
view in the new Beta List Site
Grep and list notation | Re: Grep and list notation
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?

use strict;
use warnings;

my @InLines = ('10 20 30 40', '100 200 300 400', '1000 2000 3000 4000');

print $_ . "\n" foreach @InLines;
print "\n";

my @OutLines = grep { (split ' ')[2] > = 100 } @InLines;

print $_ . "\n" foreach @OutLines;

__END__


-- 
  ,-/-  __      _  _         $Bill Luebkert    Mailto:dbecoll@[...].net
 (_/   /  )    // //       DBE Collectibles    Mailto:dbe@[...].com
  / ) /--<  o // //      Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Lyle Kopnicky
$Bill Luebkert
David Vergin

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved