[27648] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 9116 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 3 18:05:58 2006

Date: Mon, 3 Apr 2006 15:05:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 3 Apr 2006     Volume: 10 Number: 9116

Today's topics:
        Extract first part of a string <ian.east@geemail.invalid>
    Re: Extract first part of a string <1usa@llenroc.ude.invalid>
    Re: Extract first part of a string lawrence@hummer.not-here.net
    Re: I tried to make logon but unsuccessfully? <glex_no-spam@qwest-spam-no.invalid>
        Net::SMTP <john.swilting@wanadoo.fr>
    Re: Speed of increment operators lawrence@hummer.not-here.net
    Re: Speed of increment operators <rvtol+news@isolution.nl>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Mon, 03 Apr 2006 12:01:47 -0700
From: Ian East <ian.east@geemail.invalid>
Subject: Extract first part of a string
Message-Id: <eur2325qdthitra4uvk9gh8ngtqet2t2iu@4ax.com>


This is a silly question that I'm sure is quite simple.

What's the best way to extract the first bit of text from a string (up
to the fist whitespace).

For example,

$string = "one two three";
split(/ /, $string);
print $_[0];

This works but I'm sure but it seems kind of ugly and I'm sure there
must be a better way.

Thanks


------------------------------

Date: Mon, 03 Apr 2006 19:13:25 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Extract first part of a string
Message-Id: <Xns979A9AFF04110asu1cornelledu@127.0.0.1>

Ian East <ian.east@geemail.invalid> wrote in 
news:eur2325qdthitra4uvk9gh8ngtqet2t2iu@4ax.com:

> What's the best way to extract the first bit of text from a string (up
> to the fist whitespace).
> 
> For example,
> 
> $string = "one two three";
> split(/ /, $string);
> print $_[0];

#!/usr/bin/perl

use strict;
use warnings;

my $s = q{one two three};

my $x   = (split /\s/, $s)[0];
my ($y) = ($s =~ /\A(\S+)/);
my $z   = substr $s, 0, index($s, ' ');

print map { qq{'$_'\n} } $x, $y, $z;
__END__

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



------------------------------

Date: 03 Apr 2006 12:12:26 -0700
From: lawrence@hummer.not-here.net
Subject: Re: Extract first part of a string
Message-Id: <874q1acw2t.fsf@hummer.i-did-not-set--mail-host-address--so-shoot-me>

Ian East <ian.east@geemail.invalid> writes:

> This is a silly question that I'm sure is quite simple.
> 
> What's the best way to extract the first bit of text from a string (up
> to the fist whitespace).
> 
> For example,
> 
> $string = "one two three";
> split(/ /, $string);
> print $_[0];
> 
> This works but I'm sure but it seems kind of ugly and I'm sure there
> must be a better way.
> 
> Thanks


Evaluate split in a list context assigning into only one variable

============================== BEGIN PERL CODE =========================

#!/usr/bin/perl
use warnings;
use strict;

while (my $line = <DATA>) {
  chomp $line;
  my ($first) = split(/\s+/, $line );
  print "$first\n";
}


__DATA__
one two three
only
left right

=============================== END PERL CODE ==========================

Produces the following output

one
only
left

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
	Lawrence Statton - lawrenabae@abaluon.abaom s/aba/c/g
Computer  software  consists of  only  two  components: ones  and
zeros, in roughly equal proportions.   All that is required is to
sort them into the correct order.


------------------------------

Date: Mon, 03 Apr 2006 09:23:02 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: I tried to make logon but unsuccessfully?
Message-Id: <gdaYf.9$L1.662@news.uswest.net>

info@perot.com wrote:
> I tried to make logon but unsuccessfully?
> How to make login on web page?

Well, what are you using to make the request?

If you're not using WWW::Mechanize, take a look at it.


------------------------------

Date: Mon, 3 Apr 2006 18:01:35 +0200
From: "john.swilting" <john.swilting@wanadoo.fr>
Subject: Net::SMTP
Message-Id: <443146cf$0$19719$8fcfb975@news.wanadoo.fr>

i would like to eclaicir a point of detail i use net::smtp it places the 
EHLO localhost.localdomain order but me i would love HELO 
localhost.localdomain
This for e good functioning of my scripts i read doc but I n 
arrives(manages,happens) not indeed at the dechiffrer can you m help I thank 
you

sub SMTP_TEST{

    my($host,$nom,$e_mail) = @_;

    my $smtp = Net::SMTP->new($host);
    if(defined($smtp)){
        ;
        }
    if(defined($smtp->mail($nom))){
        ;
        }
    if(defined($smtp->to($e_mail))){
        ;
        }
    if(defined($smtp->data())){
        ;
        }
    if(defined($smtp->datasend("To: postmaster\n","\n","a simple test
message\n"))){
        ;
        }
    if(defined($smtp->dataend())){
        ;
        }
    if(defined($smtp)){
        AFFICHAGE($host);
        }

    } 




------------------------------

Date: 03 Apr 2006 08:40:43 -0700
From: lawrence@hummer.not-here.net
Subject: Re: Speed of increment operators
Message-Id: <87fykud5vo.fsf@hummer.i-did-not-set--mail-host-address--so-shoot-me>

Joe Smith <joe@inwap.com> writes:

> axel@white-eagle.invalid.uk wrote:
> 
> > On a slightly different track, is there any different in execution
> > speed between ++$i and $i++ in Perl. I seem to remember that there
> > was such a difference in C++ but may be mistaken.
> 
> No such difference with C++.
> 
> There was a difference, back in the 1960's, in the opcodes used in the
> PDP-5 and PDP-8.
> 	-Joe

While I whole-hearted agree "there is not a gnat's eyelash of
difference" in Perl, and most other compiled languages i++ and ++i
both compile down to the same code on all modern processors.

However, the C construct x = *p++ and x = *++p (besides giving
different answers) would compile down into very different code of
greatly varying efficiency based on architecture.  PDP-11s and VAX
supported post-increment and pre-decrement (but not their inverses)
for integral types.  The 68000 inherited this behavior -- $DEITY only
knows on the bastard processors.  

I've pointed followups to a.f.c. where this discussion is on-topic.

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
	Lawrence Statton - lawrenabae@abaluon.abaom s/aba/c/g
Computer  software  consists of  only  two  components: ones  and
zeros, in roughly equal proportions.   All that is required is to
sort them into the correct order.


------------------------------

Date: Mon, 3 Apr 2006 18:37:23 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Speed of increment operators
Message-Id: <e0rq2l.1f0.1@news.isolution.nl>

lawrence@hummer.not-here.net schreef:
> Joe Smith:
>> axel@white-eagle.invalid.uk:

>>> On a slightly different track, is there any different in execution
>>> speed between ++$i and $i++ in Perl. I seem to remember that there
>>> was such a difference in C++ but may be mistaken.
>>
>> No such difference with C++.
>> There was a difference, back in the 1960's, in the opcodes used in
>> the PDP-5 and PDP-8.
>
> While I whole-hearted agree "there is not a gnat's eyelash of
> difference" in Perl, and most other compiled languages i++ and ++i
> both compile down to the same code on all modern processors.

There is another difference: when conditions are involved, a
post-increment can be skipped more often than a pre-increment. So in a
statistical sense, the post-increment is faster.
;)

-- 
Affijn, Ruud

"Gewoon is een tijger."



------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 9116
***************************************


home help back first fref pref prev next nref lref last post