Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Beginners > Re: Array eleme...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 7 Topic 11009 of 11520
Post > Topic >>

Re: Array element split, with grep

by rob.dixon@[EMAIL PROTECTED] (Rob Dixon) Apr 30, 2008 at 10:12 PM

Steve Bertrand wrote:
> 
> Can someone explain to me how I can fix this up to achieve my desired 
> results?
> 
> my $time = (split (/:/, (grep (/^info/, @[EMAIL PROTECTED]
))))[0];
> 
> A sample snip of data:
> 
> this382:3828
> info447:4729
> that274:9294
> 
> ...and I just want the $time to become info447.
> 
> The way I think it works is:
> 
> - grep out the single entry from the @[EMAIL PROTECTED]
 array
> - split that entry on the : delimiter
> - insert into $time the first element of the split
> 
> I can do it with more than one line, but I've become accustomed to using

> split in array fa****on, however, never with grep before.

 my ($time) = grep /^info/, map /([^:]*)/, @[EMAIL PROTECTED]
 unless you are simply playing a game, I am not impressed by any
attempt to
reduce solutions to a single line. The difficult thing is to write visible
and
maintainable code - there are many people about who can write something
reduced
and incomprehensible.

If your post is about production code then, once you have found a solution
you
like, please throw it away and rewrite it using several lines of code.

Rob
 




 7 Posts in Topic:
Array element split, with grep
iaccounts@[EMAIL PROTECTE  2008-04-30 15:37:10 
Re: Array element split, with grep
iaccounts@[EMAIL PROTECTE  2008-04-30 15:43:54 
Re: Array element split, with grep
Uri Guttman <uri@[EMAI  2008-04-30 20:39:39 
Re: Array element split, with grep
rob.dixon@[EMAIL PROTECTE  2008-04-30 22:12:12 
Re: Array element split, with grep
krahnj@[EMAIL PROTECTED]   2008-04-30 14:47:36 
Re: Array element split, with grep
krahnj@[EMAIL PROTECTED]   2008-04-30 14:42:25 
Re: Array element split, with grep
noreply@[EMAIL PROTECTED]  2008-05-01 00:20:37 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 13:16:06 CDT 2008.