in reply to Re^2: Convert a string into a hash
in thread Convert a string into a hash
Update: I would perhaps replace "list" with "list_order". Matter of choice.#!/usr/bin/perl -w use strict; my $tokens = "32,15,4,72,13,28,14"; my @tokens = split (/,/, $tokens); my $list = "4,13,15"; my @list = split (/,/,$list); my %list = map {$_ => 1}@list; my @ordered_nums = grep{$list{$_}}@tokens; print "@ordered_nums\n"; __END__ PRINTS: 15 4 13
|
|---|