l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
September 2: Social gathering
Next Installfest:
TBD
Latest News:
Aug. 18: Discounts to "Velocity" in NY; come to tonight's "Photography" talk
Page last updated:
2001 Dec 30 16:57

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] newbie regexp question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] newbie regexp question



Micah,

Basic Perl question, in your example:

> #!/usr/bin/perl
> undef $/; # slurp the file into a scalar
> $contents = <>;
> $contents =~ /$exactSequence/;
> $beforeMatch = $`;
> $match = $&;
> $afterMatch = $';

Since you don't identify the file (I'm not sure where the "<>" will read), lets
say I had a file at /home/jstrauss/FileToBeRead.txt, how would I read an entire
file into the variable?

And what does "undef $/;" do?

Jay Strauss
jstrauss@bazillion.com
(h) 773.935.5326
(c) 312.617.0264

----- Original Message -----
From: "Micah Cowan" <micah@cowanbox.com>
To: <vox-tech@franz.mother.com>
Sent: Thursday, September 28, 2000 3:56 PM
Subject: Re: [vox-tech] newbie regexp question


> On Thu, Sep 28, 2000 at 01:31:18PM -0700, Ricardo Anguiano wrote:
> >
> > Eric Engelhard <ekengelhard@sagresdiscovery.com> writes:
> >
> > > Hi all,
> > >
> > > I am writing a perl script to process DNA sequences and want to use
> > > regular expressions to mark a site at known landmarks (exact sequence
> > > match) and cut the sequence both before AND after these landmarks. I
> > > promise to whip out the regexp O'Reilly book tonight, but I need a
> > > demo up in a couple hours. First correct answer scores a pint of hony
> > > beer (12% alcohol).
> > >
> > > -- Eric K. Engelhard
> >
> > Will this work?  Keep the beer if it does.
> >
> > #!/usr/bin/perl
> > while (<>) {
> > chomp;
> > if (/(.*)(exactSequence)(.*)/) {
> >     $beforematch = $1;
> >     $match = $2;
> >     $aftermatch = $3;
> > }
> >
> > -Ricardo
>
> Or:
>
> #!/usr/bin/perl
> undef $/; # slurp the file into a scalar
> $contents = <>;
> $contents =~ /$exactSequence/;
> $beforeMatch = $`;
> $match = $&;
> $afterMatch = $';
>
> - Micah
>


LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
O'Reilly and Associates
For numerous book donations.