Hi guys,
Am pretty new to perl and wanted to export the last value of $last. But it doesn't work. Could you help?
ps: I just wanted to make the equivalent of a Unix "tail -1"
thanksuse CGI qw(:standard); use strict; use utf8; my $srce = "/some/file"; my $string1 = "some-regex"; my $last; open my $fh, $srce or die "Could not open $scre: $!"; my @lines = grep /\Q$string1/, <$fh>; foreach my $line (@lines) { my @fields = split /\s+/, $line; $last= $fields[3]; } print "$last";
In reply to export variable outside foreach by mitchreward
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |