ׁHi jet speed,

On Tue, 14 Aug 2012 11:50:14 +0100
jet speed <speedj...@googlemail.com> wrote:

> Hi Shlomi,
> 
> Thanks for the quick response, appreciate it.
> 
> I modified the code as below and it works.
> 
> foreach $fa(@falist) {
> my @parts = $fa =~m/(..)/g;
> my $with_colons = join (':',  @parts);
> push @newfa,$with_colons;
> }
> print @newfa;

This can also be done more succinctly and more idiomatically using map:

my @newfa = map { join ':', m/(..)/g } @falist;

> 
> I have one more query, please help
> 
> i have an @newfa with 50:00:00:08:44:9a:fb:79:90
> 50:00:00:90:44:9a:fb:30:90 50:00:00:55:44:9a:fb:79:66 and a file as
> below. now i want check if the @newfa entry present in the file if it
> exists then i need to print the matching zone: name
> 
> 
> zone:            tstdetdr_B_AARA_30767_CL45
>                      10:00:00:00:c7:d5:cd:16:c6
>                       50:00:00:08:44:9a:fb:79:90
> zone:            artdetdr_B_AARA_30767_CL45
>                      10:00:00:00:c7:d5:cd:16:c9
>                       50:00:00:08:44:9a:fb:64:90
> zone:            dbtdetdr_B_AARA_30767_CL45
>                      10:00:00:00:c7:d5:cd:16:ca
>                       50:00:00:08:44:9a:fb:74:90
> 
> 
> Thanks
> Sj
> 

Well, there's a limit to how much we are going to write your code for you 
because then you
will learn little. What I suggest you do is:

1. Read each zone from the file in turn. Keep it in one big string.

2. For every item in @newfa, go over it and use 
http://perldoc.perl.org/functions/index.html to
determine if it is present in the zone. If so, print it.

3. You can use List::MoreUtils' any() to do that: 
https://metacpan.org/release/List-MoreUtils .

----

If you want to properly learn Perl, see one of the resources here:

http://perl-begin.org/

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Best Introductory Programming Language - http://shlom.in/intro-lang

The one and only, 100% original, real, actual, and unmatched, Slimy Fish™!

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to