Re: help in regular expression

2011-09-11 Thread Uri Guttman
 ta == timothy adigun 2teezp...@gmail.com writes:

  ta You can use unpack:

  ta$val = 11.0.56.1;
  ta$new_val=unpack(x5 A2,$val);  # skip forward 6, get 2

  ta  print $new_val  # print 56;

unpack would be a poor choice if the number of digits in a field
changes. pack/unpack are meant for use in fixed field records.

uri

-- 
Uri Guttman  --  uri AT perlhunter DOT com  ---  http://www.perlhunter.com --
  Perl Developer Recruiting and Placement Services  -
-  Perl Code Review, Architecture, Development, Training, Support ---

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: help in regular expression

2011-09-11 Thread timothy adigun
 ug == Uri Guttman u...@stemsystems.com writes:

  ug unpack would be a poor choice if the number of digits in a field
  ug changes. pack/unpack are meant for use in fixed field records.

   That was a bad assumption on my side, I only considered the problem at
hand, thinking unpack will be faster that substr.

Thanks,
timothy


Re: help in regular expression

2011-09-10 Thread Shlomi Fish
Hi Irfan,

On Sat, 10 Sep 2011 10:23:31 -0700 (PDT)
Irfan Sayed irfan_sayed2...@yahoo.com wrote:

 hi,
 
 i have following string. 
 
 $val = 11.0.56.1;
 
 i need to write regular expression which should match only 56 and print 
 

There are any number of ways to extract 56 using a regular expression from
this string, and which would you would prefer depends on the general format of
the strings like that that you expect.

Can you describe how these strings look like?

Please reply to the list.

Regards,

Shlomi Fish

 please suggest 
 
 regards
 irfan



-- 
-
Shlomi Fish   http://www.shlomifish.org/
Funny Anti-Terrorism Story - http://shlom.in/enemy

Live as if you were to die tomorrow. Learn as if you were to live forever.
— http://en.wikiquote.org/wiki/Mohandas_Gandhi (Disputed)

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: help in regular expression

2011-09-10 Thread Shawn H Corey

On 11-09-10 01:23 PM, Irfan Sayed wrote:

i have following string.

$val = 11.0.56.1;

i need to write regular expression which should match only 56 and print

please suggest


( $val =~ /(56)/ )  print $1;


--
Just my 0.0002 million dollars worth,
  Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software:  Fail early  often.

Eliminate software piracy:  use only FLOSS.

Make something worthwhile.  -- Dear Hunter

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: help in regular expression

2011-09-10 Thread Rob Dixon

On 10/09/2011 18:23, Irfan Sayed wrote:

hi,

i have following string.

$val = 11.0.56.1;

i need to write regular expression which should match only 56 and print

please suggest


I think you should forget about regular expressions and use split:

  my $sub = (split /\./, $val)[2];

HTH,

Rob

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: help in regular expression

2011-09-10 Thread timothy adigun
Hi Irfan,
You can use unpack:

   $val = 11.0.56.1;
   $new_val=unpack(x5 A2,$val);  # skip forward 6, get 2
 print $new_val  # print 56;


Re: Help on regular expression !!

2009-08-03 Thread John W. Krahn

jet speed wrote:

Guys,


Hello,


I am new to perl,  I am having trouble capturing the required output from
the command, with my limited knowlege i tried to put something togather. not
sure how to proceed beyond.


In a regular expression, when you want to capture part of a pattern you 
have to enclose that part in parentheses.




What i am trying to achieve
for certain drives ex : B3494_901, B3494_102 from the outputlist is to  find
the index number ex: 19 for drive  B3494_102 as in the output below
 then collect the different index number for these selected drives  in a
variable $idx = 1:2:19:5
  then i can use the $idx inside the command 'tpconfig -multiple_delete
-drive $idx '

Any help would be much appericiated.

Script

use strict;
use warnings;

my @tpd = `tpconfig -dl`;
my $idx;
my $drv;

foreach my $line (@tpd) {
chomp $line;
#$line  =~ m/^Index\s+\d\d/  do {
$line  =~ m/^Index\w+/  do {


It looks like the pattern you want is more like:

$line =~ /
 ^ # start of string
 \s+   # followed by whitespace
 Index # match literal string
 \s+   # followed by whitespace
 ( \d+ )   # match and capture any numerical digits
 /x



$idx = $1;
print $idx \n;
};
$line =~ /^Drive.*\s+\w\d+/  do {


$line =~ /
 ^ # start of string
 \s+   # followed by whitespace
 Drive\ Name   # match literal string
 \s+   # followed by whitespace
 ( \w+ )   # match and capture any word characters
 /x



$drv =$1;
print $drv /n;
};

}


(  tpconfig -dl  )command output below



   Drive Name  B3494_102
Index   19
NonRewindDrivePath  /dev/rmt/23cbn
Typehcart2
Status  DOWN
SCSI Protection SR (Global)
Shared Access   Yes
TLH(0)  IBM Device Number=974680
Serial Number   07897468

Different Drives

Drive Name  B3494_901
Drive Name  B3494_100
Drive Name  B3494_102



John
--
Those people who think they know everything are a great
annoyance to those of us who do.-- Isaac Asimov

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Help on regular expression !!

2009-08-03 Thread jet speed
On Mon, Aug 3, 2009 at 4:00 PM, John W. Krahn jwkr...@shaw.ca wrote:

 jet speed wrote:

 Guys,


 Hello,

 I am new to perl,  I am having trouble capturing the required output from
 the command, with my limited knowlege i tried to put something togather.
 not
 sure how to proceed beyond.


 In a regular expression, when you want to capture part of a pattern you
 have to enclose that part in parentheses.


 What i am trying to achieve
 for certain drives ex : B3494_901, B3494_102 from the outputlist is to
  find
 the index number ex: 19 for drive  B3494_102 as in the output below
  then collect the different index number for these selected drives  in a
 variable $idx = 1:2:19:5
  then i can use the $idx inside the command 'tpconfig -multiple_delete
 -drive $idx '

 Any help would be much appericiated.

 Script

 use strict;
 use warnings;

 my @tpd = `tpconfig -dl`;
 my $idx;
 my $drv;

 foreach my $line (@tpd) {
 chomp $line;
 #$line  =~ m/^Index\s+\d\d/  do {
 $line  =~ m/^Index\w+/  do {


 It looks like the pattern you want is more like:

 $line =~ /
 ^ # start of string
 \s+   # followed by whitespace
 Index # match literal string
 \s+   # followed by whitespace
 ( \d+ )   # match and capture any numerical digits
 /x


 $idx = $1;
 print $idx \n;
 };
 $line =~ /^Drive.*\s+\w\d+/  do {


 $line =~ /
 ^ # start of string
 \s+   # followed by whitespace
 Drive\ Name   # match literal string
 \s+   # followed by whitespace
 ( \w+ )   # match and capture any word characters
 /x


 $drv =$1;
 print $drv /n;
 };

 }


 (  tpconfig -dl  )command output below



   Drive Name  B3494_102
Index   19
NonRewindDrivePath  /dev/rmt/23cbn
Typehcart2
Status  DOWN
SCSI Protection SR (Global)
Shared Access   Yes
TLH(0)  IBM Device Number=974680
Serial Number   07897468

 Different Drives

Drive Name  B3494_901
Drive Name  B3494_100
Drive Name  B3494_102



 John
 --
 Those people who think they know everything are a great
 annoyance to those of us who do.-- Isaac Asimov

 --
 To unsubscribe, e-mail: beginners-unsubscr...@perl.org
 For additional commands, e-mail: beginners-h...@perl.org
 http://learn.perl.org/



Hi John, Thanks for your help, Much appreciated.  Please could you also
refer any good reference for Regular expression for a beginer like me, would
be great.
Cheers, Sj


Re: Help on regular expression !!

2009-08-03 Thread John W. Krahn

jet speed wrote:


Hi John, Thanks for your help, Much appreciated.  Please could you also
refer any good reference for Regular expression for a beginer like me, would
be great.


Have you read the documentation that comes with Perl?

perldoc perlrequick
perldoc perlretut
perldoc perlre



John
--
Those people who think they know everything are a great
annoyance to those of us who do.-- Isaac Asimov

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Help on regular expression !!

2009-08-03 Thread jet speed
On Mon, Aug 3, 2009 at 5:45 PM, John W. Krahn jwkr...@shaw.ca wrote:

 jet speed wrote:


 Hi John, Thanks for your help, Much appreciated.  Please could you also
 refer any good reference for Regular expression for a beginer like me,
 would
 be great.


 Have you read the documentation that comes with Perl?

 perldoc perlrequick
 perldoc perlretut
 perldoc perlre




 John
 --
 Those people who think they know everything are a great
 annoyance to those of us who do.-- Isaac Asimov

 --
 To unsubscribe, e-mail: beginners-unsubscr...@perl.org
 For additional commands, e-mail: beginners-h...@perl.org
 http://learn.perl.org/


 Hi John, Thanks again, I have been jumping between manuals orelly books
mainly Programming 3rd edition  Perl, cookbook etc.. I do find the orelly
books hard to follow.

I will give it a shot the documentation you have referred. Cheers, Sj


Re: Help on regular expression !!

2009-08-03 Thread John W. Krahn

jet speed wrote:

On Mon, Aug 3, 2009 at 5:45 PM, John W. Krahn jwkr...@shaw.ca wrote:


jet speed wrote:


Hi John, Thanks for your help, Much appreciated.  Please could you also
refer any good reference for Regular expression for a beginer like me,
would
be great.


Have you read the documentation that comes with Perl?

perldoc perlrequick
perldoc perlretut
perldoc perlre


Hi John, Thanks again, I have been jumping between manuals orelly books
mainly Programming 3rd edition  Perl, cookbook etc.. I do find the orelly
books hard to follow.

I will give it a shot the documentation you have referred. Cheers, Sj


The best reference (IMHO) is the book from O'Reilly:

http://oreilly.com/catalog/9780596528126/



John
--
Those people who think they know everything are a great
annoyance to those of us who do.-- Isaac Asimov

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Help on regular expression

2007-12-13 Thread jeff pang

--- Sayed, Irfan (Irfan) [EMAIL PROTECTED] wrote:

 Hi All,
  
 I have a string like this 
  
 CLEARCASE_CMDLINE = (mkact -nc notme sprint) Now with the regular
 expression what I want is only those characters before closing
 braces
 excluding white space character. I mean to say that if regular
 expression encounter the white space character then it should stop.
 So my output should come as sprint.
 

What result string do you want? for example?

Best Regards,
Jeff (joy) Peng


  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 



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




Re: Help on regular expression

2007-12-13 Thread Chas. Owens
On Dec 13, 2007 6:12 AM, Sayed, Irfan (Irfan) [EMAIL PROTECTED] wrote:
 Hi All,

 I have a string like this

 CLEARCASE_CMDLINE = (mkact -nc notme sprint) Now with the regular
 expression what I want is only those characters before closing braces
 excluding white space character. I mean to say that if regular
 expression encounter the white space character then it should stop.
 So my output should come as sprint.

 Regards
 Irfan.

What have you tried?  What about it is confusing you?

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




Re: Help on regular expression

2007-12-13 Thread Rob Dixon

Sayed, Irfan (Irfan) wrote:

Hi All,
 
I have a string like this 
 
CLEARCASE_CMDLINE = (mkact -nc notme sprint) Now with the regular

expression what I want is only those characters before closing braces
excluding white space character. I mean to say that if regular
expression encounter the white space character then it should stop.
So my output should come as sprint.


Does the program below do what you need?

HTH,

Rob


use strict;
use warnings;

my $str = 'CLEARCASE_CMDLINE = (mkact -nc notme sprint)';

$str =~ /(\S+)\s*\)/ or die String didn't match expected pattern;

my $word = $1;
print Word found is '$word'\n;

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




RE: Help on regular expression

2007-12-13 Thread Sayed, Irfan (Irfan)
 
Thanks Rob. It really helped. I got what I want.

Request you to please explain me in detail how you did this.

I did not understand much. Please guide.

Regards
Irfan.



-Original Message-
From: Rob Dixon [mailto:[EMAIL PROTECTED] 
Sent: Thursday, December 13, 2007 6:21 PM
To: beginners@perl.org  Perl Beginners
Cc: Sayed, Irfan (Irfan)
Subject: Re: Help on regular expression

Sayed, Irfan (Irfan) wrote:
 Hi All,
  
 I have a string like this
  
 CLEARCASE_CMDLINE = (mkact -nc notme sprint) Now with the regular 
 expression what I want is only those characters before closing braces 
 excluding white space character. I mean to say that if regular 
 expression encounter the white space character then it should stop.
 So my output should come as sprint.

Does the program below do what you need?

HTH,

Rob


use strict;
use warnings;

my $str = 'CLEARCASE_CMDLINE = (mkact -nc notme sprint)';

$str =~ /(\S+)\s*\)/ or die String didn't match expected pattern;

my $word = $1;
print Word found is '$word'\n;

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




Re: Help on regular expression

2007-12-13 Thread Rob Dixon

Sayed, Irfan (Irfan) wrote:

 From: Rob Dixon [mailto:[EMAIL PROTECTED]

 Sayed, Irfan (Irfan) wrote:

 Hi All,

 I have a string like this

 CLEARCASE_CMDLINE = (mkact -nc notme sprint) Now with the regular
 expression what I want is only those characters before closing braces
 excluding white space character. I mean to say that if regular
 expression encounter the white space character then it should stop.
 So my output should come as sprint.

 Does the program below do what you need?


 use strict;
 use warnings;

 my $str = 'CLEARCASE_CMDLINE = (mkact -nc notme sprint)';

 $str =~ /(\S+)\s*\)/ or die String didn't match expected pattern;

 my $word = $1;
 print Word found is '$word'\n;


 Thanks Rob. It really helped. I got what I want.

 Request you to please explain me in detail how you did this.

 I did not understand much. Please guide.

OK

- \S matches any non-space character, so \S+ matches a sequence of
  one or more of them

- \s matches any space character, so \s* matches an optional
  sequence of them

- \) matches a closing parenthesis

- so the regular expression /\S+\s*\)/ matches a sequence of
  non-space characters, followed optionally by a some whitespace,
  followed by a closing parenthesis, which is what the relevant
  part of your string looks like

- finally, putting parentheses around \S causes the string of
  non-space characters to be stored in $1

I hope that makes it clearer.

Rob

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




Re: help in regular expression

2006-06-01 Thread John W. Krahn
Irfan J Sayed wrote:
 Hi ,

Hello,

 I am using following code 
 
 #!/usr/local/bin/perl
 
  # Main program
  
  use warnings;
  use strict;
 
  my $file = c:\backup.pl;

The escape sequence \b represents the backspace character.  You probably want:

my $file = 'c:/backup.pl';

  open(FH,$file) || die  can't open a file;

You should include the $file variable and the $! variable in the error message:

open(FH,$file) || die  can't open '$file' $!;

  my $pattern = '\w\s\w';
  my $input = ;

You probably want to get your input from the FH filehandle:

my $input = FH;

  print yes got the match  if $input =~ /$pattern/;
 
 but  i am getting following error
 
 Name main::FH used only once: possible typo at C:\irfan\search.pl line 
 9.

You are only using the FH filehandle once, in the open function.

  can't open a file at C:\irfan\search.pl line 9.

You probably don't have a file name with a backspace character in it.



John
-- 
use Perl;
program
fulfillment

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




Re: help in regular expression

2006-06-01 Thread David Romano

Hi Irfan,
On 6/1/06, Irfan J Sayed [EMAIL PROTECTED] wrote:

Hi ,

I am using following code

#!/usr/local/bin/perl

 # Main program

 use warnings;
 use strict;

 my $file = c:\backup.pl;
 open(FH,$file) || die  can't open a file;
 my $pattern = '\w\s\w';
 my $input = ;
 print yes got the match  if $input =~ /$pattern/;

but  i am getting following error

Name main::FH used only once: possible typo at C:\irfan\search.pl line
9.
 can't open a file at C:\irfan\search.pl line 9.

can anybody plz help me out

As far as I can tell, you need to escape the '\' in the string you're
assigning to $file:
my $file = c:\\backup.pl;

You also need to either escape the slashes for the pattern you're
using, or use the qr// form:
my $pattern = qr/\w\s\w/; # or  my $pattern = '\\w\\s\\w';

HTH,
David

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




interpolation problems (was: Re: help in regular expression)

2006-06-01 Thread Dr.Ruud
Irfan J Sayed schreef:


 #!/usr/local/bin/perl

  use warnings;
  use strict;

Good!


  my $file = c:\backup.pl;

Use

  my $file = 'c:\backup.pl';

or rather

  my $file = 'c:/backup.pl';


  open(FH,$file) || die  can't open a file;

Make that:

  open my $fh, '', $file  or  die Error opening '$file': $! ;


  my $pattern = '\w\s\w';

   my $pattern = qr/\w\s\w/ ;


  my $input = ;
  print yes got the match  if $input =~ /$pattern/;

Try this:

   while ( $fh ) {
 /$pattern/ and printf match in line %s\n, $. ;
   }


 but  i am getting following error

 Name main::FH used only once: possible typo at C:\irfan\search.pl


   close $fh  or  die Error closing '$file': $! ;

-- 
Affijn, Ruud

Gewoon is een tijger.



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




Re: help in regular expression

2006-06-01 Thread Muma W.

Irfan J Sayed wrote:

Hi ,

I am using following code 


#!/usr/local/bin/perl

 # Main program
 
 use warnings;

 use strict;

 my $file = c:\backup.pl;
 open(FH,$file) || die  can't open a file; [...]


For the die statement, use this instead:

die  can't open this file: $file reason: $!;

Your problem is that \b has a special meaning in a double-quoted string. 
It's a backspace character. Escape the backslash by putting another 
backslash before it.





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




Re: help in regular expression

2006-06-01 Thread Dr.Ruud
David Romano schreef:


 [ $pattern = '\w\s\w' ]
 You also need to [...] escape the slashes for the pattern you're
 using

I don't think that is needed:

(1)  perl -le '$re = q{\w\s\w} ; print qr/$re/'

(2)  perl -le '$re = q{\\w\\s\\w} ; print qr/$re/'

(on Windows you'll need to change the outer quotes to dquotes)

Both will print: (?-xism:\w\s\w).


Try also:

  perl -le 'print q{\\w\\s\\w}'

  perl -le 'print q{\w\s\w}'

that both print: \w\s\w.

-- 
Affijn, Ruud

Gewoon is een tijger.



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




Re: help in regular expression

2006-06-01 Thread David Romano

Hi Ruud,
On 6/1/06, Dr.Ruud [EMAIL PROTECTED] wrote:

David Romano schreef:


 [ $pattern = '\w\s\w' ]
 You also need to [...] escape the slashes for the pattern you're
 using

I don't think that is needed:

(1)  perl -le '$re = q{\w\s\w} ; print qr/$re/'

(2)  perl -le '$re = q{\\w\\s\\w} ; print qr/$re/'

(on Windows you'll need to change the outer quotes to dquotes)

Both will print: (?-xism:\w\s\w).


Try also:

  perl -le 'print q{\\w\\s\\w}'

  perl -le 'print q{\w\s\w}'

that both print: \w\s\w.


Yep, you're right. Looking at it again, my only excuse is that it was
4 in the morning. When I was writing that, I forgot what I learned
from the Llama book that only \' and \\ work between single-quotes
(thus the suggestion to change c:\backup.pl to c:\\backup.pl
instead of 'c:\backup.pl'). Thanks again for pointing out where I
erred :-)

David

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




Re: help on regular expression

2004-01-28 Thread Rob Dixon
Madhu Reddy wrote:

 Hi,
I need some help on regular expression...
 i have following in variable $total_count

 $total_count = ##I USBP 01 10:38:09(000)
 xyz_abc_etrack_validation,6 ETRACK_TOTAL_RECS : 100

 Here in this ETRACK_TOTAL_RECS is fixed and common for
 all and rest is changing...

 like following

 $total_count = ##I USBP 02 12:38:09(000)
 abc_gkkh_uiu,8 ETRACK_TOTAL_RECS : 500


 here i need some regular expression to get, 100 like
 following

 $total_count = 100

 I appreciate u r help..

Hi Madhu.

There are two separate things that regexes are good for:
verifying that a string matches a given pattern, and
extracting pieces of data from the string. Usually you want
a mixture of both at the same time. Code looking something
like this should do what you want:

  if ($total_count =~ m/\sETRACK_TOTAL_RECS\s*:\s*(\d+)/) {

my $total_recs = $1;
print ETRACK_TOTAL_RECS = $total_recs\n;
  }
  else {

die Unexpected record format: $total_count;
  }

But there are endless variations depending on how much checking
you want to build in.

HTH,

Rob



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




RE: help on regular expression

2004-01-28 Thread Mark Anderson

 Hi,
I need some help on regular expression...
 i have following in variable $total_count

 $total_count = ##I USBP 01 10:38:09(000)
 xyz_abc_etrack_validation,6 ETRACK_TOTAL_RECS : 100

 Here in this ETRACK_TOTAL_RECS is fixed and common for
 all and rest is changing...

 like following

 $total_count = ##I USBP 02 12:38:09(000)
 abc_gkkh_uiu,8 ETRACK_TOTAL_RECS : 500


 here i need some regular expression to get, 100 like
 following

 $total_count = 100


tmtowtdi, but if I knew that I was going to have a number with no
punctuation after the text ETRACK_TOTAL_RECS :  that I wanted to capture,
I'd do:

$total_count =~ /ETRACK_TOTAL_RECS\s*:\s*(\d+)/;

Then the number would be in $1.

If I wasn't sure of the format (i.e., it could have a decimal, commas, etc),
but knew that I wanted to capture everything from the : to the end of the
string, I'd do:

$total_count =~ /ETRACK_TOTAL_RECS\s*:\s*(.+)/;

And the result would be in $1.

Hope this helps,
/\/\ark


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




Re: help on regular expression

2004-01-28 Thread Kenton Brede
On Tue, Jan 27, 2004 at 07:49:02AM -0800, Madhu Reddy ([EMAIL PROTECTED]) wrote:
 Hi,
I need some help on regular expression...
 i have following in variable $total_count
 
 $total_count = ##I USBP 01 10:38:09(000)
 xyz_abc_etrack_validation,6 ETRACK_TOTAL_RECS : 100
 
 Here in this ETRACK_TOTAL_RECS is fixed and common for
 all and rest is changing...
 
 like following
 
 $total_count = ##I USBP 02 12:38:09(000)
 abc_gkkh_uiu,8 ETRACK_TOTAL_RECS : 500
 
 
 here i need some regular expression to get, 100 like
 following
 
 $total_count = 100
 
 I appreciate u r help..

I'm not entirely sure what you are trying to do here but I'll take a
stab at it.  I'm assuming you have lines in a file or database like -

##I USBP 01 10:38:09(000) xyz_abc_etrack_validation,6 ETRACK_TOTAL_RECS : 100
##I USBP 02 12:38:09(000) abc_gkkh_uiu,8 ETRACK_TOTAL_RECS : 500

You want to pull the last number from each of those lines and total them
up.  If that is the case then the following example may help you.  If my example
is what you're looking for and you need more explenation let me know.  If it
isn't what you are looking for, explain a little more about what you are
trying to do and show us the code you have written.

#!/usr/bin/perl
use warnings;
use strict;

my $total_count;
while(DATA) {
$_ =~ /:\s+(\d+)/;
$total_count += $1;
}
print $total_count\n;

__DATA__
##I USBP 01 10:38:09(000) xyz_abc_etrack_validation,6 ETRACK_TOTAL_RECS : 100
##I USBP 02 12:38:09(000) abc_gkkh_uiu,8 ETRACK_TOTAL_RECS : 500

Kent

-- 
A computer lets you make more mistakes faster than any invention in human history - 
with the possible exceptions of handguns and tequila. 
  Mitch Ratliffe

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




Re: help on regular expression

2004-01-28 Thread Jan Eden
Hi,

$total_count =~ s/.+ : (\d+)/$1/;

HTH,

Jan

Madhu Reddy wrote:

Hi,
   I need some help on regular expression...
i have following in variable $total_count

$total_count = ##I USBP 01 10:38:09(000)
xyz_abc_etrack_validation,6 ETRACK_TOTAL_RECS : 100

Here in this ETRACK_TOTAL_RECS is fixed and common for
all and rest is changing...

like following

$total_count = ##I USBP 02 12:38:09(000)
abc_gkkh_uiu,8 ETRACK_TOTAL_RECS : 500


here i need some regular expression to get, 100 like
following

$total_count = 100

I appreciate u r help..

Thanks
-Madhu





__
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/

-- 
A common mistake that people make when trying to design something completely foolproof 
is to underestimate the ingenuity of complete fools.

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




Re: help on regular expression

2004-01-28 Thread John McKown
On Tue, 27 Jan 2004, Madhu Reddy wrote:

 Hi,
I need some help on regular expression...
 i have following in variable $total_count
 
 $total_count = ##I USBP 01 10:38:09(000)
 xyz_abc_etrack_validation,6 ETRACK_TOTAL_RECS : 100
 
 Here in this ETRACK_TOTAL_RECS is fixed and common for
 all and rest is changing...
 
 like following
 
 $total_count = ##I USBP 02 12:38:09(000)
 abc_gkkh_uiu,8 ETRACK_TOTAL_RECS : 500
 
 
 here i need some regular expression to get, 100 like
 following
 
 $total_count = 100
 
 I appreciate u r help..
 
 Thanks
 -Madhu

From your examples, it appears that the number you want is always at the 
end of the line. The simpliest, but not necessarily the best way to do 
this might be:

($total_count) = ($total_count =~ /(\d+)$/);

Basically, this says: Match all the digits before the end of the line.


--
Maranatha!
John McKown


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




Re: Help with regular expression

2002-09-26 Thread ANIDIL RAJENDRAN

Try this if you want regex.
This may not be the appropriate but works.

@list = ('1992','1993 (summer)','1995 fall');
foreach (@list) {

  push @array, $1 if $_ =~ /(\d+)\s*.*$/;
}
print map {$_,\n} @array;


regards

Rajendran
Burlingame,CA

- Original Message -
From: Shaun Bramley [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, September 25, 2002 1:24 PM
Subject: Help with regular expression


 Hi all,

 I'm just looking for some confirmation on my regx.

 I have a list ('1992', '1993 (summer)', '1995 fall') and what I want to do
 is keep only the first four characters.  Will the regx work for me?

 @list =~ s/\s*//;

 Again will that turn the list into (1992, 1993, 1995)?


 as always thank you for your time and effort in helping me

 Shaun Bramley

 --
 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]




RE: Help with regular expression

2002-09-25 Thread Shishir K. Singh

Nope..this won't work. Why don't you loop over the list and do a substring or pack as 
you know that you need to keep only the first 4 characters of each element?

-Original Message-
From: Shaun Bramley [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, September 25, 2002 4:24 PM
To: [EMAIL PROTECTED]
Subject: Help with regular expression


Hi all,

I'm just looking for some confirmation on my regx.

I have a list ('1992', '1993 (summer)', '1995 fall') and what I want to do
is keep only the first four characters.  Will the regx work for me?

@list =~ s/\s*//;

Again will that turn the list into (1992, 1993, 1995)?


as always thank you for your time and effort in helping me

Shaun Bramley

-- 
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]




RE: Help with regular expression

2002-09-25 Thread Bob Showalter

 -Original Message-
 From: Shaun Bramley [mailto:[EMAIL PROTECTED]]
 Sent: Wednesday, September 25, 2002 4:24 PM
 To: [EMAIL PROTECTED]
 Subject: Help with regular expression
 
 
 Hi all,
 
 I'm just looking for some confirmation on my regx.
 
 I have a list ('1992', '1993 (summer)', '1995 fall') and what 
 I want to do
 is keep only the first four characters.  Will the regx work for me?
 
 @list =~ s/\s*//;
 
 Again will that turn the list into (1992, 1993, 1995)?

No.

1. You can't have a list on the left side of =~. To apply the substitution
over the list, use:

   s/\s*// for @list;

2. That regex will strip leading whitespace from the string, if any.

To grab just the first 4 chars, you don't even need a regex:

   $_ = substr($_, 0, 4) for $list;

HTH

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




Re: Help with regular expression

2002-09-25 Thread david

Shaun Bramley wrote:

 Hi all,
 
 I'm just looking for some confirmation on my regx.
 
 I have a list ('1992', '1993 (summer)', '1995 fall') and what I want to do
 is keep only the first four characters.  Will the regx work for me?
 
 @list =~ s/\s*//;
 
 Again will that turn the list into (1992, 1993, 1995)?
 

you can use substr() to null out from the 5th byte:

substr($_,4) = '' for(@list);

or you can use the unpack() function which could be a bit faster:

print unpack('A4',$_),\n for(@list);

david

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




Re: Help with regular expression

2002-09-25 Thread Janek Schleicher

Shaun Bramley wrote at Wed, 25 Sep 2002 22:24:00 +0200:

 I'm just looking for some confirmation on my regx.
 
 I have a list ('1992', '1993 (summer)', '1995 fall') and what I want to do
 is keep only the first four characters.  Will the regx work for me?
 
 @list =~ s/\s*//;
 
 Again will that turn the list into (1992, 1993, 1995)?

Another than using substr is really to use a regexp:

my @year = map /(\d\d\d\d)/, @list;


I would prefer it against the substr solution,
as it better express what you want to get out of the string.
(4 digits representing a year).
It has the disadvantage that it is slower than the substr solution.


Greetings,
Janek


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




Re: Help in Regular expression with array

2002-06-05 Thread Eric Beaudoin

At 15:49 2002.06.05, Ankit Gupta wrote:
Hello,

I am facing a problem in using regular expression on array. My code is
written below:
open(FILE, $dirvalue) ;
  my @lines = FILE;
  print @lines;   # prints the file contents
  if( @lines =~ m/Date:/) { print ok;}
   close(FILE);

here I can print @lines which gives me:

the =~ operator works on a scalar, not an array. You'll have to wait for Perl 6 to do 
that :-).

Received: from pc_jrs.spacebel.be (pc_jr) by earth.spacebel (5.x/SMI-SVR4)
 id AA26092; Sun, 27 Oct 1996 16:44:52 +0100
Date: Sun, 27 Oct 96 17:38:51 PST
From: John Reynolds [EMAIL PROTECTED]
Subject: Ebnf2ps


Now @lines does contain Date: characters but it does not return true
anwswer. Could someone please help me as how I can achieve this.

Here's another way to do the same (warning, I didn't syntax check the code).

open FILE, $dirvalue or die Can't open $dirvalue: $!;

my $found_date = 0;
while(FILE) {
print; # This print $_ which is the current line
$found_date = 1 if /Date:/; # the // is applied to $_ by default
}

close FILE or die Can't close $dirvalue: $!;

print OK\n if $found_date;

Hope this helps

--
Éric Beaudoin   mailto:[EMAIL PROTECTED]


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




RE: Help in Regular expression with array

2002-06-05 Thread Bob Showalter

 -Original Message-
 From: Ankit Gupta [mailto:[EMAIL PROTECTED]]
 Sent: Wednesday, June 05, 2002 3:49 PM
 To: [EMAIL PROTECTED]
 Subject: Help in Regular expression with array
 
 
 Hello,
 
 I am facing a problem in using regular expression on array. My code is
 written below:
 open(FILE, $dirvalue) ;
   my @lines = FILE;
   print @lines;   # prints the file contents

Here @lines is used in list context, so you get the contents of
the array.

   if( @lines =~ m/Date:/) { print ok;}

Here @lines is used in scalar context, so you get a number representing
the number of elements in the array.

close(FILE);
 
 here I can print @lines which gives me:
 
 Received: from pc_jrs.spacebel.be (pc_jr) by earth.spacebel 
 (5.x/SMI-SVR4)
  id AA26092; Sun, 27 Oct 1996 16:44:52 +0100
 Date: Sun, 27 Oct 96 17:38:51 PST
 From: John Reynolds [EMAIL PROTECTED]
 Subject: Ebnf2ps
 
 
 Now @lines does contain Date: characters but it does not return true
 anwswer. Could someone please help me as how I can achieve this.

You need a loop:

   /Date:/  print(ok\n), last for @lines;

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




RE: Help in Regular expression with array

2002-06-05 Thread Beau E. Cox

Hi -
I don't think you can regex on a whole array; try this
after you have loaded the array:
for (@lines) {print ok if /Date:/; }
This iterates the array lines presenting $_ for each
iteration. The regex /Date:/ operates on $_.

Aloha = Beau.

-Original Message-
From: Ankit Gupta [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 05, 2002 9:49 AM
To: [EMAIL PROTECTED]
Subject: Help in Regular expression with array


Hello,

I am facing a problem in using regular expression on array. My code is
written below:
open(FILE, $dirvalue) ;
  my @lines = FILE;
  print @lines;   # prints the file contents
  if( @lines =~ m/Date:/) { print ok;}
   close(FILE);

here I can print @lines which gives me:

Received: from pc_jrs.spacebel.be (pc_jr) by earth.spacebel (5.x/SMI-SVR4)
 id AA26092; Sun, 27 Oct 1996 16:44:52 +0100
Date: Sun, 27 Oct 96 17:38:51 PST
From: John Reynolds [EMAIL PROTECTED]
Subject: Ebnf2ps


Now @lines does contain Date: characters but it does not return true
anwswer. Could someone please help me as how I can achieve this.

Thanx
Ankit



-- 
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]




RE: Help in Regular expression with array

2002-06-05 Thread Shishir K. Singh


Don't know if you can do a search on an array (until and unless you want to evaluate 
each element)

In case you are trying to achieve the multiple lines search, maybe this or the 2nd 
example can help :

 open (FILE , $ARGV[0]);
 my @lines = FILE;
 close(FILE);  

 $line = join( , @lines);
 print $line;

if( $line =~ /Date:/m) { print ok;}


---
else  you may try this way in case you have only one file (note)
---

while () {
 print ok if  (/Date:/);
}


else the old way or looping over each element 

open (FILE , $ARGV[0]);
print ok if  ( map { /Date:/ } (FILE) );
close FILE;

-Original Message-
From: Ankit Gupta [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 05, 2002 3:49 PM
To: [EMAIL PROTECTED]
Subject: Help in Regular expression with array


Hello,

I am facing a problem in using regular expression on array. My code is
written below:
open(FILE, $dirvalue) ;
  my @lines = FILE;
  print @lines;   # prints the file contents
  if( @lines =~ m/Date:/) { print ok;}
   close(FILE);

here I can print @lines which gives me:

Received: from pc_jrs.spacebel.be (pc_jr) by earth.spacebel (5.x/SMI-SVR4)
 id AA26092; Sun, 27 Oct 1996 16:44:52 +0100
Date: Sun, 27 Oct 96 17:38:51 PST
From: John Reynolds [EMAIL PROTECTED]
Subject: Ebnf2ps


Now @lines does contain Date: characters but it does not return true
anwswer. Could someone please help me as how I can achieve this.

Thanx
Ankit



-- 
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]




RE: Help in Regular expression with array

2002-06-05 Thread Eric Beaudoin

At 16:12 2002.06.05, Shishir K. Singh wrote:
open (FILE , $ARGV[0]);
print ok if  ( map { /Date:/ } (FILE) );
close FILE;

map return an array with the result of the express apply to each line. Even if none of 
the lines in FILE contain Date:, you will have an array with one   value for each 
line. This is a non empty array i.e. it has multiple lines and when evaluate in a 
scalar context (with the if() ), it would always be true unless there are no lines in 
FILE.

I think you want grep there as in

print ok if (grep /Date:/ ,(FILE));

or 

print ok if (map { /Date:/ ? $_ : () } , (FILE));

I may be wrong though.

Best


--
Éric Beaudoin   mailto:[EMAIL PROTECTED]


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




RE: Help in Regular expression with array

2002-06-05 Thread Shishir K. Singh

Beau..I guess , the evaluation of the expression  is not going to be true if no 
Date: is found. Since map returns a list consisting of the results of each 
successive evaluation of the expression..., the map will  return undef. 

Although, here..I think using grep would be a better idea!! 

-Original Message-
From: Eric Beaudoin [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 05, 2002 4:29 PM
To: Shishir K. Singh
Cc: Ankit Gupta; [EMAIL PROTECTED]
Subject: RE: Help in Regular expression with array


At 16:12 2002.06.05, Shishir K. Singh wrote:
open (FILE , $ARGV[0]);
print ok if  ( map { /Date:/ } (FILE) );
close FILE;

map return an array with the result of the express apply to each line. Even if none of 
the lines in FILE contain Date:, you will have an array with one   value for each 
line. This is a non empty array i.e. it has multiple lines and when evaluate in a 
scalar context (with the if() ), it would always be true unless there are no lines in 
FILE.

I think you want grep there as in

print ok if (grep /Date:/ ,(FILE));

or 

print ok if (map { /Date:/ ? $_ : () } , (FILE));

I may be wrong though.

Best


--
Éric Beaudoin   mailto:[EMAIL PROTECTED]


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




RE: Help in Regular expression with array

2002-06-05 Thread Timothy Johnson


At this point I feel compelled to mention that if the file you will be
working on is more than a few K or so, then it might be a good idea to
rewrite  your loop so that you don't dump the entire file to memory.
Something like:

open(FILE,myfile.txt);
while(FILE){
   if($_ =~ /Date:/){
  print Ok!\n;
DoSomeOtherStuff();
   }
}

Which you'll notice is already being done in some form in a few of the
responses.

-Original Message-
From: Shishir K. Singh [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 05, 2002 1:48 PM
To: Eric Beaudoin
Cc: Ankit Gupta; [EMAIL PROTECTED]
Subject: RE: Help in Regular expression with array


Beau..I guess , the evaluation of the expression  is not going to be true if
no Date: is found. Since map returns a list consisting of the results of
each successive evaluation of the expression..., the map will  return undef.


Although, here..I think using grep would be a better idea!! 

-Original Message-
From: Eric Beaudoin [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 05, 2002 4:29 PM
To: Shishir K. Singh
Cc: Ankit Gupta; [EMAIL PROTECTED]
Subject: RE: Help in Regular expression with array


At 16:12 2002.06.05, Shishir K. Singh wrote:
open (FILE , $ARGV[0]);
print ok if  ( map { /Date:/ } (FILE) );
close FILE;

map return an array with the result of the express apply to each line. Even
if none of the lines in FILE contain Date:, you will have an array with
one   value for each line. This is a non empty array i.e. it has multiple
lines and when evaluate in a scalar context (with the if() ), it would
always be true unless there are no lines in FILE.

I think you want grep there as in

print ok if (grep /Date:/ ,(FILE));

or 

print ok if (map { /Date:/ ? $_ : () } , (FILE));

I may be wrong though.

Best


--
Éric Beaudoin   mailto:[EMAIL PROTECTED]


-- 
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]




RE: help in regular expression

2002-05-31 Thread Shishir K. Singh

You forgot to add g (global)in the end...
$dirstruct =~ s/([\W])/-/g;

Cheers
Shishir

-Original Message-
From: Ankit Gupta [mailto:[EMAIL PROTECTED]]
Sent: Friday, May 31, 2002 10:53 AM
To: [EMAIL PROTECTED]
Subject: help in regular expression


Hello Friends,

 I need help in the below written script.

$dirstruct =~ s/([\W])/-/;
  print $dirstruct;

here $dirstruct is c:\ankit\test

what I need as output is c--ankit-test but the output given by my script is
c-\ankit\test

Thanx

Ankit



-- 
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]




Re: help in regular expression

2002-05-31 Thread Jeff 'japhy' Pinyan

On May 31, Ankit Gupta said:

$dirstruct =~ s/([\W])/-/;

You're missing the /g modifier.  And s/([\W])/-/g could be written as
s/\W/-/g and would be a bit more efficient.

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for Regular Expressions in Perl published by Manning, in 2002 **
stu what does y/// stand for?  tenderpuss why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


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




RE: Help with regular expression.

2001-10-04 Thread Gibbs Tanton - tgibbs

You are looking for the word addr: followed by four groups of digits, three
of which are separated by a dot.  Therefore you want

$string =~ /addr:(\d+\.\d+.\d+\.\d+)/;
Now, $1 has the correct ip address.

-Original Message-
From: Daniel Falkenberg
To: [EMAIL PROTECTED]
Sent: 10/4/2001 6:43 PM
Subject: Help with regular expression.

List,

I have an IP address within this regular expression that I need
extracting and stored in a variable.  Could some one offer some help on
this?  The line is as follows...

  inet addr:144.137.215.25  P-t-P:172.31.28.24
Mask:255.255.255.255

I need to extract the inet addr: i.e 144.137.215.25 and store it in a
variable.

I am very new to regexes.  So any help would be greatly appriciated.

Daniel Falkenberg. 

==
VINTEK CONSULTING PTY LTD
(ACN 088 825 209)
Email:  [EMAIL PROTECTED]
WWW:http://www.vintek.net
Tel:(08) 8523 5035
Fax:(08) 8523 2104
Snail:  P.O. Box 312
Gawler   SA   5118
==


-- 
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]