PREE HW#7 - 1. #!/usr/local/bin/perl #This program prints a...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1. #!/usr/local/bin/perl #This program prints a string vertically $" = " \n"; $str = <STDIN>; @str = split(//,$str); print("@str") 2. #!/usr/local/bin/perl -w #This program prints a string with a space between each character $" = " \n"; $str = <STDIN>; @str = split(//,$str); $str = join(" ",@str); print($str); #End 3. #!/usr/local/bin/perl #This program reads a file made of two colums (numbers) and prints them in order while(<STDIN>) { ($num1, $num2) = split; if($num1 < $num2) { print("$num1 $num2 \n"); } else { print("$num2 $num1 \n"); } }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4. #!/usr/local/bin/perl #This program reads a file made of columns and prints the last column. while(<STDIN>) { @columns = split; print("$columns[$#columns] \n"); } #End 5. #!/usr/local/bin/perl #This program reads a file made of columns and swaps the first and the last columns. while(<STDIN>) { @columns = split; @columns[$#columns, 0] = @columns[0, $#columns]; print("@columns \n"); } #End 6. #!/usr/local/bin/perl -w
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

PREE HW#7 - 1. #!/usr/local/bin/perl #This program prints a...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online