in reply to Printing Stacks
A little rewrite using DATA instead of an external file and a loop.
use strict; use warnings; #my ($a, $b, $c, $d, $e); my $file = "data.txt"; #open(my $fh,'<', $file) or die "can't open $file $!"; #my @stack = <$fh>; my @stack = <DATA>; #chomp @stack; #$a = pop @stack; #print $a . "\n"; #$b = pop @stack; #print $b . "\n"; #$c = pop @stack; #print $c . "\n"; print while defined ($_ = pop @stack); __DATA__ line 1 line 2 line 3 line 4
Result:
line 4 line 3 line 2 line 1
See also: reverse and File::ReadBackwards.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Printing Stacks
by drose2211 (Sexton) on Mar 27, 2018 at 02:38 UTC | |
by hippo (Archbishop) on Mar 27, 2018 at 07:56 UTC | |
by drose2211 (Sexton) on Mar 27, 2018 at 14:33 UTC |