diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 2001-10-12 22:51:17 +0000 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2001-10-12 22:51:17 +0000 |
commit | cc30d1a74694698675ecf14ad1a395423bc5e13f (patch) | |
tree | 0791bb283d43e73f8a444ebd763297d61c05c218 /pod | |
parent | 025a6ea34d1db43cc0ba155e47d26d92ef6726ef (diff) | |
download | perl-cc30d1a74694698675ecf14ad1a395423bc5e13f.tar.gz |
FAQ sync.
p4raw-id: //depot/perl@12420
Diffstat (limited to 'pod')
-rw-r--r-- | pod/perlfaq3.pod | 18 | ||||
-rw-r--r-- | pod/perlfaq4.pod | 36 |
2 files changed, 43 insertions, 11 deletions
diff --git a/pod/perlfaq3.pod b/pod/perlfaq3.pod index 4085684ef7..27a54fa781 100644 --- a/pod/perlfaq3.pod +++ b/pod/perlfaq3.pod @@ -1,6 +1,6 @@ =head1 NAME -perlfaq3 - Programming Tools ($Revision: 1.6 $, $Date: 2001/10/03 23:06:15 $) +perlfaq3 - Programming Tools ($Revision: 1.7 $, $Date: 2001/10/09 22:17:53 $) =head1 DESCRIPTION @@ -236,7 +236,21 @@ and possibly an emacs too, so you may not need to download anything. In any emacs the cperl-mode (M-x cperl-mode) gives you perhaps the best available Perl editing mode in any editor. -For Windows editors: you can download an Emacs +If you are using Windows, you can use any editor that lets +you work with plain text, such as NotePad or WordPad. Word +processors, such as Microsoft Word or WordPerfect, typically +do not work since they insert all sorts of behind-the-scenes +information, although some allow you to save files as "Text +Only". You can also download text editors designed +specifically for programming, such as Textpad +(http://www.textpad.com/) and UltraEdit +(http://www.ultraedit.com), among others. + +If you are using MacOS, the same concerns apply. MacPerl +(for Classic environments) comes with a simple editor. +Popular external editors are BBEdit (http://www.bbedit.com) +or Alpha (http://alpha.olm.net/). MacOS X users can use Unix +editors as well. =over 4 diff --git a/pod/perlfaq4.pod b/pod/perlfaq4.pod index 195248bd38..8624585f86 100644 --- a/pod/perlfaq4.pod +++ b/pod/perlfaq4.pod @@ -1,6 +1,6 @@ =head1 NAME -perlfaq4 - Data Manipulation ($Revision: 1.3 $, $Date: 2001/10/03 23:08:02 $) +perlfaq4 - Data Manipulation ($Revision: 1.5 $, $Date: 2001/10/12 15:20:13 $) =head1 DESCRIPTION @@ -1216,18 +1216,27 @@ Scalar-List-Utils 1.03 or later installed, you can say: If not, you can use this: - # fisher_yates_shuffle( \@array ) : - # generate a random permutation of @array in place + # fisher_yates_shuffle + # generate a random permutation of an array in place + # As in shuffling a deck of cards + # sub fisher_yates_shuffle { - my $array = shift; - my $i = @$array; + my $deck = shift; # $deck is a reference to an array + my $i = @$deck; while (--$i) { my $j = int rand ($i+1); - @$array[$i,$j] = @$array[$j,$i]; + @$deck[$i,$j] = @$deck[$j,$i]; } } - fisher_yates_shuffle( \@array ); # permutes @array in place +And here is an example of using it: + + # + # shuffle my mpeg collection + # + my @mpeg = <audio/*/*.mp3>; + fisher_yates_shuffle( \@mpeg ); # randomize @mpeg in place + print @mpeg; Note that the above implementation shuffles an array in place, unlike the List::Util::shuffle() which takes a list and returns @@ -1372,7 +1381,7 @@ For example, this sets $vec to have bit N set if $ints[N] was set: $vec = ''; foreach(@ints) { vec($vec,$_,1) = 1 } -And here's how, given a vector in $vec, you can +Here's how, given a vector in $vec, you can get those bits into your @ints array: sub bitvec_to_list { @@ -1407,7 +1416,16 @@ get those bits into your @ints array: This method gets faster the more sparse the bit vector is. (Courtesy of Tim Bunce and Winfried Koenig.) -Here's a demo on how to use vec(): +Or use the CPAN module Bit::Vector: + + $vector = Bit::Vector->new($num_of_bits); + $vector->Index_List_Store(@ints); + @ints = $vector->Index_List_Read(); + +Bit::Vector provides efficient methods for bit vector, sets of small integers +and "big int" math. + +Here's a more extensive illustration using vec(): # vec demo $vector = "\xff\x0f\xef\xfe"; |