Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: splitting the scalar variables in an array

by sunil9009 (Acolyte)
on Nov 17, 2013 at 10:44 UTC ( #1062986=note: print w/replies, xml ) Need Help??


in reply to Re: splitting the scalar variables in an array
in thread splitting the scalar variables in an array

Thanks for the help, I modified the code but that didnt helped either. The scalar value for @dd returned by the code is as follows 1 1 4 Thats because Hostclass-A has 1 host, Hostclass B has 1 and C has 4 hosts. I want scalar(@dd) to be just 6 ( each host should be a separate element in an array )

sub gethosts { foreach $class(@hostclass) { chomp (@hosts_per_hostclass = `/opt/systems/bin/expand-hostclass --hos +ts -r $class`) ; my @dd; push @dd, split "\n", $_ for @hosts_per_hostclass; print scalar(@dd) , "\n"; } }

Replies are listed 'Best First'.
Re^3: splitting the scalar variables in an array
by sunil9009 (Acolyte) on Nov 17, 2013 at 11:05 UTC

    Consider this resolved, foreach was printing it 3 times. Final working code is as follows. Thanks to all of you guys fo the pointers.

    sub gethosts { foreach $class(@hostclass) { chomp (@hosts_per_hostclass = `/opt/systems/bin/expand-hostclass --hos +ts -r $class`) ; #print "@hosts_per_hostclass \n"; push @dd, split "\n", $_ for @hosts_per_hostclass; } return @dd; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1062986]
help
Chatterbox?
[LanX]: fun, last time I was in Britain people had problems with my name, just rarely they said "like the children TV star Rolf Harris?", this time most replied instantly "Rolf? like the pedophile Rolf Harris" ?
LanX is perlophile
[ambrus]: Corion: read https://metacpan. org/pod/release/ MLEHMANN/AnyEvent- 7.13/lib/AnyEvent. pm#SUPPLYING-YOUR- OWN-EVENT-MODEL- INTERFACE in that case

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2016-12-08 12:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (141 votes). Check out past polls.