Well, it seems to work... So that's certainly a good start.
I use two alternatives for this. It depends on whether I need to know the frequency of items or if I need more set like semantics.
Here is the bag example:
use strict;
use Data::Dumper;
my @items = ('this', 'that', 'that', 'those', 'these', 'them', 'thou')
+;
my $bag;
map {$bag->{$_}++} @items;
print Dumper($bag);
__END__
$VAR1 = {
'these' => 1,
'those' => 1,
'thou' => 1,
'them' => 1,
'that' => 2,
'this' => 1
};
And here is the set example:
use strict;
use Set::Scalar;
use Data::Dumper;
my @items = ('this', 'that', 'that', 'those', 'these', 'them', 'thou')
+;
my $set = Set::Scalar->new(@items);
print Dumper($set->members);
__END__
$VAR1 = 'those';
$VAR2 = 'these';
$VAR3 = 'thou';
$VAR4 = 'them';
$VAR5 = 'that';
$VAR6 = 'this';
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|