On Tue, 25 Sep 2001 [EMAIL PROTECTED] wrote:

> I've been programming for a number of years, but I'm VERY new to Perl, and
> it looks like a lot of fun.  However, I'm very much in the learning stage,
> so please be patient, I'm still learning all the keywords etc...
>
> I'm curious how I can parse part of one variable into another
>
> ex:
> $part1 = "this is a great day"
> # I want $part2 = the first four letters of $part1 (this)
>
> how would I do this?

This all depends on how you want to pull apart your data.  If you want the
first four letters and only the first four letters, regardless of what the
text is, then you can use the substr() function:

my $part2 = substr $part1, 0, 4;

If you specifically want the first *word*, then you need to do something
more generalized, using a pattern matching algorithm.  For instance, this
will give you all of the words in the above variable as a list that you
can stuff into an array, using the split function, which lets you split a
string based on a particular pattern

my @parts = split /\s/, $part1;

Are you working out of a decent introductory tutorial or book on Perl?

-- Brett
                                          http://www.chapelperilous.net/
------------------------------------------------------------------------
Of course power tools and alcohol don't mix.  Everyone knows power
tools aren't soluble in alcohol...
                -- Crazy Nigel


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

Reply via email to