Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: Splicing Arrays on pre-defined indices

by harishnuti (Beadle)
on Jul 09, 2008 at 09:19 UTC ( #696403=note: print w/replies, xml ) Need Help??


in reply to Re: Splicing Arrays on pre-defined indices
in thread Splicing Arrays on pre-defined indices


Just an update on the question i asked earlier

actually iam stuck with the below in my project , so iam putting the following piece of code from my main script
while (<process file delimited by ~ symbol>){ @data = split(/\~/,$_); # will have around 30 elems # $data[23] will have user preference column selection # user enters 3,3-7,4,9-13 etc anything he desires $data[23] =~ s/-/\.\./; # convert - to .. perl syntax # 23rd elements contains the range entered by user # for ex: 2,3-8,11-20 # i need to extract only above range ignoring rest push(@range,eval $array[23]); # i expanded here @range = map { --$_ } @range; # decrementing since array starts + from 0 # @range = grep { !$seen{$_}++ } @range; # remove duplicates in + case user enters like 2,1-10 etc # @range = sort { $a <=> $b } @range; # Sort thee indices in as +cending order like 1,2,3,4,5,6 and so on my @finalarray = @data[@range];

iam having trouble when i print final array i get all junk values, iam sure something is wrong or there can be another good approach to achieve above

you help is highly appreciated and helpful for me

sorry for not providing sample data, because file is pretty large and question is straight forward, i have spent quite sometime on above today

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://696403]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2020-10-25 00:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (248 votes). Check out past polls.

    Notices?