Match in perl not working with ARGV

Hi ,

I need to match module data_tx_dig (

I tried matching
~m/module(\s+)ARGV[1](\s+)\(/ --> (generic code)but is not working.The same is able to match when i provide hardcoded value instead of passing from the command line.
~m/module(\s+)data_tx_dig(\s+)\(/ -->(hardcoded code).Please help me fix this.

Try putting $ character in front of the variable name (BTW, first argument is $ARGV[0], not $ARGV[1]):

~m/module(\s+)$ARGV[0](\s+)\(/

hi bartus ,Thanks for the reply

i tried ~m/module(\s+)$ARGV[1](\s+)\(/ but still not working..I know ARG[0] and ARG[1] are first and second arguments ,ARG[1] was intentionally given in my script.

Can you show more of your code?

chomp($ARGV[1]);
open(FH1,"<$ARGV[0]");
  while(<>){
    if ($_=~m/module(\s+)$ARGV[1](\s+)\(/)
      print $_;
  }
}
close FH1;

sorry this is my actual code.made a typo

Wait... so you want to pass the word to be matched as the first of the second parameter? The match operator contains "$ARGV[0]", which you also use as filename in the "open" function. Additionally, this: chomp($ARG[1]); should probably be: chomp($ARGV[1]);
Why are you opening a file - open(FH1,"<$ARGV[0]"); , when you are not reading from it - while(<>){ - this reads from STDIN...

sorry please check my edited code.

chomp($ARGV[1]);
open(FH1,"<$ARGV[0]");
while(<>){
if ($_=~m/module(\s+)$ARGV[1](\s+)\(/)
print $_;
}
}
close FH1;

im reading from file ARGV[0] while searching for ARGV[1] pattern

You are not reading from $ARGV[0]. To read from that file you have to specify it's file handle in the diamond operator: while(<FH1>) {

It worked fine.Thanks a lot ,i would be grateful to u.wasted a lot of time,out of my laziness in specifying the file pointer.