Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Variable interpolation on STDIN ?

Reply
Thread Tools

Variable interpolation on STDIN ?

 
 
Michele Dondi
Guest
Posts: n/a
 
      08-03-2004
On 3 Aug 2004 11:44:41 GMT, Julius Plenz <> wrote:

>> I tried $ENV{HOME}/x.pl also, but it also gave the same error :

>
>Did you also try "$ENV{HOME}/x.pl"?


He means that he tried writing that ON STDIN, not literally in the
program source...


Michele
--
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
"perl bug File::Basename and Perl's nature"
 
Reply With Quote
 
 
 
 
Andrew Palmer
Guest
Posts: n/a
 
      08-04-2004

Here's another thought. If you want true shell-like evaluation, you could
literally pass your input to the shell.

> my $fileToCheck = <STDIN>;


$fileToCheck=`echo $fileToCheck`;

> chomp ($fileToCheck);
> if (-e $fileToCheck)
> {
> print "Not Found\n";
> }


This should expand "~" as well as expand environment variables and do other
shell things. However, this is kind of quick and dirty. Not as safe as

$fileToCheck =~ s/\$(\w+)/$ENV{ $1}/g;


>
> The problem is that I want to allow the user to specify the file with
> environment variables in some way. For example, to check if x.pl is

present
> under the home directory, the user should be able to give
>
> $HOME/x.pl
>
> However, it seems that we cannot interpolate like this while reading from
> STDIN (or from a file)? Am I missing something ?
>
> I tried $ENV{HOME}/x.pl also, but it also gave the same error :
>
> No such file or directory
>
> TIA
>
> --
> Abhinav




 
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
peek at stdin, flush stdin Johnathan Doe C Programming 5 4 Weeks Ago 04:30 PM
How to pass stdin of a C++ program to the stdin of a process createdwith ShellExecute() Ben C Programming 2 08-29-2009 09:47 PM
STDIN, OUT, ERR and $stdin, out, err - Differences? Terry Cooper Ruby 7 06-09-2009 05:48 AM
Variable Interpolation with %%variable phrankster Perl Misc 9 08-14-2005 12:19 AM
Reading stdin once confuses second stdin read Charlie Zender C Programming 6 06-21-2004 01:39 PM



Advertisments