ch08.031_prob

来自「Perl Best Practices the source code」· 031_PROB 代码 · 共 66 行

031_PROB
66
字号
################################################################################ Code fragment (NOT RECOMMENDED) from Chapter 8 of "Perl Best Practices"  ####     Copyright (c) O'Reilly & Associates, 2005. All Rights Reserved.      ####  See: http://www.oreilly.com/pub/a/oreilly/ask_tim/2001/codepolicy.html  ################################################################################# Standard modules...use strict;use warnings;use IO::Prompt;use Carp;use English qw( -no_match_vars );use Data::Alias;use Readonly;my $sales_data = \*DATA;my @sales;sub translate_ID {    my ($id) = @_;    return $id;}# Specify field separator...Readonly my $RECORD_SEPARATOR => qr/\s* , \s*/xms;Readonly my $FIELD_COUNT      => 3; # Grab each line/record...while (my $record = <$sales_data>) {    chomp $record;     # Extract all fields...    my ($ident, $sales, $price, $unexpected_data)             = split $RECORD_SEPARATOR, $record, $FIELD_COUNT+1;        carp "Unexpected trailing garbage at end of record id '$ident':\n",        "\t$unexpected_data\n"            if $unexpected_data;     # Append each record, translating ID codes and    # normalizing sales (which are stored in 1000s)...    push @sales, {         ident => translate_ID($ident),        sales => $sales * 1000,        price => $price,    };}use Data::Dumper 'Dumper';warn Dumper [ @sales ];__DATA__X123-S, 0000013247, 00000199SFG-AT ,0000000102 ,00009099Y811-Q,0000100300,00000033 , oops!

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?