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]

Reply via email to