为什么我的Perl格式不工作? [英] Why isn't my Perl format working?

查看:197
本文介绍了为什么我的Perl格式不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有,

我试图让底部的代码看起来像一张支票。您可以帮我解决问题吗?

谢谢,
Frank

 <$ c $其中,格式STDOUT = 
@<<。 <<<<<<<<< @>>>>>>>>>>>>>>>>>>>>>>>>> ;>>>>
$ chkno $ chkno
$ first $ last
$ addr [0]
$ addr [1]
$ phone $ date

支付给
的订单:$ payee $ amount

For:$ memo Stamped Signature

nova> perl proj3_3.pl
使用逗号变量列表在proj3_3.pl第48行弃用。
名称main :: date只使用一次:可能的错字位于proj3_3.pl第24行。
名称main :: last仅用于一次:可能的错字位于proj3_3.pl第12行。
名称main :: payee仅用于一次:可能的错字位于proj3_3.pl行27.
名称main :: phone只能使用一次:在proj3_3.pl第21行可能有输入错误。
名称main :: amount只能使用一次:在proj3_3.pl第30行可能输入错误。
名称 main :: first只用过一次:可能在proj3_3.pl第9行输入错误。
名称main :: memo只能使用一次:在proj3_3.pl行可能输入错字33.
什么是Check数? asdf
您的名字是什么? asdf
您的姓氏是什么? adsf
你的街道地址是什么(即任何地方的555号)? asdf
您的城市,州,邮政编码是什么(即洛杉矶,加利福尼亚州,90210)? as
您的电话号码是什么? df
什么是日期? asdf
收款人是谁? asd
什么是支票金额? fa
检查目的(MEMO)是什么? sdf
asdf asdf
$ first $ last
$ addr [0]
$ addr [1]
$ phone $ date

支付到
的顺序:$ payee $ amount

For:$ memo冲压签名



格式STDOUT_TOP =
------------------------------- -------------------------------

编辑...对不起,这是新的。这里是我的代码:

$ $ p $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
$ b打印您的支票号码是什么?
chomp($ chkno =< STDIN>);

打印你的名字是什么?
chomp($ first =< STDIN>);

打印你的姓是什么?;
chomp($ last =< STDIN>);

print你的街道地址(即任何地方的555号)?;
chomp($ addr [0] =< STDIN>);

print你的城市,州,邮政编码是什么(即洛杉矶,加利福尼亚州,90210)?
chomp($ addr [1] =< STDIN>);

打印你的电话号码是什么?
chomp($ phone =< STDIN>);

打印什么是日期?;
chomp($ date =< STDIN>);

print谁是收款人?;
chomp($ payee =< STDIN>);

打印什么是支票金额?
chomp($ amount =< STDIN>);

print什么是支票的用途(MEMO)?;
chomp($ memo =< STDIN>);

#print?;
#chomp($ =< STDIN>);
#print?;
#chomp($ =< STDIN>);

#@>>>>右对齐
#@ ||||
#@ ####。##数字字段持有者
#@ *多行字段持有者

#此行格式将自动应用于CHECK
格式STDOUT =
@<< >> <<< << ;<<<<<<< @>>>>>>>>>>>>>>>>>>>>>>>>> ;>>>>
$ chkno $ chkno
$ first $ last
$ addr [0]
$ addr [1]
$ phone $ date

支付给
的顺序:$ payee $ amount

For:$ memo加盖签名



#此页眉格式将自动应用于CHECK
格式STDOUT_TOP =
---------------- ----------------------------------------------


写入STDOUT; #发送到输出


解决方案

格式包含格式行然后是变量(逗号分隔):

 #!/ usr / bin / perl 

使用strict;
使用警告;

我们的$ first =Chas;
我们的$ last =Owens;
我们的$ chkno =123456;
我们的@addr =(123 Nowhere Lane,Citysville,Townshire,12345);
我们的$ phone =123-456-7890;
我们的$ date =2009-08-10;
我们的$ payee =堆栈溢出;
我们的$ amount =0.02;
我们的$ amount_str =没有美元和两美分;
我们的$备忘录=我的两分钱;

写;

格式STDOUT =
@<<<<<<< @<<<<<<<<<<<<<<<< @>>>>>>>>>>>>>>>>>>>>>>>>> ;>>>>
$ first,$ last,$ chkno
@<<<<<<<<< lt;<<<<<<<<<<< ;<<<<<<<<<<<<<<
$ addr [0]
@<< >> <<< << 1 < <<<<<<<<<<<<<日期:
$ addr [1]
@<<<<<<<<<<< <<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<
$ phone,$ date

支付给
的次序:@<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<<<<<<< <<<< @ #######。##
$ payee,$ amount
<<<<<<<<<<<<<<<<<<<<<<<<<<<< ;<<<<<<<<<<<<<<<<<<<<<<<<< ;<<<<<<<<<<<<<<<<<<
$ amount_str
签名
备忘:@ << ;<<<<<<<<<<< _________________________
$备忘录

也就是说,格式有一些非常糟糕的缺点,您应该使用不同的解决方案。另一个选择是使用 Perl6 :: Form 。这是Perl 6格式草案的回溯:

 #!/ usr / bin / perl 

使用严格;
使用警告;

使用Perl6 :: Form;

my $ first =Chas。;
my $ last =Owens;
my $ chkno =123456;
我的@addr =(123 Nowhere Lane,Citysville,Townshire,12345);
my $ phone =123-456-7890;
my $ date =2009-08-10;
my $ payee =Stack Overflow;
my $ amount =0.02;
my $ amount_str =不含两美分;
我的$备忘录=我的两分钱;

print form
{<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<¥¥¥¥¥¥¥¥¥其中: >>>>>>>>>>>>>>>",
$ first,$ last,$在这种情况下,可以使用以下公式来计算: addr [1],
{< <<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<}>,
$ phone,$ date,

支付给​​,
的订单:{<<<< LT;<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<< lt;>>>>>收款人$金额
;<<<<<<<<<<<<<<<<<<<<<<<<< ;
$ amount_str,
Signature,
Memo:{$ lt; $ lt; <<<<<<<<<<<<<<<<<<<<<<<<< <<<} _________________________;,
$ memo;


All,

I'm trying to get the code at the bottom to look like a check. Could you help me troubleshoot?

Thanks, Frank

format STDOUT = 
    @<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 
    $chkno                         $chkno                                                 
    $first                         $last                           
    $addr[0]                                                      
    $addr[1]                                                      
    $phone                         $date           

    Pay to the                                                    
    Order of: $payee               $amount         

    For: $memo                     Stamped Signature      

nova> perl proj3_3.pl
Use of comma-less variable list is deprecated at proj3_3.pl line 48.
Name "main::date" used only once: possible typo at proj3_3.pl line 24.
Name "main::last" used only once: possible typo at proj3_3.pl line 12.
Name "main::payee" used only once: possible typo at proj3_3.pl line 27.
Name "main::phone" used only once: possible typo at proj3_3.pl line 21.
Name "main::amount" used only once: possible typo at proj3_3.pl line 30.
Name "main::first" used only once: possible typo at proj3_3.pl line 9.
Name "main::memo" used only once: possible typo at proj3_3.pl line 33.
What is your Check Number? asdf
What is your First Name? asdf
What is your Last Name? adsf
What is your street address (i.e. 555 Anywhere St.)? asdf
What is your city, state, zip code (i.e. Los Angeles, CA, 90210)? as
What is your Phone Number? df
What is the Date? asdf
Who is the Payee? asd
What is the Check Amount? fa
What is the Check's Purpose (MEMO)? sdf
        asdf                                                     asdf
        $first                         $last
        $addr[0]
        $addr[1]
        $phone                         $date

        Pay to the
        Order of: $payee                           $amount

        For: $memo                     Stamped Signature
        .


format STDOUT_TOP =
--------------------------------------------------------------

Edit... Sorry, new to this. Here's my code:

#!/usr/bin/perl -w

use FileHandle

print "What is your Check Number? ";
chomp($chkno = <STDIN>);

print "What is your First Name? ";
chomp($first = <STDIN>);

print "What is your Last Name? ";
chomp($last = <STDIN>);

print "What is your street address (i.e. 555 Anywhere St.)? ";
chomp($addr[0] = <STDIN>);

print "What is your city, state, zip code (i.e. Los Angeles, CA, 90210)? ";
chomp($addr[1] = <STDIN>);

print "What is your Phone Number? ";
chomp($phone = <STDIN>);

print "What is the Date? ";
chomp($date = <STDIN>);

print "Who is the Payee? ";
chomp($payee = <STDIN>);

print "What is the Check Amount? ";
chomp($amount = <STDIN>);

print "What is the Check's Purpose (MEMO)? ";
chomp($memo = <STDIN>);

#print "? ";
#chomp($ = <STDIN>);
#print "? ";
#chomp($ = <STDIN>);

# @>>>> right-justified
#   @|||| centered
#   @####.## numeric field holder
#   @* multiline field holder

# now this line format will automatically apply to CHECK
format STDOUT = 
    @<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 
    $chkno                         $chkno                                                 
    $first                         $last                           
    $addr[0]                                                      
    $addr[1]                                                      
    $phone                         $date           

    Pay to the                                                    
    Order of: $payee               $amount         

    For: $memo                     Stamped Signature          
    .


# and this page header format will automatically apply to CHECK
format STDOUT_TOP =
--------------------------------------------------------------
.   

write STDOUT; #send to the output

解决方案

Formats consist of a format line followed by the variables that go in that line (comma separated):

#!/usr/bin/perl

use strict;
use warnings;

our $first      = "Chas.";
our $last       = "Owens";
our $chkno      = "123456";
our @addr       = ("123 Nowhere Lane", "Citysville, Townshire, 12345");
our $phone      = "123-456-7890";
our $date       = "2009-08-10";
our $payee      = "Stack Overflow";
our $amount     = "0.02";
our $amount_str = "no dollars and two cents";
our $memo       = "my two cents worth";

write;    

format STDOUT = 
 @<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<  @>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 
 $first,        $last,             $chkno
 @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 $addr[0]
 @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<        Date:
 $addr[1]
 @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<        @<<<<<<<<<<<<<<<<<<<<<<<
 $phone,                                 $date

Pay to the
Order of:  @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<  @#######.##
           $payee,                                    $amount 
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< dollars
$amount_str
                                        Signature
Memo: @<<<<<<<<<<<<<<<<<<<<<<<<<<<      _________________________         
      $memo
.

That said, formats have some really bad drawbacks and you should really use a different solution. Another option is to use Perl6::Form. It is a backport of the draft of formats for Perl 6:

#!/usr/bin/perl

use strict;
use warnings;

use Perl6::Form;

my $first      = "Chas.";
my $last       = "Owens";
my $chkno      = "123456";
my @addr       = ("123 Nowhere Lane", "Citysville, Townshire, 12345");
my $phone      = "123-456-7890";
my $date       = "2009-08-10";
my $payee      = "Stack Overflow";
my $amount     = "0.02";
my $amount_str = "no dollars and two cents";
my $memo       = "my two cents worth";

print form 
 "{<<<<<<<<<<<<<} {<<<<<<<<<<<<<<<<}  {>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}",
 $first,        $last,             $chkno,
 "{<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<}",
 $addr[0],
 "{<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<}        Date:",
 $addr[1],
 "{<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<}        {<<<<<<<<<<<<<<<<<<<<<<<}",
 $phone,                                 $date,
 "",
"Pay to the",
'Order of:  {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<}  ${>>>>>>>.<<}',
            $payee,                                     $amount,
"{<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<} dollars",
$amount_str,
"                                        Signature",
"Memo: {<<<<<<<<<<<<<<<<<<<<<<<<<<<}      _________________________",
       $memo;

这篇关于为什么我的Perl格式不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆