Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to resolve parameter read from text file in perl script

Reply
Thread Tools

How to resolve parameter read from text file in perl script

 
 
Gancy
Guest
Posts: n/a
 
      02-09-2005
Hi All,
I have a perl script which reads parameters from text file and builds
the command line string for another perl script. and i intend to
execute the same with systm command.

parameter file would look Something like this

Parameter file:
description=1
log=0
outputdir=~gancy/testsource
scandir=pwd

perl script reads this and builds commnad line and calls the system
command.

if i print the string would look like
print $CmdLine;

perl BinaryParser.pl -d ~gancy/testsource pwd

system("$CmdLine");

but the problem is system command does not resolve ~ and pwd.

I have tried same in C, it works exactly as i want. Even i tried to
fork antoher process.

any suggestions

Thanks
Ganesh Tiwari

 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      02-09-2005
Gancy wrote:
> I have a perl script which reads parameters from text file and builds
> the command line string for another perl script. and i intend to
> execute the same with systm command.


<snip>

> print $CmdLine;
>
> perl BinaryParser.pl -d ~gancy/testsource pwd
>
> system("$CmdLine");
>
> but the problem is system command does not resolve ~ and pwd.


Why are you using system() to invoke another Perl script? Why not

@ARGV = qw(-d ~gancy/testsource pwd);
do 'BinaryParser.pl';

or to also check for errors

defined do 'BinaryParser.pl' or die $!;

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
 
 
 
nobull@mail.com
Guest
Posts: n/a
 
      02-09-2005

Gunnar Hjalmarsson wrote:
> Gancy wrote:
> > system("$CmdLine");
> >
> > but the problem is system command does not resolve ~ and pwd.

>
> Why are you using system() to invoke another Perl script?


He is using it to resolve ~.

 
Reply With Quote
 
nobull@mail.com
Guest
Posts: n/a
 
      02-09-2005

Gancy wrote:

> if i print the string would look like
> print $CmdLine;
>
> perl BinaryParser.pl -d ~gancy/testsource pwd
>
> system("$CmdLine");
>
> but the problem is system command does not resolve ~ and pwd.


What do you mean by 'resolve pwd'? The string 'pwd' does not contain
any shell metacharacters.

> I have tried same in C, it works exactly as i want.


Works here for me with perl5.6.1 and 5.8.5 on Linux.

What's your perl -V ?

Have you read 'perldoc -q tilde' ?

 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      02-09-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Gunnar Hjalmarsson wrote:
>> Gancy wrote:
>>> system("$CmdLine");
>>>
>>> but the problem is system command does not resolve ~ and pwd.

>>
>> Why are you using system() to invoke another Perl script?

>
> He is using it to resolve ~.


Aha, thanks!

So, a new attempt at a pure Perl solution:

use FindBin '$Bin';
@ARGV = qw(-d ~gancy/testsource pwd);
map { s#~#/home/#; s/pwd/$Bin/ } @ARGV;
do 'BinaryParser.pl';

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
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
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
unable to resolve template parameter Noah Roberts C++ 6 12-08-2009 07:41 AM
read a ruby script like you would read a text file Mmcolli00 Mom Ruby 2 01-27-2009 10:52 PM
src-resolve: Cannot resolve the name ... ivanet@gmail.com XML 1 03-23-2007 12:10 PM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 AM



Advertisments