Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl (http://www.velocityreviews.com/forums/f17-perl.html)
-   -   perl newbie (http://www.velocityreviews.com/forums/t24780-perl-newbie.html)

Gunnar Hjalmarsson 01-24-2004 06:45 AM

Re: perl newbie
 
ABE wrote:
> How to open or read a file passed as a parameter.
>
> Example. myperl.pl myconfigfile
>
> $cfgfile = ***** what to put here.....


my ($cfgfile) = @ARGV;

See perldoc perlvar

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


Jürgen Exner 01-24-2004 06:45 AM

Re: perl newbie
 
ABE wrote:
> How to open


perldoc -f open

> or read a file


You could use
perldoc -f read

But I would suggest to use the more standard method of processing the file
line by line
while (<MyFile>) {
# do whatever you want with each line, to be found in $_
}

> passed as a parameter.


> Example. myperl.pl myconfigfile
>
> $cfgfile = ***** what to put here.....


Do you want to access the value of the parameter?
$cfgfile = $_[0];
However, that would be just the file name, not the file itself.
Further details please see 'perldoc perlvar'.

> if ( -e $cfgfile )


Well, I guess you weren't looking for how to open or read a file after all.
You just wanted to know how to access command line parameters. Why all the
fuzz about files and opening and reading?

jue



Jürgen Exner 01-24-2004 06:50 AM

Re: perl newbie
 
Jürgen Exner wrote:
> Do you want to access the value of the parameter?
> $cfgfile = $_[0];


Ooops, sorry, that should have been
$cfgfile = $ARGV[0];

jue



Gunnar Hjalmarsson 01-24-2004 06:53 AM

Re: perl newbie
 
Jürgen Exner wrote:
> ABE wrote:
>>Example. myperl.pl myconfigfile
>>
>>$cfgfile = ***** what to put here.....

>
> Do you want to access the value of the parameter?
> $cfgfile = $_[0];


Suppose you mean

$cfgfile = $ARGV[0];

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


ABE 01-24-2004 11:03 PM

perl newbie
 
How to open or read a file passed as a parameter.

Example. myperl.pl myconfigfile

$cfgfile = ***** what to put here.....

if ( -e $cfgfile )
{
print "Ok\n";
}
else
{
print "Not found.\n";
}






All times are GMT. The time now is 08:39 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.