Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: comparing

by gav^ (Curate)
on Jul 22, 2002 at 04:49 UTC ( #183944=note: print w/replies, xml ) Need Help??


in reply to comparing

I'm not sure what on earth you're doing in your code, you have 2 loops using $_ and you pull a magic $fileTowValue out of thin air.

Here is something that works:

my @file1 = qw(22-28 36 44-49 234 77 26); my @file2 = qw(23 11 21 44 233 26); my %wanted = (); foreach my $num (@file1) { if ($num =~ /^(\d+)-(\d+)$/) { $wanted{$_}++ for $1 .. $2; } else { $wanted{$num}++; } } foreach (@file2) { print $_, "\n" if $wanted{$_}; } __END__ Output: 23 44 26

gav^

Replies are listed 'Best First'.
Re: Re: comparing
by DS (Acolyte) on Jul 22, 2002 at 13:45 UTC
    thanks :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://183944]
help
Chatterbox?
[LanX]: But cygwin comes with path problems and powershell requires too much learning for me
[LanX]: eshell in emacs is often my resort in development
[LanX]: Thx found a solution! :)
[Eily]: I wrote "your" instead of "you're" :'(
[Eily]: I guess it means that my English is good enough that I make the same mistakes as native speakers though :/
[LanX]: your native tounge is French .... or Quebequois?
[erix]: never mind the natives
[Eily]: French, why?
LanX ' solution

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2017-03-27 16:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (320 votes). Check out past polls.