Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Basic I/O Exercises

by vroom (His Eminence)
on Nov 17, 1999 at 02:51 UTC ( [id://994]=perlmeditation: print w/replies, xml ) Need Help??

Basic I/O Exercises

  1. Write a program which asks the user for his/her first name and last name, and then prints out a line of text welcoming him/her using the given names. (solution)
  2. Write a program which reads lines until it reads a "." on a line by itself, then prints out all of the lines it has read in reverse order. (solution)

Replies are listed 'Best First'.
Basic I/O #2
by vroom (His Eminence) on Nov 17, 1999 at 03:06 UTC
    # Read lines until a line consisting only of "." is seen. # Then print the lines back out in the opposite order. my @lines; while ( $line = <> and $line ne ".\n" ) { push @lines, $line; } foreach ( reverse @lines ) # only reverses the list used by foreach; d +oes not modify the array { print; }
Basic I/O #1
by vroom (His Eminence) on Nov 17, 1999 at 03:02 UTC
    # prompt for and read First and Last name, then print a welcome messag +e. print "\nWhat is your first name? "; my $first = <>; print "\nWhat is your last name? "; my $last = <>; chomp $first; # strip the newline from the first name print "Welcome $first $last";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://994]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (1)
As of 2024-04-25 04:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found