2009-08-10 5 views
0

Alle,Warum funktioniert mein Perl-Format nicht?

Ich versuche, den Code auf der Unterseite wie ein Scheck aussehen zu lassen. Können Sie mir bei der Fehlersuche helfen?

Danke, 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 = 
-------------------------------------------------------------- 

Bearbeiten ... Sorry, neu in diesem. Hier ist mein 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 
+1

Keine Möglichkeit, wirklich zu wissen, was ohne den Eingabeabschnitt falsch läuft. – chaos

+0

Wir müssen mehr Code sehen als Sie zeigen. –

+1

Format ist wie, total veraltet. Vermeiden. – jrockway

Antwort

4

Formate einer Formatzeile bestehen durch die Variablen gefolgt, die in dieser Zeile gehen (durch Komma getrennt):

#!/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 
. 

Das heißt, Formate haben ein paar wirklich schlechte Nachteile und Sie sollten verwende wirklich eine andere Lösung. Eine andere Möglichkeit ist die Verwendung von Perl6::Form. Es ist ein Backport des Entwurfs der Formate für 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; 
+0

Hey, bist du * auch * aus Citysville, Townshire? Wie geht es dir, Nachbar? –

+0

Chas, Sie waren eine große Hilfe! Können Sie mir helfen, Benutzereingaben hinzuzufügen? Die Zuordnung erforderte Folgendes: Schreiben Sie ein Programm, das eine Prüfung generiert. Das Häkchen sollte auf dem Bildschirm so gedruckt werden, wie es in der angehängten Datei (check.txt) erscheint. Ihr Programm muss den Benutzer auffordern, die folgenden Informationen einzugeben. Ordnen Sie die Benutzerdaten den Skalar- und Array-Variablen zu, die alle unten aufgeführt sind. Sie müssen Formate verwenden, um den Scheck so auszudrucken, wie er angezeigt wird. Dazu gehört das Zeilenfeld, das die Scheckpositionen umgibt. –

+2

@Frank das klingt verdächtig wie Hausaufgaben oder eine Interviewfrage. Ich würde vorschlagen, die Formatdokumentation zu lesen (siehe den Link in der Antwort oder 'perldoc perlform'). –

Verwandte Themen