Re: maching end of a line with $

2003-04-06 Thread Jose Malacara
Thanks for the help! You are correct, a string equality test is easier.
My main problem was that I realized that I wasn't splitting my line of
input (containing the IP addresses and other values) before I was trying
to match, so I had:

if ($array[0] eq $value) {
@array = split(/,/, $line);


instead of:

@array = split(/,/, $line);
if ($array[0] eq $value) {


This was causing my match to fail because it was trying to match against
the entire line of input instead of just the IP.

Thanks to all that helped.

Jose


On Fri, 2003-04-04 at 17:54, Wiggins d'Anconia wrote:
 Jose Malacara wrote:
  Can someone help me out here, please.
  
  I have an if statement that is looping over a list of IP addresses:
  
  192.168.1.1
  192.168.1.2
  192.168.1.3 ...192.168.1.10
  
  $value=192.168.1.1
  
  if ($line =~ /($value)/) ...
  
  I only want to match the value exactly (192.168.1.1). My problem is that I am 
  matching all addresses containing that string (192.168.1.10, 192.168.1.11, 
  192.168.1.100, etc...)
  
 
 In the case of an exact match why not just use string equality test? 
 (don't forget to 'chomp' the line if you are getting it from a filehandle)
 
 if ($line eq $value) 
 
  I know the trailing '$' anchors the match to the end of the line only, but I 
  cannot seem to get it to work as I think my syntax is incorrect.
  
 
 What trailing '$' you don't have one in the code you posted above...if 
 you insist on the regex, it would go something like:
 
 if ($line =~ /^($value)$/) 
 
 Which says match $value (and set it to $1) starting at the beginning of 
 the string '^' and going until the end of the string '$'.
 
 http://danconia.org
 
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



maching end of a line with $

2003-04-04 Thread Jose Malacara
Can someone help me out here, please.

I have an if statement that is looping over a list of IP addresses:

192.168.1.1
192.168.1.2
192.168.1.3 ...192.168.1.10

$value=192.168.1.1

if ($line =~ /($value)/) ...

I only want to match the value exactly (192.168.1.1). My problem is that I am matching 
all addresses containing that string (192.168.1.10, 192.168.1.11, 192.168.1.100, 
etc...)

I know the trailing '$' anchors the match to the end of the line only, but I cannot 
seem to get it to work as I think my syntax is incorrect.

Any help would be appreciated.

Thanks,
Jose

Re: maching end of a line with $

2003-04-04 Thread Wiggins d'Anconia
Jose Malacara wrote:
Can someone help me out here, please.

I have an if statement that is looping over a list of IP addresses:

192.168.1.1
192.168.1.2
192.168.1.3 ...192.168.1.10
$value=192.168.1.1

if ($line =~ /($value)/) ...

I only want to match the value exactly (192.168.1.1). My problem is that I am matching all addresses containing that string (192.168.1.10, 192.168.1.11, 192.168.1.100, etc...)

In the case of an exact match why not just use string equality test? 
(don't forget to 'chomp' the line if you are getting it from a filehandle)

if ($line eq $value) 

I know the trailing '$' anchors the match to the end of the line only, but I cannot seem to get it to work as I think my syntax is incorrect.

What trailing '$' you don't have one in the code you posted above...if 
you insist on the regex, it would go something like:

if ($line =~ /^($value)$/) 

Which says match $value (and set it to $1) starting at the beginning of 
the string '^' and going until the end of the string '$'.

http://danconia.org

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: maching end of a line with $

2003-04-04 Thread John W. Krahn
Jose Malacara wrote:
 
 Can someone help me out here, please.
 
 I have an if statement that is looping over a list of IP addresses:
 
 192.168.1.1
 192.168.1.2
 192.168.1.3 ...192.168.1.10
 
 $value=192.168.1.1
 ^   ^ ^
 ^   ^ ^
 if ($line =~ /($value)/) ...

The periods in a regular expression match any character.  You need to
escape them to match literal periods.

if ( $line =~ /(\Q$value\E)/ ) ...


 I only want to match the value exactly (192.168.1.1).

If you want to match exactly then you should use the 'eq' operator.

chomp $line;
if ( $line eq $value ) ...


 My problem is that I
 am matching all addresses containing that string (192.168.1.10, 192.168.1.11,
 192.168.1.100, etc...)
 
 I know the trailing '$' anchors the match to the end of the line only, but
 I cannot seem to get it to work as I think my syntax is incorrect.

Show us what you tried.


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: maching end of a line with $

2003-04-04 Thread R. Joseph Newton
Jose Malacara wrote:

 Can someone help me out here, please.

 I have an if statement that is looping over a list of IP addresses:

 192.168.1.1
 192.168.1.2
 192.168.1.3 ...192.168.1.10

 $value=192.168.1.1

 if ($line =~ /($value)/) ...

Should not return true for
192.168.1.3
But should return true for:
192b16801h1
192316871k1085d
192_168-161
1921681 1
etc..{1/0}


 I only want to match the value exactly (192.168.1.1). My problem is that I am 
 matching all addresses containing that string (192.168.1.10, 192.168.1.11, 
 192.168.1.100, etc...)

 I know the trailing '$' anchors the match to the end of the line only, but I cannot 
 seem to get it to work as I think my syntax is incorrect.

 Any help would be appreciated.

 Thanks,
 Jose

Hi Jose,

Could you send more of the code, and some test results?  Although there is clearly a 
problem with using a simple quoted string in a regex, I don't see the results you cite 
as
reflecting the consequences.  As noted above, something like '192.168.1.3' should not 
match, so I think there may be some problem elsewhere in the code, also.

For now, you might want to:
perldoc -f quotemeta

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]