Re: Regular expression

2002-09-08 Thread Janek Schleicher

Octavian Rasnita wrote at Sat, 07 Sep 2002 11:03:39 +0200:

 I am trying to match a word boundry or an end of string.
 I would like something like:
 
 /$word[\bX]/
 
 where X is the symbol used for end of string. I know that I can use $ but I
 don't think I can use it between brackets.
 
 I've seen that \b doesn't match the end or beginning of a string.
 I would like to know if there is another symbol that can match both these.

From perldoc perlre:
  \Z  Match only at end of string, or before newline at the end
  \z  Match only at end of string

So you can write

 /$word(\b|\Z)/

Please note that you can't use \b in a character class.
From perldoc perlre:
  (Within character classes \b
   represents backspace rather than a word boundary, just as
   it normally does in any double-quoted string.)


Greetings,
Janek


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




Regular expression

2002-09-07 Thread Octavian Rasnita

Hi all,

I am trying to match a word boundry or an end of string.
I would like something like:

/$word[\bX]/

where X is the symbol used for end of string. I know that I can use $ but I
don't think I can use it between brackets.

I've seen that \b doesn't match the end or beginning of a string.
I would like to know if there is another symbol that can match both these.

Thank you for help.


Teddy's Center: http://teddy.fcc.ro/
Mail: [EMAIL PROTECTED]



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




Re: regular expression

2002-07-28 Thread Janek Schleicher

Gsulinux wrote at Sat, 27 Jul 2002 13:32:27 +0200:

 I wanna check the information typed in the form field whether if it is in date 
format or not .
 Like : check it if it is in format day/mount/year , in format like ab/cd/ef or 
ab/cd/efgh ab
 must be valid like between 1-31
 cd must be valid between 1-12 or must be a string that exist in an array that i 
define, for
 exemple A[12] ef must be valid like between 00-99 or efgh between 1900-2010
 
 In second part i wanna get the month in a variable, i mean cd to a variable , cd 
can be either
 a numeric value or a string

There's no real difference between a numeric value and a string in Perl.
There's only a difference in the context using the values.
E.g.

03   == 3 # but
03 ne 3

 
 Can u help me writing that regular exp.?!?

What have you tried so far ?

In the most cases,
it's enough to say

my ($day, $month, $year) = m:(\d\d)/(\d\d)/(\d\d):;  # to match ab/cd/ef
my ($day, $month, $year) = m:(\d\d)/(\d\d)/(\d{4}):; # to match ab/cd/efgh

and ignoring the constraints for a day, month, year.

of course,
you can also build complicate regexes like

my $day_re   = qr/\d | [012]\d | 3[01]/x;
my $month_re = qr/\d | 0\d | 1[012]/x;
my $year_re  = qr/19\d\d | 200\d | 2010/x;

and then write
my ($day, $month, $year) = m:($day_re)/($month_re)/($year_re):;

But note that it doesn't mean to be a valid date,
as 30/02/1997 isn't valid at least.
Best is, as already mentioned of Fliptop to use one of
the many Date::* modules


Best Wishes,
Janek


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




regular expression

2002-07-27 Thread GsuLinuX

Hi,

I wanna check the information typed in the form field whether if it is in date format 
or not . Like :
check it if it is in format day/mount/year , in format like ab/cd/ef or ab/cd/efgh 
ab must be valid like between 1-31
cd must be valid between 1-12 or must be a string that exist in an array that i 
define, for exemple A[12]
ef must be valid like between 00-99 or efgh between 1900-2010 

In second part i wanna get the month in a variable, i mean cd to a variable , cd 
can be either a numeric value or a string

Can u help me writing that regular exp.?!?

thanx

funky
Istanbul





Re: regular expression

2002-07-27 Thread fliptop

GsuLinuX wrote:
 
  I wanna check the information typed in the form field whether if it
  is in date format or not . Like : check it if it is in format
  day/mount/year , in format like ab/cd/ef or ab/cd/efgh  ab must
  be valid like between 1-31 cd must be valid between 1-12 or must
  be a string that exist in an array that i define, for exemple A[12] ef
   must be valid like between 00-99 or efgh between 1900-2010
 
  In second part i wanna get the month in a variable, i mean cd to a
   variable , cd can be either a numeric value or a string

you should look into using Date::Calc.  it has many functions for 
checking a date's validity, extracting parts, etc.

http://search.cpan.org/search?dist=Date-Calc


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




Re: Regular expression again 8P

2002-05-20 Thread Shawn

Hey ChaoZ,

 my $var=
 GET http://us.a1.yimg.com/us.yimg.com/i/mntl/lnch/britney.jpg HTTP/1.0
 Host: us.a1.yimg.com
 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.4) Gecko/20011126 
 Netscape6/6.2.1
 Accept: text/xml, application/xml, application/xhtml+xml, text/html;q=0.9, 
 image/png, image/jpeg, image/gif;q=0.2, text/plain;q=0.8, text/css, 
 */*;q=0.1
 Accept-Language: en-us
 Accept-Encoding: gzip, deflate, compress;q=0.9
 Accept-Charset: ISO-8859-1, utf-8;q=0.66, *;q=0.66
 Connection: Close
 Proxy-Authorization: Basic 893263JHGjhgjhggjghgjh
 Referer: http://www.yahoo.com/;;
 
 I would like to retrieve the line of Proxy Authorization:  Basic and 
 truncate it to only:-

To get just the Auth...

(my $var2=$var)=~s/^.*Proxy-Authorization: Basic //ms;
$var2=~s/\n.*$//ms;

This is unetested...

Shawn

 my $var = m/Proxy-Authorization:.+/; #should return true
 
 But how do i truncated to only the line? and if possible, work to the below?
 
 my $var2 = 893263JHGjhgjhggjghgjh;



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




RE: regular expression vs split

2002-05-19 Thread Ross Esposito

I think split is compiled only once while regex (as used in the previous
posts) is compiled everytime a new line is to be matched. (you can use qr//)

Someone fire up Benchmark. I could be wrong :)

xgunnerx

-Original Message-
From: Scot Robnett [mailto:[EMAIL PROTECTED]]
Sent: Friday, May 17, 2002 10:31 AM
To: Brian; [EMAIL PROTECTED]
Subject: RE: regular expression vs split


I don't believe that a regex would be faster in an instance like this, but
someone please correct me if I'm wrong. It seems that it would add (albeit a
very minimal amount) processing overhead to apply a regular expression to
each line rather than using the built-in split function on it, depending on
the complexity of the regex. In this case it doesn't seem that complicated,
so maybe we're just talking semantics. TMTOWTDI. Regarding split being a
regex, well...split is a function, but it basically uses a regex to do its
whizbangery, if that's what you mean.

Scot Robnett
inSite Internet Solutions
[EMAIL PROTECTED]
[EMAIL PROTECTED]


-Original Message-
From: Brian [mailto:[EMAIL PROTECTED]]
Sent: Friday, May 17, 2002 10:17 AM
To: [EMAIL PROTECTED]
Subject: RE: regular expression vs split


Curious, but I've always thought that regex was much quicker then
split for situations such as this...
I'd always figured that split was basically a (and the regex for this
is probably wrong, but you can get the jist of it) /[^($delimiter |
end of string)/ with a dumping of the match minus the delimiter...

I'm guessing what was meant is that regex is more work then using a
split, but it doesn't particularly seem like a huge amount of extra
work using regex...
any comments/thoughts?

~Brian
Regular expressions are overkill for what you're trying to do. It seems
like
using 'split' should do exactly what you need.

#!/usr/bin/perl -W

use strict;
open(IN,/path/to/file) or die Could not open file;
my @list = IN;
close(IN);

for(@list) {
  chomp;
  my($field,$value) = split(/=/,$_); # split each line on '='
  print Your $field is $value. \n;
}


Scot Robnett
inSite Internet Solutions
[EMAIL PROTECTED]
[EMAIL PROTECTED]


-Original Message-
From: ChaoZ Inferno [mailto:[EMAIL PROTECTED]]
Sent: Friday, May 17, 2002 11:38 AM
To: [EMAIL PROTECTED]
Subject: Re: regular expression


Actually, the content of the file looks something like:-
name=john
id=12345
password=12345
colour=blue

I am trying to grab the value field of each line and assigned it to be a
variable.

I tried the regular expressions, but seems like the syntax is wrong or
something,

@file = filehandle; #small file anyway

$file[0] is equal to 'name=john'  but i just wanna extract john to be my
scalar variable.

like print $name but returns john only and the same extraction method for
the rest of the other 3 fields as well.

kindly advice!... million thanks!




- Original Message -
From: David Gray [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Cc: 'ChaoZ InferNo' [EMAIL PROTECTED]; 'Shawn' [EMAIL PROTECTED]
Sent: Friday, May 17, 2002 10:16 PM
Subject: RE: regular expression


   code
  ...
   for(@text) {
 /(d+)$/; # Match only the numbers at the end of the string
   ^^
this should actually be (\d+)

  I would actually conditionally print also, like so:

   print $1 if /(\d+)$/;

  And depending on the size of the file, instead of reading the whole
  thing into memory with

   my @text = (FILE);

  I would do:

   while(FILE) {
 print $1 if /(\d+)$/;
   }

  # and store them in '$1' to be printed out on the
  # next line followed by a new line character
  ...
@text # contains values of a phone directory
$text[0] contains john=012345678
   
$phone1 = ?
   
let say i wanted to grab just the values'012345678'.
how should i go on truncating the values?

  Cheers,

   -dave




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


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002


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


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002




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




Re: regular expression vs split

2002-05-19 Thread drieux


On Sunday, May 19, 2002, at 02:30 , Ross Esposito wrote:

 I think split is compiled only once while regex (as used in the previous
 posts) is compiled everytime a new line is to be matched. (you can use qr/
 /)

 Someone fire up Benchmark. I could be wrong :)

 xgunnerx

funny you should ask this:

http://www.wetware.com/drieux/pbl/BenchMarks/hashCompareSplitReg.txt

http://www.wetware.com/drieux/pbl/BenchMarks/spliVregForKeyVal.txt

what you are 'suppose' to do is

/RegExHere/o

for the directive to the compiler to compile it once.

What I feel firmly safe in saying, without a doubt,
and with full certainty of mind...

If you do your data model right, opt for hashes where
appropriate, and use RegEx - you can do well.

While you can make a complete bollock of it if you
do certain classes of scoping sillies for when and how
you allocate your 'use and throw away' variables...

the delta between the 'For' and 'ForOut' is whether
you declare the 'my ($key,$val)' inside the loop
to catch from the split - or outside...

Granted this is ONLY a test for the case of some 3699
key value pairs


ciao
drieux

---


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




regular expression

2002-05-17 Thread ChaoZ InferNo

hi all,

i am working to split the data in my array as follows but ended up clueless, 
hoope some of u can help.

@text # contains values of a phone directory
$text[0] contains john=012345678

$phone1 = ?

let say i wanted to grab just the values'012345678'.
how should i go on truncating the values?

kindly advice pls.

thanks!


_
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.


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




Re: regular expression

2002-05-17 Thread Shawn

Hey Chaoz,

code  
#!/usr/bin/perl

use strict;
open(FILE,'file.txt') or die Can't open file.txt: $!\n;
my @text=(FILE);
close(FILE);

for(@text) {
  /(d+)$/; # Match only the numbers at the end of the string
   # and store them in '$1' to be printed out on the
   # next line followed by a new line character
  print $1,\n;
}

exit;
/code

shawn
- Original Message - 
From: ChaoZ InferNo [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, May 17, 2002 4:01 AM
Subject: regular expression


 hi all,
 
 i am working to split the data in my array as follows but ended up clueless, 
 hoope some of u can help.
 
 @text # contains values of a phone directory
 $text[0] contains john=012345678
 
 $phone1 = ?
 
 let say i wanted to grab just the values'012345678'.
 how should i go on truncating the values?
 
 kindly advice pls.
 
 thanks!
 
 
 _
 Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.
 
 
 -- 
 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: regular expression

2002-05-17 Thread David Gray

 code  

 for(@text) {
   /(d+)$/; # Match only the numbers at the end of the string
 ^^
  this should actually be (\d+)

I would actually conditionally print also, like so:

 print $1 if /(\d+)$/;

And depending on the size of the file, instead of reading the whole
thing into memory with

 my @text = (FILE);

I would do:

 while(FILE) {
   print $1 if /(\d+)$/;
 }

# and store them in '$1' to be printed out on the
# next line followed by a new line character

  @text # contains values of a phone directory
  $text[0] contains john=012345678
  
  $phone1 = ?
  
  let say i wanted to grab just the values'012345678'.
  how should i go on truncating the values?

Cheers,

 -dave



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




Re: regular expression

2002-05-17 Thread fliptop

ChaoZ InferNo wrote:

 @text # contains values of a phone directory
 $text[0] contains john=012345678
 
 $phone1 = ?
 
 let say i wanted to grab just the values'012345678'.


if the format of $text[0] is always name=number you can use split 
instead of a regex.

perldoc -f split


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




RE: regular expression

2002-05-17 Thread Scot Robnett

Regular expressions are overkill for what you're trying to do. It seems like
using 'split' should do exactly what you need.

#!/usr/bin/perl -W

use strict;
open(IN,/path/to/file) or die Could not open file;
my @list = IN;
close(IN);

for(@list) {
 chomp;
 my($field,$value) = split(/=/,$_); # split each line on '='
 print Your $field is $value. \n;
}


Scot Robnett
inSite Internet Solutions
[EMAIL PROTECTED]
[EMAIL PROTECTED]


-Original Message-
From: ChaoZ Inferno [mailto:[EMAIL PROTECTED]]
Sent: Friday, May 17, 2002 11:38 AM
To: [EMAIL PROTECTED]
Subject: Re: regular expression


Actually, the content of the file looks something like:-
name=john
id=12345
password=12345
colour=blue

I am trying to grab the value field of each line and assigned it to be a
variable.

I tried the regular expressions, but seems like the syntax is wrong or
something,

@file = filehandle; #small file anyway

$file[0] is equal to 'name=john'  but i just wanna extract john to be my
scalar variable.

like print $name but returns john only and the same extraction method for
the rest of the other 3 fields as well.

kindly advice!... million thanks!




- Original Message -
From: David Gray [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Cc: 'ChaoZ InferNo' [EMAIL PROTECTED]; 'Shawn' [EMAIL PROTECTED]
Sent: Friday, May 17, 2002 10:16 PM
Subject: RE: regular expression


  code
 ...
  for(@text) {
/(d+)$/; # Match only the numbers at the end of the string
  ^^
   this should actually be (\d+)

 I would actually conditionally print also, like so:

  print $1 if /(\d+)$/;

 And depending on the size of the file, instead of reading the whole
 thing into memory with

  my @text = (FILE);

 I would do:

  while(FILE) {
print $1 if /(\d+)$/;
  }

 # and store them in '$1' to be printed out on the
 # next line followed by a new line character
 ...
   @text # contains values of a phone directory
   $text[0] contains john=012345678
  
   $phone1 = ?
  
   let say i wanted to grab just the values'012345678'.
   how should i go on truncating the values?

 Cheers,

  -dave




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


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002


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




Re: regular expression

2002-05-17 Thread Shawn

Ok, first, thanks for the correction and input David...  I agree 100% with what you 
say.

Secondly, am I just crazy, or doesn't split USE regex?  Since this is the second 
mention the regex is overkill, and that split will work, I am a bit confused...  When 
you can say $var=split(/=|:/); it tells me this IS a regex...  hence the '//'s.  So 
how exactly is this any less overkill (powerful) than a regex?

shawn

- Original Message - 
From: Scot Robnett [EMAIL PROTECTED]
To: ChaoZ Inferno [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Friday, May 17, 2002 9:52 AM
Subject: RE: regular expression


 Regular expressions are overkill for what you're trying to do. It seems like
 using 'split' should do exactly what you need.
 
 #!/usr/bin/perl -W
 
 use strict;
 open(IN,/path/to/file) or die Could not open file;
 my @list = IN;
 close(IN);
 
 for(@list) {
  chomp;
  my($field,$value) = split(/=/,$_); # split each line on '='
  print Your $field is $value. \n;
 }
 
 
 Scot Robnett
 inSite Internet Solutions
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]
 
 
 -Original Message-
 From: ChaoZ Inferno [mailto:[EMAIL PROTECTED]]
 Sent: Friday, May 17, 2002 11:38 AM
 To: [EMAIL PROTECTED]
 Subject: Re: regular expression
 
 
 Actually, the content of the file looks something like:-
 name=john
 id=12345
 password=12345
 colour=blue
 
 I am trying to grab the value field of each line and assigned it to be a
 variable.
 
 I tried the regular expressions, but seems like the syntax is wrong or
 something,
 
 @file = filehandle; #small file anyway
 
 $file[0] is equal to 'name=john'  but i just wanna extract john to be my
 scalar variable.
 
 like print $name but returns john only and the same extraction method for
 the rest of the other 3 fields as well.
 
 kindly advice!... million thanks!
 
 
 
 
 - Original Message -
 From: David Gray [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Cc: 'ChaoZ InferNo' [EMAIL PROTECTED]; 'Shawn' [EMAIL PROTECTED]
 Sent: Friday, May 17, 2002 10:16 PM
 Subject: RE: regular expression
 
 
   code
  ...
   for(@text) {
 /(d+)$/; # Match only the numbers at the end of the string
   ^^
this should actually be (\d+)
 
  I would actually conditionally print also, like so:
 
   print $1 if /(\d+)$/;
 
  And depending on the size of the file, instead of reading the whole
  thing into memory with
 
   my @text = (FILE);
 
  I would do:
 
   while(FILE) {
 print $1 if /(\d+)$/;
   }
 
  # and store them in '$1' to be printed out on the
  # next line followed by a new line character
  ...
@text # contains values of a phone directory
$text[0] contains john=012345678
   
$phone1 = ?
   
let say i wanted to grab just the values'012345678'.
how should i go on truncating the values?
 
  Cheers,
 
   -dave
 
 
 
 
 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 ---
 Incoming mail is certified Virus Free.
 Checked by AVG anti-virus system (http://www.grisoft.com).
 Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002
 
 ---
 Outgoing mail is certified Virus Free.
 Checked by AVG anti-virus system (http://www.grisoft.com).
 Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002
 
 
 -- 
 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: regular expression vs split

2002-05-17 Thread Brian

Curious, but I've always thought that regex was much quicker then 
split for situations such as this...
I'd always figured that split was basically a (and the regex for this 
is probably wrong, but you can get the jist of it) /[^($delimiter | 
end of string)/ with a dumping of the match minus the delimiter...

I'm guessing what was meant is that regex is more work then using a 
split, but it doesn't particularly seem like a huge amount of extra 
work using regex...
any comments/thoughts?

~Brian
Regular expressions are overkill for what you're trying to do. It seems like
using 'split' should do exactly what you need.

#!/usr/bin/perl -W

use strict;
open(IN,/path/to/file) or die Could not open file;
my @list = IN;
close(IN);

for(@list) {
  chomp;
  my($field,$value) = split(/=/,$_); # split each line on '='
  print Your $field is $value. \n;
}


Scot Robnett
inSite Internet Solutions
[EMAIL PROTECTED]
[EMAIL PROTECTED]


-Original Message-
From: ChaoZ Inferno [mailto:[EMAIL PROTECTED]]
Sent: Friday, May 17, 2002 11:38 AM
To: [EMAIL PROTECTED]
Subject: Re: regular expression


Actually, the content of the file looks something like:-
name=john
id=12345
password=12345
colour=blue

I am trying to grab the value field of each line and assigned it to be a
variable.

I tried the regular expressions, but seems like the syntax is wrong or
something,

@file = filehandle; #small file anyway

$file[0] is equal to 'name=john'  but i just wanna extract john to be my
scalar variable.

like print $name but returns john only and the same extraction method for
the rest of the other 3 fields as well.

kindly advice!... million thanks!




- Original Message -
From: David Gray [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Cc: 'ChaoZ InferNo' [EMAIL PROTECTED]; 'Shawn' [EMAIL PROTECTED]
Sent: Friday, May 17, 2002 10:16 PM
Subject: RE: regular expression


   code
  ...
   for(@text) {
 /(d+)$/; # Match only the numbers at the end of the string
   ^^
this should actually be (\d+)

  I would actually conditionally print also, like so:

   print $1 if /(\d+)$/;

  And depending on the size of the file, instead of reading the whole
  thing into memory with

   my @text = (FILE);

  I would do:

   while(FILE) {
 print $1 if /(\d+)$/;
   }

  # and store them in '$1' to be printed out on the
  # next line followed by a new line character
  ...
@text # contains values of a phone directory
$text[0] contains john=012345678
   
$phone1 = ?
   
let say i wanted to grab just the values'012345678'.
how should i go on truncating the values?

  Cheers,

   -dave




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


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002


--
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: regular expression

2002-05-17 Thread Shawn

 Actually, the content of the file looks something like:-
 name=john
 id=12345
 password=12345
 colour=blue

Ok, how about this then...

This is based on the fact that name, id, password, colour appear for every record 
whether they have a value or not, and that none of the values after the '=' will have 
an '=' in them.

code  
#!/usr/bin/perl

use strict;
my(@name,@id,@password,@colour);
open(FILE,'file.txt') or die Can't open file.txt: $!\n;
my @text=(FILE);
close(FILE);

for(@text) { s/.*=//; }

for(my $x=0; $x  $#text; $x+4;) {
  push @name, $text[$x];
  push @id, $text[$x+1];
  push @passowrd, $text[$x+2];
  push @colour, $text[$x+3];
}

for(@name) { print if($_); }

exit;
/code


It is still way too early, so if you catch any errors, let me know David (or anyone 
else for that matter) :-)

shawn


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




RE: regular expression

2002-05-17 Thread Joel Hughes

...it certainly looks like a regex to me

-Original Message-
From: Shawn [mailto:[EMAIL PROTECTED]]
Sent: 17 May 2002 16:03
To: Scot Robnett; ChaoZ Inferno; [EMAIL PROTECTED]
Subject: Re: regular expression


Ok, first, thanks for the correction and input David...  I agree 100% with
what you say.

Secondly, am I just crazy, or doesn't split USE regex?  Since this is the
second mention the regex is overkill, and that split will work, I am a bit
confused...  When you can say $var=split(/=|:/); it tells me this IS a
regex...  hence the '//'s.  So how exactly is this any less overkill
(powerful) than a regex?

shawn

- Original Message -
From: Scot Robnett [EMAIL PROTECTED]
To: ChaoZ Inferno [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Friday, May 17, 2002 9:52 AM
Subject: RE: regular expression


 Regular expressions are overkill for what you're trying to do. It seems
like
 using 'split' should do exactly what you need.

 #!/usr/bin/perl -W

 use strict;
 open(IN,/path/to/file) or die Could not open file;
 my @list = IN;
 close(IN);

 for(@list) {
  chomp;
  my($field,$value) = split(/=/,$_); # split each line on '='
  print Your $field is $value. \n;
 }


 Scot Robnett
 inSite Internet Solutions
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]


 -Original Message-
 From: ChaoZ Inferno [mailto:[EMAIL PROTECTED]]
 Sent: Friday, May 17, 2002 11:38 AM
 To: [EMAIL PROTECTED]
 Subject: Re: regular expression


 Actually, the content of the file looks something like:-
 name=john
 id=12345
 password=12345
 colour=blue

 I am trying to grab the value field of each line and assigned it to be a
 variable.

 I tried the regular expressions, but seems like the syntax is wrong or
 something,

 @file = filehandle; #small file anyway

 $file[0] is equal to 'name=john'  but i just wanna extract john to be my
 scalar variable.

 like print $name but returns john only and the same extraction method for
 the rest of the other 3 fields as well.

 kindly advice!... million thanks!




 - Original Message -
 From: David Gray [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Cc: 'ChaoZ InferNo' [EMAIL PROTECTED]; 'Shawn' [EMAIL PROTECTED]
 Sent: Friday, May 17, 2002 10:16 PM
 Subject: RE: regular expression


   code
  ...
   for(@text) {
 /(d+)$/; # Match only the numbers at the end of the string
   ^^
this should actually be (\d+)
 
  I would actually conditionally print also, like so:
 
   print $1 if /(\d+)$/;
 
  And depending on the size of the file, instead of reading the whole
  thing into memory with
 
   my @text = (FILE);
 
  I would do:
 
   while(FILE) {
 print $1 if /(\d+)$/;
   }
 
  # and store them in '$1' to be printed out on the
  # next line followed by a new line character
  ...
@text # contains values of a phone directory
$text[0] contains john=012345678
   
$phone1 = ?
   
let say i wanted to grab just the values'012345678'.
how should i go on truncating the values?
 
  Cheers,
 
   -dave
 
 
 

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


 ---
 Incoming mail is certified Virus Free.
 Checked by AVG anti-virus system (http://www.grisoft.com).
 Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002

 ---
 Outgoing mail is certified Virus Free.
 Checked by AVG anti-virus system (http://www.grisoft.com).
 Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002


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



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




RE: regular expression vs split

2002-05-17 Thread Scot Robnett

I don't believe that a regex would be faster in an instance like this, but
someone please correct me if I'm wrong. It seems that it would add (albeit a
very minimal amount) processing overhead to apply a regular expression to
each line rather than using the built-in split function on it, depending on
the complexity of the regex. In this case it doesn't seem that complicated,
so maybe we're just talking semantics. TMTOWTDI. Regarding split being a
regex, well...split is a function, but it basically uses a regex to do its
whizbangery, if that's what you mean.

Scot Robnett
inSite Internet Solutions
[EMAIL PROTECTED]
[EMAIL PROTECTED]


-Original Message-
From: Brian [mailto:[EMAIL PROTECTED]]
Sent: Friday, May 17, 2002 10:17 AM
To: [EMAIL PROTECTED]
Subject: RE: regular expression vs split


Curious, but I've always thought that regex was much quicker then
split for situations such as this...
I'd always figured that split was basically a (and the regex for this
is probably wrong, but you can get the jist of it) /[^($delimiter |
end of string)/ with a dumping of the match minus the delimiter...

I'm guessing what was meant is that regex is more work then using a
split, but it doesn't particularly seem like a huge amount of extra
work using regex...
any comments/thoughts?

~Brian
Regular expressions are overkill for what you're trying to do. It seems
like
using 'split' should do exactly what you need.

#!/usr/bin/perl -W

use strict;
open(IN,/path/to/file) or die Could not open file;
my @list = IN;
close(IN);

for(@list) {
  chomp;
  my($field,$value) = split(/=/,$_); # split each line on '='
  print Your $field is $value. \n;
}


Scot Robnett
inSite Internet Solutions
[EMAIL PROTECTED]
[EMAIL PROTECTED]


-Original Message-
From: ChaoZ Inferno [mailto:[EMAIL PROTECTED]]
Sent: Friday, May 17, 2002 11:38 AM
To: [EMAIL PROTECTED]
Subject: Re: regular expression


Actually, the content of the file looks something like:-
name=john
id=12345
password=12345
colour=blue

I am trying to grab the value field of each line and assigned it to be a
variable.

I tried the regular expressions, but seems like the syntax is wrong or
something,

@file = filehandle; #small file anyway

$file[0] is equal to 'name=john'  but i just wanna extract john to be my
scalar variable.

like print $name but returns john only and the same extraction method for
the rest of the other 3 fields as well.

kindly advice!... million thanks!




- Original Message -
From: David Gray [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Cc: 'ChaoZ InferNo' [EMAIL PROTECTED]; 'Shawn' [EMAIL PROTECTED]
Sent: Friday, May 17, 2002 10:16 PM
Subject: RE: regular expression


   code
  ...
   for(@text) {
 /(d+)$/; # Match only the numbers at the end of the string
   ^^
this should actually be (\d+)

  I would actually conditionally print also, like so:

   print $1 if /(\d+)$/;

  And depending on the size of the file, instead of reading the whole
  thing into memory with

   my @text = (FILE);

  I would do:

   while(FILE) {
 print $1 if /(\d+)$/;
   }

  # and store them in '$1' to be printed out on the
  # next line followed by a new line character
  ...
@text # contains values of a phone directory
$text[0] contains john=012345678
   
$phone1 = ?
   
let say i wanted to grab just the values'012345678'.
how should i go on truncating the values?

  Cheers,

   -dave




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


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002


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


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002


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




Re: regular expression

2002-05-17 Thread John Brooking

I just happened to write exactly this the other day,
as a generic configuration file reader. Here's the
basics:

sub readINI {# argument: filename
   my %params;
   open( INIFILE, $_[0] )
  || die Could not open $_[0]\n;
   while(INIFILE) {
  if(! /^#/ ) {  # Allow comments
 chomp;
 $params{$`} = $' if( /=/ );
  }
   }
   return %params;
}

What you get back is a hash of key/value pairs. In
your case, $myhash{name} = 'john', $myhash{id} =
'12345', etc. You can even comment a line out by
putting a # in the first position (or by not having
an = anywhere in the line). The only slightly
obscure thing here is the use of $` and $' to mean
everything before the match and everything after
the match, to save you having to explicitely capture
those sections with parens.

FYI, more detail on your initial question would have
allowed us to cut to the chase faster.

- John

--- ChaoZ Inferno [EMAIL PROTECTED] wrote:
 Actually, the content of the file looks something
 like:-
 name=john
 id=12345
 password=12345
 colour=blue
 
 I am trying to grab the value field of each line and
 assigned it to be a
 variable.
 
 ...


=
When you're following an angel, does it mean you have to throw your body off a 
building? - They Might Be Giants, http://www.tmbg.com

Word of the week: Serendipity, see http://www.bartleby.com/61/93/S0279300.html

__
Do You Yahoo!?
LAUNCH - Your Yahoo! Music Experience
http://launch.yahoo.com

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




Regular expression help w/timestamp

2002-03-03 Thread Rob Roudebush


Has anyone ever turned the mysql timestamp format  20020303223726 into something more 
readable like - 03/03/2002 22:37:26? I am also trying to do this from an array (the 
timestamp is in a array) I just figured somebody has probably done this already

Thanks, Rob



-
Do You Yahoo!?
Yahoo! Sports - Sign up for Fantasy Baseball


Regular expression

2001-10-01 Thread Gareth Londt

hi

i have just started using perl and i am getting to grips quite quickly 
although i would like to know : i have a  text file and i need a regular 
expression to pull he information off that file...?

Help would be much appreciated!


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