Gossamer Forum
Home : General : Perl Programming :

One more read issue

Quote Reply
One more read issue
Hello,

it may be a simple question to you, i just need to read a line from terminal and have to assign to a a variable the command i used was



`read $read2`;

after executing the program it prompts for input, but it doesnot assign to a variable, when i print the $read2 nothing comes out.

Do i am using a wrong command? please suggest me what to do.

With regards,

Bijoy Babu
Quote Reply
Re: [bijoybabu] One more read issue In reply to
Use qx// for obtaining output and system() for something that doesn't return output.

my $var = qx/some command/;
Quote Reply
Re: [Paul] One more read issue In reply to
That too failed,

i tried as follows

my $read2 = qx/`read read2`/;

print $read2;

nothing come out, just asked the input after input without printing anything it returned.

do u know what may be the reason?

With regards,

Bijoy Babu
Quote Reply
Re: [bijoybabu] One more read issue In reply to
Don't put the backticks in there too. qx// is a replacement for the backticks.

Last edited by:

Paul: Dec 19, 2002, 12:44 PM
Quote Reply
Re: [Paul] One more read issue In reply to
that too didn't help, thanks for your efforts, i am attaching my code here, may be it will helpfull to you for identifing the error


my $read2 = qx/read read2/;
print "this is the value --", $read2;



funny thing is if i use just a batch job as

read read2

printf "%s" $read2

it will print what i typed, but if i use the perl it is not taking.Is it our system problem? just using the two lines, are u getting the print value in your system?





With regards,

Bijoy Babu
Quote Reply
Re: [bijoybabu] One more read issue In reply to
Will the perl implementation not do what you need?

http://www.perldoc.com/perl5.6/pod/func/read.html
Quote Reply
Re: [Paul] One more read issue In reply to
Thanks Paul, that worked, so i was using a wrong synthax. NOW i can use it in my progrmas,

Happy Chirstmas to you,



Bijoy Babu.
Quote Reply
Re: [bijoybabu] One more read issue In reply to
The 'read' you're using is a shell command - forget that (unless you want to write a shell script instead of Perl...).

The simplest way to read a line in Perl is:

my $input = <STDIN>; # Read one whole line into $input
chomp($input); # remove the newline character

Cheers,
Dave.