mitchreward has asked for the wisdom of the Perl Monks concerning the following question:
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";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: export variable outside foreach
by Eily (Monsignor) on Jun 19, 2014 at 08:38 UTC | |
|
Re: export variable outside foreach
by Anonymous Monk on Jun 19, 2014 at 08:29 UTC | |
by mitchreward (Acolyte) on Jun 19, 2014 at 08:34 UTC | |
by Anonymous Monk on Jun 19, 2014 at 08:47 UTC | |
by roboticus (Chancellor) on Jun 19, 2014 at 13:01 UTC | |
by Eily (Monsignor) on Jun 19, 2014 at 08:43 UTC | |
by AnomalousMonk (Archbishop) on Jun 19, 2014 at 09:10 UTC | |
by Eily (Monsignor) on Jun 19, 2014 at 09:18 UTC | |
|
Re: export variable outside foreach
by philipbailey (Curate) on Jun 19, 2014 at 15:36 UTC |