From: Sherm Pendley on
Sherm Pendley <spamtrap(a)shermpendley.com> writes:

> Jose Luis <jose.luis.fdez.diaz(a)gmail.com> writes:
>
>> Given the string "one;two;three;four...", is there a easy way to
>> print "one":
>
> perl -e "print split(';', 'one;two;three;four')[0]"

Duh, stupid typos. Should be:

perl -e "print ((split(';','one;two;three;four...'))[0])"

sherm--
From: Tad J McClellan on
Jose Luis <jose.luis.fdez.diaz(a)gmail.com> wrote:

>
> Given the string "one;two;three;four...", is there a easy way to
> print "one":


print "one";


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
From: Steve C on
Jose Luis wrote:
> Hi,
>
> Given the string "one;two;three;four...", is there a easy way to
> print "one":
>
>
> $ echo "one;two;three;four..."|perl -e 'while(<>){$_ =~ /^(.*)(\;)(.*)
> $/ && print $1}'
> one;two;three
>
>

Use 'sed mode':

echo "one;two;three;four..."|perl -pe 's/;.*//'
one

autosplit lets you pick other than first element:

echo "one;two;three;four..."|perl -lanF';' -e'print $F[1]'
two

From: Ben Morrow on

Quoth Jose Luis <jose.luis.fdez.diaz(a)gmail.com>:
>
> Given the string "one;two;three;four...", is there a easy way to
> print "one":
>
> $ echo "one;two;three;four..."|perl -e 'while(<>){$_ =~ /^(.*)(\;)(.*)
> $/ && print $1}'
> one;two;three

~% echo "one;two;three;four..." | perl -naF\; -le'print $F[0]'
one

or, if you have 5.10,

... | perl -naF\; -E'say $F[0]'

Ben