⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch08.031_prob

📁 Perl Best Practices the source code
💻 031_PROB
字号:
################################################################################ 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -