Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Match on xx followed by 2 numbers ....

Status
Not open for further replies.

sumncguy

IS-IT--Management
May 22, 2006
118
US
I want to be able to branch if $mod[1] = 1700 or 1720 or 1760 or 17.....



if(defined($mod[1])) {
if($mod[1] =~ m{1720}) {
print "$mod[1]\n ";
}

the above works. but neither of the two below do.


if(defined($mod[1])) {
if($mod[1] =~ m{^17,\{2}\}) {
print "$mod[1]\n ";
}

if(defined($mod[1])) {
if($mod[1] =~ m{^17}) {
print "$mod[1]\n ";
}

Forgot me dang blasted book at home ...

tks

 
what about just:

if($mod[1]=~ /^17\d{2}/) {
print "$mod[1]\n";
}
 
How about:
m!17[0-9][0-9]!
or
m!17\d\d!
or
m!17\d{2}!


I hope that helps

Mike
 

If I use
if($mod[1]=~ /^17\d{2}/) {
print "$mod[1]\n";
}

I get this :

Use of uninitialized value in pattern match (m//) at pdh line 40, <AUTO> line 444.
Use of uninitialized value in pattern match (m//) at pdh line 40, <AUTO> line 445.
Use of uninitialized value in pattern match (m//) at pdh line 40, <AUTO> line 446.

Then this :

1721
1721
1721
1721
1721
1721
1721
1721
1721
1721
1721
1721

I believe that the unintialized value is given when @model has nothing in it as defined by a separate statememt

if ($line =~ /^cisco.*ry/) {
@mod = split (/ /, $line);
print "$ip $hn[1] $mod[1] $mod[7] \n";
}


But this works pretty good .....so far ..such a perl rookie I am. Im ok at shell ... just wanting to give perl a nudder werl ... but I thinks shell is friendlier ....

if(defined($mod[1])) {
if($mod[1] =~ m{^17|^26|^25|^36|4700}) {
print "$mod[1]\n ";
}
}


 
Yes....I was assuming that you were still going to wrap the if statement within your other one that checks to see if it was defined :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top