Match in perl not working with ARGV


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Match in perl not working with ARGV
# 1  
Old 11-08-2013
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.

Last edited by dll_fpga; 11-08-2013 at 02:16 PM..
# 2  
Old 11-08-2013
Try putting $ character in front of the variable name (BTW, first argument is $ARGV[0], not $ARGV[1]):
Code:
~m/module(\s+)$ARGV[0](\s+)\(/

# 3  
Old 11-08-2013
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.
# 4  
Old 11-08-2013
Can you show more of your code?
# 5  
Old 11-08-2013
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

Last edited by Scott; 11-08-2013 at 03:26 PM.. Reason: Code tags
# 6  
Old 11-08-2013
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...
# 7  
Old 11-08-2013
Quote:
Originally Posted by bartus11
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.
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

Last edited by Scott; 11-08-2013 at 03:26 PM.. Reason: Code tags, please
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl sys.argv issue

I am running a perl script and reading the arguments passed to the script as below..... resembles more arguments. java weblogic.WLST /web/update.py 34 56 .... I am trying to print the arguments passed to the update.py script as below for arg in sys.argv: print "other args:", arg... (1 Reply)
Discussion started by: mohtashims
1 Replies

2. Shell Programming and Scripting

Match working for some but not all

I am not sure why the script below seems to pull the correct values for most, but not all. Basically what is supposed to result is the $1 value in genes.txt is matched to the $3 value in RefSeqGene.txt and the value in 6 field is copied. In the output below that is the case most of the time but... (3 Replies)
Discussion started by: cmccabe
3 Replies

3. Shell Programming and Scripting

Wildcarding in a Perl @ARGV Context?

Hello folks! While "sedding" about again, I ran into this little conundrum du jour:#!/usr/bin/perl use strict; use warnings; use diagnostics; @ARGV = ('./afile.dat', './*.txt'); $^I = ''; while (<>) { s/Twinkies/Dinner/g; print; }When run, perl complains,...but, of... (2 Replies)
Discussion started by: LinQ
2 Replies

4. Shell Programming and Scripting

Wildcarding in a Perl @ARGV Context?

Hello folks! While "sedding" about again, I ran into this little conundrum du jour:#!/usr/bin/perl use strict; use warnings; use diagnostics; @ARGV = ('./afile.dat', './*.txt'); $^I = ''; while (<>) { s/Twinkies/Dinner/g; print; }When run, perl complains,...but, of... (1 Reply)
Discussion started by: LinQ
1 Replies

5. UNIX for Advanced & Expert Users

O argv, argv, wherefore art thou argv?

All of my machines (various open source derivatives on x86 and amd64) store argv above the stack (at a higher memory address). I am curious to learn if any systems store argv below the stack (at a lower memory address). I am particularly interested in proprietary Unices, such as Solaris, HP-UX,... (9 Replies)
Discussion started by: alister
9 Replies

6. Shell Programming and Scripting

exact match in Perl

Hi By using select clause I'm trying to pull out the rows to a variable. If the variable has 0 row(s) selected then i'm printing some text message else printing some other text message if($xyz =~ m/0 row/) { print "0 rows "; } else { print " There are rows"; } By my problem... (4 Replies)
Discussion started by: pdreddy34
4 Replies

7. Shell Programming and Scripting

how to include slashes "/" in @ARGV (Perl)

Hello I have simple script that will accept as arg string like this : ".../foo/blah/,.../.../foo1/,.../blah" now perl automatically removes the slashes "/" , I can't escape the slashes in the input I have to control on it so how can I force perl to not touch this slashes? Thanks ... (5 Replies)
Discussion started by: umen
5 Replies

8. Shell Programming and Scripting

perl exact match

How to emulate grep -o option in perl. I mean to print not all line, only the exact match. echo "2A2 BB" | perl -ne 'print if /2A2/' 2A2 BB I want to print only 2A2. (2 Replies)
Discussion started by: mirusnet
2 Replies

9. Shell Programming and Scripting

Perl: Getting $ARGV's to operate like while(<>)

I have a script that asks a bunch of questions using the following method for input: print "Name:"; while(<>){ chomp; $name=$_; } So for example, if the questions asked for name, age, & color (in that order)... I want to be able to easily convert $ARGV into the input expected by... (2 Replies)
Discussion started by: jjinno
2 Replies

10. Shell Programming and Scripting

RegExp negative match not working

or I don't know how to make it work ... Hello im trying to build regexp that will match me single string or function call inside of brackets for example I have : <% myFunction("blah",foo) %> or <% myVar %> and not match : <% if(myFunction("blah",foo)==1) %> or <% while(myvar < 3){... (2 Replies)
Discussion started by: umen
2 Replies
Login or Register to Ask a Question