1 / 25

Chapter 20 Email, Files, CGI.pm

Chapter 20 Email, Files, CGI.pm. The Computer Survey page contains an example of every form element. Chapter 20 Hash of Arrays, I. Encoded Fields Storage Representation title=Ms $hash{'title'}[0]="Ms"; First=Penny $hash{'First'}[0]="Penny";

zody
Download Presentation

Chapter 20 Email, Files, CGI.pm

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 20 Email, Files, CGI.pm The Computer Survey page contains an example of every form element.

  2. Chapter 20 Hash of Arrays, I Encoded Fields Storage Representation title=Ms$hash{'title'}[0]="Ms"; First=Penny$hash{'First'}[0]="Penny"; Last=Opossum$hash{'Last'}[0]="Opossum"; Address=323+River+Rd.\n $hash{'Address'}[0]="323 River Muskrat+MoundsRd.<BR>Muskrat Mounds"; Mac=on $hash{'system'}[0]="Mac"; Linux=on$hash{'system'}[1]="Linux";

  3. Chapter 20 Hash of Arrays Encoded Fields Storage Representation languages=Perl $hash{'languages'}[0]="Perl"; language=CPP $hash{'languages'}[1]="C++"; languages=HTML $hash{'languages'}[2]="HTML"; languages=Java $hash{'languages'}[3]="Java"; languages=JavaScript $hash{'languages'}[4] ="JavaScript"; years=Six+to+ ten+years $hash{'years'}[0]= "Six to ten years";

  4. Chapter 20 Email Version Delivered-To: Recipient@Email.address Date Fri, 13 Oct 2000 10:52:59 -0500 From: Sender@Email.address Mime-Version: 1.0 The completed form information is: Ms Penny Opossum 323 River Rd. Muskrat Mounds Years of Experience: Six to ten years Language Knowledge: C++ HTML Java JavaScript Perl System Experience: Mac Linux

  5. Chapter 20 Email Version 1. Open a File Handle.open(MAIL, "|mail mmusk\@musk.rat.com"); 2. Print to the Email File.print MAIL, “My name is Penny.\n”; 3. Close the File.close(MAIL);

  6. Chapter 20 Reading Files The poem.txt file is written toa page.

  7. Chapter 20 Reading Files 1. Open a File Handle.open(FILE, $name); 2. Read the File.@FileInfo = <FILE>; 3. Close the File.close(FILE); The file reading operator, <>, reads the file into an array.

  8. Chapter 20 The read_file() Subroutine sub read_file {#read the information from the file my($name) = @_; my (@FileInfo); open(FILE, $name); #1 @FileInfo = <FILE>; #2 close(FILE); #3 return @FileInfo; }

  9. Chapter 20 Writing Files The Suggestion Box page writes the new suggestion to a file and then reads and displays the file.

  10. Chapter 20 Writing Files 1. Open a File Handle.open(FILE, “>$name”); Oropen(FILE, “>>$name”); 2. Print to the File.foreach $line(@contents_ref) {print FILE $line;} 3. Close the File.close(FILE); Create a new file. Append to an existing file.

  11. Chapter 20 CGI.pm Basics Invoking the CGI.pm Module Methods Group Approach use CGI qw/methods group/; $title = param("title"); Object-Oriented Approach use CGI; $form = CGI::new(); $title = $form->param("title");

  12. Chapter 20 Method Groups Method Group Purpose :all Complete package :cgi CGI methods :form HTML form methods :html All HTML methods :html2 All HTML 2.0 methods :html3 All HTML 3.0 methods :netscape All Netscape Extensions :standard HTML 2.0, Form, and CGI methods

  13. Chapter 20 Using CGI.pm #!/usr/local/bin/perl use CGI qw/:standard/; ... print param("title"); print param("First"); print " "; print param("Last"); print “<BR>”; print param("Address"); ... This code prints a portion of the Computer Survey page using CGI.pm

  14. Chapter 20 CGI.pm Form Functions startform(-name=>'form name', -method=>'GET' | 'POST', -action=>'script name', -target=>'frame name', -encoding=>'encoding scheme'); Put the form elements here endform();

  15. Chapter 20 CGI.pm: Text Fields textfield(-name=>'name', -default =>'value', -size=>'number', … -onChange=>'function', -onFocus=>'function' -onBlur=>'function' -onSelect=>'function');

  16. Chapter 20 CGI.pm: Text Fields HTML CGI.pm <INPUT TYPE="text" print $form->textfield( NAME="First" -name=>'First', SIZE="7">-size=>'7'); <INPUT TYPE="text" print $form->textfield( NAME="Last" -name=>'Last', SIZE="12"> -size=>'12');

  17. Chapter 20 CGI.pm: Text Areas textarea(-name=>'name', -default =>'value', -size=>'number', -rows=>'number', -columns=>'number', -wrap=>'wrap style', -onChange=>'function', -onFocus=>'function' -onBlur=>'function' -onSelect=>'function');

  18. Chapter 20 CGI.pm: Radio Buttons radio_group(-name=>'name', -values=>\@values, -default=>'selected value', -labels=>\%hash);

  19. Chapter 20 CGI.pm: Radio Buttons honorific = ("Mr","Mrs", "Miss","Ms", "Dr"); print $form->radio_group( -name =>'title', -values=>\@honorific);

  20. Chapter 20 CGI.pm: Checkboxes checkbox(-name=>'name', -checked=>'checked value', -value=>'value', -label=>'label name');

  21. Chapter 20 CGI.pm: Checkboxes @system = ("PC", "Mac", "Linux", "Unix", "Other"); foreach $element(@system) { print $form->checkbox( -name=>$element, -label=>$element); }

  22. Chapter 20 CGI.pm: Buttons button(-name=>'name', -value=>'button label', -onClick=>'function'); submit(); reset();

  23. Chapter 20 CGI.pm: Select Lists scrolling_list(-name=>'name', -values=>\@option names, -default=>'selected option', -size=>'number', -multiple=>'true', -labels=>\%label names, -onFocus=>'function' -onBlur=>'function' -onSelect=>'function');

  24. Chapter 20 CGI.pm: Multiple-Select Lists @language_list =("Ada", "Algol", "C", "CPP", "Fortran", "HTML","Java", "JavaScript", "Logo", "Lisp", "Modula", "Pascal", "Perl", "Prolog", "Scheme", "Snobol", "Other"); $label{"CPP"} = "C++"; print $form->scrolling_list( -name=>'languages', -values=>\@language_list, -size=>'8', -multiple=>'true', -labels=>\%label, -default=>"HTML");

  25. Chapter 20 CGI.pm: Single-Select Lists @years = ("Less than one year", "One to five years", "Six to ten years", "More than ten years"); print $form->scrolling_list( -name=>'years', -values=>\@years);

More Related