Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: read file from ARGV

by nithins (Sexton)
on Feb 02, 2013 at 07:33 UTC ( #1016667=note: print w/replies, xml ) Need Help??

in reply to read file from ARGV

hope the below code will b helpful for you

#!/usr/bin/perl use strict; use warnings; my @a; open (FH,'<',$ARGV[0]); #or @ARGV[0] while(<FH>) { push(@a,$_); } print "@a";

Replies are listed 'Best First'.
Re^2: read file from ARGV
by 2teez (Vicar) on Feb 02, 2013 at 09:13 UTC

    Hi nithins,
    I think it would be a good practice to check the return of open function and to also close an opened filehandles like

    open my $fh,'<',$ARGV[0] or die "can't open file: $!"; ... close $fh or die "can't close file: $!";
    Except one is doinguse autodie qw(open close);

    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1016667]
[Discipulus]: marto apotropaic gestures in Eataly..
[Discipulus]: LanX nick does not downvote peoples, just content he dislike (I think)
[Discipulus]: anyway I have my Tk toys running at 50%!! someone want to see it?
[LanX]: disc+ true every node authored by me or mentioning Perl 6 ;)
[Discipulus]: naahh..
[LanX]: oh a tunnel ...
LanX ducks!
marto quacks

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2018-04-26 10:29 GMT
Find Nodes?
    Voting Booth?