RE: Regular Expression

2002-12-10 Thread Larry Coffin
>This should do the trick...
>$List =~ /^(?:([\d|\.]+)\*)?(\w+)\/(?:([\d|\.]+)\*)?(\w+)$/;

Note that this will also pass '12|34.56' as a valid number because
of the '|' in the '[...]'. I think you will really want just '[\d\.]'.

---Larry


++
| Larry Coffin, G.P.H. Watertown, MA |
| http://www.PointInfinity.com/lcoffin/[EMAIL PROTECTED] |
++

Hofstadter's Law:
It always takes longer than you expect, even when you take
Hofstadter's Law into account.


-



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




Re: Regular Expression

2002-12-10 Thread Keex
hi there - I did not try this, but it seems somewhat logical to me:

$List =~ /^(?:(\d+(\.\d+)?)\*)?(\w+)\/(?:(\d+(\.\d+)?)\*)?(\w+)$/;


> > Hello,
> > 
> > I have this regular expression:
> > 
> > $List =~ /^(?:(\d+)\*)?(\w+)\/(?:(\d+)\*)?(\w+)$/;
> > 
> > It checks for a string like this: number*word/number*word
> > 
> > But it only accept integer number...
> > 
> > Does anybody knows how to change it to accept decimal numbers like
> 0.1???
> > 
> > Thanks,
> > Wagner Garcia Campagner
> > 
> > -- 
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > 
> 
> -- 
> - Alex
> 
>   ICQ-#: 40011562
>   mailto:[EMAIL PROTECTED]  
> 
> 
> 
> 
> 
> +++ GMX - Mail, Messaging & more  http://www.gmx.net +++
> NEU: Mit GMX ins Internet. Rund um die Uhr für 1 ct/ Min. surfen!
> 
> 

-- 
- Alex

  ICQ-#: 40011562
  mailto:[EMAIL PROTECTED]  





+++ GMX - Mail, Messaging & more  http://www.gmx.net +++
NEU: Mit GMX ins Internet. Rund um die Uhr für 1 ct/ Min. surfen!


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




RE: Regular Expression

2002-12-10 Thread Joel Hughes
Hi Wagner,
This should do the trick...
$List =~ /^(?:([\d|\.]+)\*)?(\w+)\/(?:([\d|\.]+)\*)?(\w+)$/;   

Basically looks like you need a character class to accept a '.' as well.

(However, this reg exp looks like it will let thru 100.0.0.1 is a
number!)


Joel


-Original Message-
From: Wagner [mailto:[EMAIL PROTECTED]] 
Sent: 10 December 2002 16:03
To: 'perl cgi'
Subject: Regular Expression


Hello,

I have this regular expression:

$List =~ /^(?:(\d+)\*)?(\w+)\/(?:(\d+)\*)?(\w+)$/;

It checks for a string like this: number*word/number*word

But it only accept integer number...

Does anybody knows how to change it to accept decimal numbers like
0.1???

Thanks,
Wagner Garcia Campagner

-- 
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.408 / Virus Database: 230 - Release Date: 24/10/2002
 

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.408 / Virus Database: 230 - Release Date: 24/10/2002
 


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




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]




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]




Re: regular expression

2002-07-27 Thread drieux


On Saturday, July 27, 2002, at 05:31 , fliptop wrote:

> GsuLinuX wrote:
> >
> > I wanna check the information typed in the form field whether if it
> > is in date format or not .
[..]
> 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

I basically agree that using Date::Calc is a long term solution.

but if a part of the goal here is to get a better feel for
how to do simple regular expressions may I offer:

http://www.wetware.com/drieux/pbl/RegEx/simpleDayMonYear.txt

as a way to think about solving simple classes of problems,
in case the 'web server' does not have Date::Calc and one
does not have the time to get the ISP to install it.



ciao
drieux

---


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




Re: regular expression

2002-07-27 Thread Wiggins d'Anconia

On a side note, where you said "A[12]" just to avoid future problems 
either you wanted A[11] or don't forget to add a blank starting element 
in the array, as arrays are indexed starting at 0!!

http://danconia.org


fliptop wrote:
> 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

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 drieux


On Monday, May 20, 2002, at 03:43 , Shawn wrote:
> To get just the Auth...
>
> (my $var2=$var)=~s/^.*Proxy-Authorization: Basic //ms;
> $var2=~s/\n.*$//ms;
>
> This is unetested...

actually i just tested it - works well.

> 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";

since you asked for a 'regEx' how about

http://www.wetware.com/drieux/pbl/RegEx/parseProxyAuth.txt

where I hope I explain myself well enough as to why I would
save in the long run by doing the RegEx

do let me know if that helps.

ciao
drieux

---


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

/


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,"my @list = ;
>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 = ; #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
>
>
>>  > 
>>  ...
>>  > 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 = ();
>>
>>  I would do:
>>
>>   while() {
>> 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.
&

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() {
  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]




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,"my @list = ;
>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 = ; #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
>
>
>>  > 
>>  ...
>>  > 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 = ();
>>
>>  I would do:
>>
>>   while() {
>> 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 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," my @list = ;
> 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 = ; #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
>
>
> > > 
> > ...
> > > 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 = ();
> >
> > I would do:
> >
> >  while() {
> >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

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.

  
#!/usr/bin/perl

use strict;
my(@name,@id,@password,@colour);
open(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;



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 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,"my @list = ;
>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 = ; #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
>
>
>>  > 
>>  ...
>>  > 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 = ();
>>
>>  I would do:
>>
>>   while() {
>> 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

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," my @list = ;
> 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 = ; #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
> 
> 
> > > 
> > ...
> > > 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 = ();
> >
> > I would do:
> >
> >  while() {
> >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 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,";
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 = ; #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


> > 
> ...
> > 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 = ();
>
> I would do:
>
>  while() {
>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 ChaoZ Inferno

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 = ; #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


> > 
> ...
> > 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 = ();
>
> I would do:
>
>  while() {
>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 David Gray

>   

> 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 = ();

I would do:

 while() {
   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 Shawn

Hey Chaoz,

  
#!/usr/bin/perl

use strict;
open(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;


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]