by rob.dixon@[EMAIL PROTECTED]
(Rob Dixon)
Apr 28, 2008 at 06:56 PM
Richard Lee wrote:
>
> I would imagine linux's head command can be replaced w/ chop
> I asked this because I have a filehandle which was,
>
> open $source, '/tmp/server.txt' ( and no doing head -1 /tmp/server.txt
> is not an option since I need to go through some other stuff
> before i need to issue below command )
>
> and I wanted to do
>
> my $top = `head -1 $source`
> my $bottom = `tail -1 $source`
>
> but I realized I cannot do $source in back tick.
>
> so I imagine i can do
>
> my $top = chop $source;
>
> But what about the $bottom one?
The chop() function simply removes the last character from a string and
returns it. Since $source isn't a string you would get an error. Your best
bet is likely to be the Tie::File module. For instance
use strict;
use warnings;
use Tie::File;
tie my @[EMAIL PROTECTED]
'Tie::File', '/tmp/server.txt' or die $!;
my ($top, $bottom) = @[EMAIL PROTECTED]
-1];
HTH,
Rob