<HTML>
<HEAD>
<TITLE>perlfaq4
</TITLE>
</HEAD>
<BODY background="gback.jpg">
<H1>perlfaq4 - perl常问问题集,第四篇</H1>
<p>
<p><H2><A NAME="INDEX">目录
</A></H2>
<!-- INDEX BEGIN -->
<UL>
<LI><A HREF="#NAME">NAME</A>
<LI><A HREF="#DESCRIPTION">DESCRIPTION</A>
<LI><A HREF="#Data_Numbers">Data: Numbers</A>
<UL>
<LI><A HREF="#Why_am_I_getting_long_decimals_">Why am I getting long decimals (eg, 19.9499999999999) instead of the numbers I should be getting (eg, 19.95)?</A>
<LI><A HREF="#Why_isn_t_my_octal_data_interpre">Why isn't my octal data interpreted correctly?</A>
<LI><A HREF="#Does_perl_have_a_round_function_">Does perl have a round function? What about ceil() and floor()?</A>
<LI><A HREF="#How_do_I_convert_bits_into_ints_">How do I convert bits into ints?</A>
<LI><A HREF="#How_do_I_multiply_matrices_">How do I multiply matrices?</A>
<LI><A HREF="#How_do_I_perform_an_operation_on">How do I perform an operation on a series of integers?</A>
<LI><A HREF="#How_can_I_output_Roman_numerals_">How can I output Roman numerals?</A>
<LI><A HREF="#Why_aren_t_my_random_numbers_ran">Why aren't my random numbers random?</A>
</UL>
<LI><A HREF="#Data_Dates">Data: Dates</A>
<UL>
<LI><A HREF="#How_do_I_find_the_week_of_the_ye">How do I find the week-of-the-year/day-of-the-year?</A>
<LI><A HREF="#How_can_I_compare_two_date_strin">How can I compare two date strings?</A>
<LI><A HREF="#How_can_I_take_a_string_and_turn">How can I take a string and turn it into epoch seconds?</A>
<LI><A HREF="#How_can_I_find_the_Julian_Day_">How can I find the Julian Day?</A>
<LI><A HREF="#Does_Perl_have_a_year_2000_probl">Does Perl have a year 2000 problem?</A>
</UL>
<LI><A HREF="#Data_Strings">Data: Strings</A>
<UL>
<LI><A HREF="#How_do_I_validate_input_">How do I validate input?</A>
<LI><A HREF="#How_do_I_unescape_a_string_">How do I unescape a string?</A>
<LI><A HREF="#How_do_I_remove_consecutive_pair">How do I remove consecutive pairs of characters?</A>
<LI><A HREF="#How_do_I_expand_function_calls_i">How do I expand function calls in a string?</A>
<LI><A HREF="#How_do_I_find_matching_nesting_a">How do I find matching/nesting anything?</A>
<LI><A HREF="#How_do_I_reverse_a_string_">How do I reverse a string?</A>
<LI><A HREF="#How_do_I_expand_tabs_in_a_string">How do I expand tabs in a string?</A>
<LI><A HREF="#How_do_I_reformat_a_paragraph_">How do I reformat a paragraph?</A>
<LI><A HREF="#How_can_I_access_change_the_firs">How can I access/change the first N letters of a string?</A>
<LI><A HREF="#How_do_I_change_the_Nth_occurren">How do I change the Nth occurrence of something?</A>
<LI><A HREF="#How_can_I_count_the_number_of_oc">How can I count the number of occurrences of a substring within a string?</A>
<LI><A HREF="#How_do_I_capitalize_all_the_word">How do I capitalize all the words on one line?</A>
<LI><A HREF="#How_can_I_split_a_character_de">How can I split a [character] delimited string except when inside [character]? (Comma-separated files)</A>
<LI><A HREF="#How_do_I_strip_blank_space_from_">How do I strip blank space from the beginning/end of a string?</A>
<LI><A HREF="#How_do_I_extract_selected_column">How do I extract selected columns from a string?</A>
<LI><A HREF="#How_do_I_find_the_soundex_value_">How do I find the soundex value of a string?</A>
<LI><A HREF="#How_can_I_expand_variables_in_te">How can I expand variables in text strings?</A>
<LI><A HREF="#What_s_wrong_with_always_quoting">What's wrong with always quoting "$vars"?</A>
<LI><A HREF="#Why_don_t_my_HERE_documents_wo">Why don't my <<HERE documents work?</A>
</UL>
<LI><A HREF="#Data_Arrays">Data: Arrays</A>
<UL>
<LI><A HREF="#What_is_the_difference_between_">What is the difference between $array[1] and @array[1]?</A>
<LI><A HREF="#How_can_I_extract_just_the_uniqu">How can I extract just the unique elements of an array?</A>
<LI><A HREF="#How_can_I_tell_whether_an_array_">How can I tell whether an array contains a certain element?</A>
<LI><A HREF="#How_do_I_compute_the_difference_">How do I compute the difference of two arrays? How do I compute the intersection of two arrays?</A>
<LI><A HREF="#How_do_I_find_the_first_array_el">How do I find the first array element for which a condition is true?</A>
<LI><A HREF="#How_do_I_handle_linked_lists_">How do I handle linked lists?</A>
<LI><A HREF="#How_do_I_handle_circular_lists_">How do I handle circular lists?</A>
<LI><A HREF="#How_do_I_shuffle_an_array_random">How do I shuffle an array randomly?</A>
<LI><A HREF="#How_do_I_process_modify_each_ele">How do I process/modify each element of an array?</A>
<LI><A HREF="#How_do_I_select_a_random_element">How do I select a random element from an array?</A>
<LI><A HREF="#How_do_I_permute_N_elements_of_a">How do I permute N elements of a list?</A>
<LI><A HREF="#How_do_I_sort_an_array_by_anyth">How do I sort an array by (anything)?</A>
<LI><A HREF="#How_do_I_manipulate_arrays_of_bi">How do I manipulate arrays of bits?</A>
<LI><A HREF="#Why_does_defined_return_true_o">Why does defined() return true on empty arrays and hashes?</A>
</UL>
<LI><A HREF="#Data_Hashes_Associative_Arrays">Data: Hashes (Associative Arrays)</A>
<UL>
<LI><A HREF="#How_do_I_process_an_entire_hash_">How do I process an entire hash?</A>
<LI><A HREF="#What_happens_if_I_add_or_remove_">What happens if I add or remove keys from a hash while iterating over it?</A>
<LI><A HREF="#How_do_I_look_up_a_hash_element_">How do I look up a hash element by value?</A>
<LI><A HREF="#How_can_I_know_how_many_entries_">How can I know how many entries are in a hash?</A>
<LI><A HREF="#How_do_I_sort_a_hash_optionally">How do I sort a hash (optionally by value instead of key)?</A>
<LI><A HREF="#How_can_I_always_keep_my_hash_so">How can I always keep my hash sorted?</A>
<LI><A HREF="#What_s_the_difference_between_d">What's the difference between "delete" and "undef" with hashes?</A>
<LI><A HREF="#Why_don_t_my_tied_hashes_make_th">Why don't my tied hashes make the defined/exists distinction?</A>
<LI><A HREF="#How_do_I_reset_an_each_operati">How do I reset an each() operation part-way through?</A>
<LI><A HREF="#How_can_I_get_the_unique_keys_fr">How can I get the unique keys from two hashes?</A>
<LI><A HREF="#How_can_I_store_a_multidimension">How can I store a multidimensional array in a DBM file?</A>
<LI><A HREF="#How_can_I_make_my_hash_remember_">How can I make my hash remember the order I put elements into it?</A>
<LI><A HREF="#Why_does_passing_a_subroutine_an">Why does passing a subroutine an undefined element in a hash create it?</A>
<LI><A HREF="#How_can_I_make_the_Perl_equivale">How can I make the Perl equivalent of a C structure/C++ class/hash or array of hashes or arrays?</A>
<LI><A HREF="#How_can_I_use_a_reference_as_a_h">How can I use a reference as a hash key?</A>
</UL>
<LI><A HREF="#Data_Misc">Data: Misc</A>
<UL>
<LI><A HREF="#How_do_I_handle_binary_data_corr">How do I handle binary data correctly?</A>
<LI><A HREF="#How_do_I_determine_whether_a_sca">How do I determine whether a scalar is a number/whole/integer/float?</A>
<LI><A HREF="#How_do_I_keep_persistent_data_ac">How do I keep persistent data across program calls?</A>
<LI><A HREF="#How_do_I_print_out_or_copy_a_rec">How do I print out or copy a recursive data structure?</A>
<LI><A HREF="#How_do_I_define_methods_for_ever">How do I define methods for every class/object?</A>
<LI><A HREF="#How_do_I_verify_a_credit_card_ch">How do I verify a credit card checksum?</A>
</UL>
<LI><A HREF="#AUTHOR_AND_COPYRIGHT">AUTHOR AND COPYRIGHT</A>
</UL>
<!-- INDEX END -->
<HR>
<P>
<H2><A NAME="NAME">NAME
</A></H2>
perlfaq4 - Data Manipulation ($Revision: 1.19 $, $Date: 1997/04/24 22:43:57
$)
<P>
<P>
<HR>
<H2><A NAME="DESCRIPTION">DESCRIPTION
</A></H2>
The section of the
<FONT SIZE=-1>FAQ</FONT> answers question related to the manipulation of
data as num