Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > perl newbie

Reply
Thread Tools

perl newbie

 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      01-24-2004
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

 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      01-24-2004
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


 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      01-24-2004
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


 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      01-24-2004
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

 
Reply With Quote
 
ABE
Guest
Posts: n/a
 
      01-24-2004
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";
}




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ 2.17 What is perl.com? Perl Mongers? pm.org? perl.org? cpan.org? PerlFAQ Server Perl Misc 0 04-04-2011 10:00 PM
FAQ 1.4 What are Perl 4, Perl 5, or Perl 6? PerlFAQ Server Perl Misc 0 02-27-2011 11:00 PM
FAQ 2.17 What is perl.com? Perl Mongers? pm.org? perl.org? cpan.org? PerlFAQ Server Perl Misc 0 02-03-2011 11:00 AM
FAQ 1.4 What are Perl 4, Perl 5, or Perl 6? PerlFAQ Server Perl Misc 0 01-23-2011 05:00 AM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 AM



Advertisments