[26485] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8647 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 9 06:05:35 2005

Date: Wed, 9 Nov 2005 03:05:05 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 9 Nov 2005     Volume: 10 Number: 8647

Today's topics:
        How to get array item directly from split result? <huajian.luo@bsd.world>
    Re: How to get array item directly from split result? <noreply@gunnar.cc>
    Re: how to represent it via REL <huajian.luo@bsd.world>
    Re: how to represent it via REL <huajian.luo@bsd.world>
    Re: how to represent it via REL <samwyse@gmail.com>
    Re: how to represent it via REL <sbryce@scottbryce.com>
    Re: how to represent it via REL <huajian.luo@bsd.world>
    Re: how to represent it via REL <bart.lateur@pandora.be>
    Re: why the perl documents is hard to understand? <bart.lateur@pandora.be>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 9 Nov 2005 09:53:18 +0000 (UTC)
From: Huajian Luo<huajian.luo@bsd.world>
Subject: How to get array item directly from split result?
Message-Id: <dksgue$821$1@news1nwk.SFbay.Sun.COM>

Hi there,

I'm now parse a output from a command which need use split to 
split each line to array and get the fields like the following
pseudo code.

for my $line (@lines) {
    if ($line =~ /mb_setno/) {
	$line =~ s/\s//;
	my @fields = split(/\s+/, $line);
        my $100th_fld = $fields[99];
	}
} 

Cause the fields is too much, I wanna skip the @fields by just 
my $100th_fld = split(/\s+/, $line){99}; or sth like that, but
it didn't work, does any guys tried this or still any hints on
this.

-- 
Thanks,

Huajian Luo.


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

Date: Wed, 09 Nov 2005 11:00:57 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How to get array item directly from split result?
Message-Id: <3tdvmqFs9gmmU1@individual.net>

Huajian Luo wrote:
> I'm now parse a output from a command which need use split to 
> split each line to array and get the fields like the following
> pseudo code.
> 
> for my $line (@lines) {
>     if ($line =~ /mb_setno/) {
> 	$line =~ s/\s//;
> 	my @fields = split(/\s+/, $line);
>         my $100th_fld = $fields[99];
> 	}
> } 
> 
> Cause the fields is too much, I wanna skip the @fields by just 
> my $100th_fld = split(/\s+/, $line){99}; or sth like that, but
> it didn't work, does any guys tried this or still any hints on
> this.

This gives you the 100th field:

     ( split /\s+/, $line )[99]

Is that what you mean?

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Wed, 9 Nov 2005 05:05:01 +0000 (UTC)
From: Huajian Luo<huajian.luo@bsd.world>
Subject: Re: how to represent it via REL
Message-Id: <dks01s$t6k$1@news1nwk.SFbay.Sun.COM>

"John W. Krahn" <krahnj@telus.net> writes:
> Huajian Luo wrote:
> > 
> > "valid names are comprised of only alphanumeric characters
> > plus the characters '-', '_', and '.'.  Names must begin
> > with a letter.
> 
> $name =~ /\A[a-zA-Z][\w.-]*\z/;

It works, Thanks for the info.
-- 
Thanks,

Huajian Luo.


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

Date: Wed, 9 Nov 2005 05:21:28 +0000 (UTC)
From: Huajian Luo<huajian.luo@bsd.world>
Subject: Re: how to represent it via REL
Message-Id: <dks10o$t6k$2@news1nwk.SFbay.Sun.COM>

"John W. Krahn" <krahnj@telus.net> writes:
> Huajian Luo wrote:
> > 
> > I need to state the following name convention by perl regular
> > expression.
> > 
> > "valid names are comprised of only alphanumeric characters
> > plus the characters '-', '_', and '.'.  Names must begin
> > with a letter.
> 
> $name =~ /\A[a-zA-Z][\w.-]*\z/;
> 
But I have a problem when $name is "s_@_______", I tried qw()
but it still think it's valid.
-- 
Thanks,

Huajian Luo.


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

Date: Wed, 09 Nov 2005 06:43:05 GMT
From: Samwyse <samwyse@gmail.com>
Subject: Re: how to represent it via REL
Message-Id: <ZTgcf.13604$q%.5443@newssvr12.news.prodigy.com>

Huajian Luo wrote:
> "John W. Krahn" <krahnj@telus.net> writes:
> 
>>$name =~ /\A[a-zA-Z][\w.-]*\z/;
>>
> 
> But I have a problem when $name is "s_@_______", I tried qw()
> but it still think it's valid.

1)  How are you using qw()?  It is used for array contants.

2)  "s_@_______" shouldn't match the reg-ex that John gave you.  Are you 
sure you copied it correctly?

3)  Show us the code that fails.


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

Date: Tue, 08 Nov 2005 23:45:41 -0700
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: how to represent it via REL
Message-Id: <jsSdnS_0NvSIBuzeRVn-qw@comcast.com>

Huajian Luo wrote:

> "John W. Krahn" <krahnj@telus.net> writes:
> 
>>Huajian Luo wrote:
>>
>>>"valid names are comprised of only alphanumeric characters
>>>plus the characters '-', '_', and '.'.  Names must begin
>>>with a letter.
>>
>>$name =~ /\A[a-zA-Z][\w.-]*\z/;
>>
> 
> But I have a problem when $name is "s_@_______", I tried qw()
> but it still think it's valid.

Add these two lines at the beginning of your script:

use strict;
use warnings;

That will help you find the problem. I suspect your script won't 
compile, but the errors and warnings will help you see the problem.

In case you still can't figure it out, this script demonstrates the problem:


my $name = "s_@_______";

print somesub($name), "\n";

$name = 's_@_______';
print somesub($name), "\n";

sub somesub
{
	return shift;
}


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

Date: Wed, 9 Nov 2005 08:23:27 +0000 (UTC)
From: Huajian Luo<huajian.luo@bsd.world>
Subject: Re: how to represent it via REL
Message-Id: <dksblv$65a$1@news1nwk.SFbay.Sun.COM>

Scott Bryce <sbryce@scottbryce.com> writes:
> 
> use strict;
> use warnings;
> 
> That will help you find the problem. I suspect your script won't 
> compile, but the errors and warnings will help you see the problem.
I just write a test prog to test my function, sorry.

> In case you still can't figure it out, this script demonstrates the problem:
> 
> 
> my $name = "s_@_______";
> 
> print somesub($name), "\n";
> 
> $name = 's_@_______';
> print somesub($name), "\n";
> 
> sub somesub
> {
> 	return shift;
> }
Yes, you and John's REL are right the reason is that the string I issued,
I should Use single quote instead of double quote, to avoid interpolation.

Thanks for your help.

-- 
Thanks,

Huajian Luo.


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

Date: Wed, 09 Nov 2005 08:37:44 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: how to represent it via REL
Message-Id: <u0d3n1p5ec415kj0mh257vlpk1uinuhbcl@4ax.com>

Huajian Luo wrote:

>"valid names are comprised of only alphanumeric characters
>plus the characters '-', '_', and '.'.  Names must begin
>with a letter.
>
>I've tried the following function
>sub valid_name{
>   my $name = $_
>
>   if ($name !~ /*[!a-zA-Z0-9_.-]* | [!a-zA-Z]*/) {
>        print "Name $name is not valid";
>   } else {
>        print "MMMMMMMMMMMMMMMMMMMMM";
>}

Let's work with what you've got... First of all, negating a character
class happens with "^", not "!". It looks to me like you want to test if
some characters don't fit the description, then you want it to fail. But
it appears to me you have too many negations. Reduced:

	$name =~ /[^a-zA-Z0-9_.\-]|^[^a-zA-Z]/

This will succeed if there's an unacceptable character anywhere, or a
non-letter at the front. And then you have an unacceptable name.

-- 
	Bart.


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

Date: Wed, 09 Nov 2005 08:28:17 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: why the perl documents is hard to understand?
Message-Id: <jec3n1l4ad7jl7fpm4j3tg3um07pqfg0h6@4ax.com>

Xiaoshen Li wrote:

>For example, JAVA has all the functions document pages online. 
>So any time, if I don't understand a function or need a function for 
>doing something, I can check out the document pages. But I found Perl's 
>document pages are so hard to read.
>
>http://search.cpan.org/dist/perl/pod/perlfunc.pod

If you want a nicer-to-read version of the same docs online, try

	<http://perldoc.perl.org/perlfunc.html>

Split up per function, try 

	<http://perldoc.perl.org/index-functions.html>


>I have tried to read the descriptions of some functions. I am so totally 
>lost. The wording, the phrases are so hard to follow.

Like people said: it's a reference manual. Accuracy is more important
than being easy to read, it's not a tutorial. You're better off starting
with a tutorial, I recommend "Learning Perl" by Randal Schwartz (AKA the
Llama -- the book, not the author). Two days with this book, and you'll
feel more at ease with Perl.

-- 
	Bart.


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

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 8647
***************************************


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