Perl user login for unix command

Can someone please help me with what I'm doing wrong here, scratching my head a bit. I don't know much perl, just making a small change to the irssi script.

$selectedname = <STDIN>; $Nameslist = `grep -i -w '$selectedname'~/file`; 

It works correctly with the problem I am facing, it looks like the variable is not inserted correctly. For example, if I type the same command using a word test on the command line, I get 3 lines that appear. But if I use the same word with this script, it becomes empty.

I know that it works correctly, because I can do * as input, and it will show me the whole file. It just does not work with the entered lines.

Any help would be greatly appreciated, it really pounded me.

+6
source share
1 answer

In fact, when you use <STDIN> , a new line character appears. therefore you need to remove the new character string. you can use chomp to remove a new line character

The code:

  $selectedname = <STDIN>; chomp($selectedname); $Nameslist = `grep -i -w '$selectedname'~/file`; 
+1
source

All Articles