Randy, 
The code is still not working with the modifications that you listed
earlier.  The code does not have any compilation errors but does not
show the results for the variables $1, $2 and $3.  I was wandering if
you could think of something else that is causing the problem.

#!C:\perl\bin\perl5.6.1


$file1 = ' C:\perl\bin\dummy.txt' ;


open (INFO, "< $file1 ") or die "Can't open $file: $1";

while (<INFO>)
{

 if (/2\.2\.(\d+)\.(\d+)\.(\d+)/)
{

 print " $1,$2, $3 "; }}

close (INFO);

Thanks,
Sunny..

-----Original Message-----
From: Randy W. Sims [mailto:[EMAIL PROTECTED] 
Sent: Monday, August 09, 2004 4:57 PM
To: Singh, Harjit
Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: Trying To write a script

Singh, Harjit wrote:
> The following code is what I used to check if item number could be
> detected for the file I sent in the earlier email.  The code seems to
> have failed and need a advise on it..
> 

A couple of suggestions/corrections:

> 
> #!C:\perl\bin\perl5.6.1

use strict;
use warnings;

> $file1 = ' C:\perl\bin\dummy.txt' ;
> 
> 
> open (INFO, "< $file1 ") or die "Can't open $file: $1";
> 
> while (<INFO>)

This assigns each line in turn to the special variable $_

> {
> 
>  if ($test = ~ "/2\.2\./d+\./d+\./d+"){

so, matching against $test, which is undefined, does nothing. Also, the 
regular expression should not be in quotes. What you want to do is match

the regular expression againg $_ and capture the data you want using the

regular expression capture operator (). Using your above expression that

would be something like:

if ( $_ =~ /2\.2\.(/d+)\.(/d+)\.(/d+)/ ){

or since the $_ variable is implied, it can be shortened to:

if ( /2\.2\.(/d+)\.(/d+)\.(/d+)/ ){

> 
>  print " $test \n " ; }}

Using the above captures, your results will now be in the variables $1, 
$2, & $3.

> close (INFO);

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to