[25643] in Perl-Users-Digest
Perl-Users Digest, Issue: 7885 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 15 18:10:20 2005
Date: Tue, 15 Mar 2005 15:10:13 -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 Tue, 15 Mar 2005 Volume: 10 Number: 7885
Today's topics:
Random String Generator <dummymb@hotmail.com>
Re: Random String Generator <pilkowsk@informatik.uni-marburg.de>
Re: Random String Generator <mritty@gmail.com>
Re: Random String Generator <mritty@gmail.com>
Re: Random String Generator <No_4@dsl.pipex.com>
Re: Random String Generator <someone@example.com>
Re: regular expression help with apostrophe <hendrik_maryns@despammed.com>
Re: regular expression help with apostrophe <pilkowsk@informatik.uni-marburg.de>
Re: regular expression help with apostrophe <tadmc@augustmail.com>
Re: regular expression help with apostrophe <tadmc@augustmail.com>
Re: regular expression help with apostrophe <hendrik_maryns@despammed.com>
Re: regular expression help with apostrophe <tadmc@augustmail.com>
Re: regular expression help with apostrophe (Walter Roberson)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 15 Mar 2005 12:53:26 -0800
From: "DMB" <dummymb@hotmail.com>
Subject: Random String Generator
Message-Id: <1110920006.418464.280300@o13g2000cwo.googlegroups.com>
I need to write a Perl function that returns a 32 character randomly
generated string of characters.
I tried the following with success, but I thought someone out there
might have a cleaner way to do this.
my @c = qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3
4 5 6 7 8 9);
my $ID = $c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand
@c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand
@c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand
@c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand
@c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand
@c].$c[rand @c].$c[rand @c].$c[rand @c];
------------------------------
Date: Tue, 15 Mar 2005 23:18:04 +0100
From: Fabian Pilkowski <pilkowsk@informatik.uni-marburg.de>
Subject: Re: Random String Generator
Message-Id: <MPG.1ca17d857ba88d969898dd@news.individual.de>
* Paul Lalli wrote:
>
> > I need to write a Perl function that returns a 32 character randomly
> > generated string of characters.
>
> #!/usr/bin/perl
> use strict;
> use warnings;
> my @c = qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4
> 5 6 7 8 9);
> my $ID = '';
> for (1..32){
> $ID .= $c[rand @c];
> }
> __END__
By replacing your for loop with a map call, you could write the string
generation down in one line ;-)
my @c = ( 'A' .. 'Z', '0' .. '9' );
my $ID = join '', map $c[rand @c], 1 .. 32;
regards,
fabian
------------------------------
Date: Tue, 15 Mar 2005 21:05:53 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Random String Generator
Message-Id: <R6IZd.5051$aS5.536@trndny05>
"DMB" <dummymb@hotmail.com> wrote in message
news:1110920006.418464.280300@o13g2000cwo.googlegroups.com...
> I need to write a Perl function that returns a 32 character randomly
> generated string of characters.
>
> I tried the following with success, but I thought someone out there
> might have a cleaner way to do this.
>
> my @c = qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3
> 4 5 6 7 8 9);
>
> my $ID = $c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand
> @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand
@c].$c[rand
> @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand
@c].$c[rand
> @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand
@c].$c[rand
> @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand
@c].$c[rand
> @c].$c[rand @c].$c[rand @c].$c[rand @c];
#!/usr/bin/perl
use strict;
use warnings;
my @c = qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4
5 6 7 8 9);
my $ID = '';
for (1..32){
$ID .= $c[rand @c];
}
__END__
Paul Lalli
------------------------------
Date: Tue, 15 Mar 2005 21:10:07 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Random String Generator
Message-Id: <PaIZd.3335$ed6.2070@trndny06>
"Paul Lalli" <mritty@gmail.com> wrote in message
news:R6IZd.5051$aS5.536@trndny05...
> my @c = qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3
4
> 5 6 7 8 9);
This, of course, can be shortened to:
my @c = ('A'..'Z', '0'..'9');
> my $ID = '';
> for (1..32){
> $ID .= $c[rand @c];
> }
>
> __END__
>
> Paul Lalli
>
------------------------------
Date: Tue, 15 Mar 2005 21:45:59 +0000
From: Big and Blue <No_4@dsl.pipex.com>
Subject: Re: Random String Generator
Message-Id: <J4CdnVLem9AIyqrfRVnyhw@pipex.net>
DMB wrote:
>
> my $ID = $c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand
> @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand
> @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand
> @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand
> @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand
> @c].$c[rand @c].$c[rand @c].$c[rand @c];
my @c = qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
0 1 2 3 4 5 6 7 8 9);
my $ID = ' 'x32;
for (0..31){
substr($ID, $_, 1) = $c[rand @c];
}
--
Just because I've written it doesn't mean that
either you or I have to believe it.
------------------------------
Date: Tue, 15 Mar 2005 22:04:16 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Random String Generator
Message-Id: <AZIZd.43801$KI2.20241@clgrps12>
DMB wrote:
> I need to write a Perl function that returns a 32 character randomly
> generated string of characters.
>
> I tried the following with success, but I thought someone out there
> might have a cleaner way to do this.
>
> my @c = qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3
> 4 5 6 7 8 9);
>
> my $ID = $c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand
> @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand
> @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand
> @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand
> @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand
> @c].$c[rand @c].$c[rand @c].$c[rand @c];
my @c = ( 'A' .. 'Z', 0 .. 9 );
my $ID = join '', map $c[ rand @c ], 1 .. 32;
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 15 Mar 2005 20:08:05 +0100
From: Hendrik Maryns <hendrik_maryns@despammed.com>
Subject: Re: regular expression help with apostrophe
Message-Id: <1110913571.661716@seven.kulnet.kuleuven.ac.be>
Ted Zlatanov schreef:
> On Mon, 14 Mar 2005, tadmc@augustmail.com wrote:
>
>
>>Regular expressions do not "yield" characters.
>>
>>They either match (succeed), or they don't match (fail).
>
>
> This is not always true, e.g.
>
> perl -n -e '@all = m/(.)/g; print @all'
This does nothing at all here. Actually, it just blocks. (And that is
after changing the ' to " to work on my Windoze machine.)
What should it do?
H.
--
Hendrik Maryns
Interesting websites:
www.lieverleven.be (I cooperate)
www.eu04.com European Referendum Campaign
aouw.org The Art Of Urban Warfare
------------------------------
Date: Tue, 15 Mar 2005 21:05:24 +0100
From: Fabian Pilkowski <pilkowsk@informatik.uni-marburg.de>
Subject: Re: regular expression help with apostrophe
Message-Id: <MPG.1ca15e73d40ceece9898db@news.individual.de>
* Hendrik Maryns wrote:
> > >=20
> > > Regular expressions do not "yield" characters.
> > >=20
> > > They either match (succeed), or they don't match (fail).
> >=20
> > This is not always true, e.g.
> >=20
> > perl -n -e '@all =3D m/(.)/g; print @all'
>=20
> This does nothing at all here. Actually, it just blocks. (And that is=
=20
> after changing the ' to " to work on my Windoze machine.)
>=20
> What should it do?
Have you read `perldoc perlvar` to learn more about the =BB-n=AB switch? It=
=20
adds a while loop with the diamond operator around the code which makes=20
it iterate over filename arguments. Since there are no arguments in the=20
line above the script will block and wait for input. On Windoze machines=20
the script will start its work if one hits some keys followed by enter.
To see the effect a bit better, I'd change the line to
perl -ne "@all =3D m/(.)/g; print qq{@all\n}"
Btw, by hitting Ctrl-Z as input your script terminates regularly ;)
regards,
fabian
------------------------------
Date: Tue, 15 Mar 2005 15:55:32 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: regular expression help with apostrophe
Message-Id: <slrnd3emek.7r1.tadmc@magna.augustmail.com>
dmalhotr2001@yahoo.com <dmalhotr2001@yahoo.com> wrote:
> Jesus christ,
I am pretty sure that he does not subscribe to this newsgroup.
> You guys are overthinking this to death.
That is to compensate for your underthinking when composing
your initial question.
You can expect that the value of followups will be directly
proportional to the amount of thought you put into composing
your question.
A silly question that nobody can figure out is likely to yield
a bunch of silly followups asking questions in an attempt to
figure it out (or worse).
> I want a regular expression to ignore the above
Regular expressions don't "ignore" they either succeed/match
or fail/don't match.
It is still not clear to me whether you want the match to succeed
or to fail above...
> I want the regular expression to yield.
Want the regular expression to yield _what_?
A true value if it matches or a false value if it doesn't match?
It will already do that.
> Any questions??
Yes, see above.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 15 Mar 2005 15:56:32 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: regular expression help with apostrophe
Message-Id: <slrnd3emgg.7r1.tadmc@magna.augustmail.com>
Ted Zlatanov <tzz@lifelogs.com> wrote:
> On Mon, 14 Mar 2005, tadmc@augustmail.com wrote:
>
>> Regular expressions do not "yield" characters.
>>
>> They either match (succeed), or they don't match (fail).
>
> This is not always true, e.g.
>
> perl -n -e '@all = m/(.)/g; print @all'
>
> to give a simple example of a regex that returns characters. Maybe I
> misunderstood your intent, Tad.
Yeah, I should have said:
Pattern matches in scalar context to not "yield" characters...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 15 Mar 2005 21:32:36 +0100
From: Hendrik Maryns <hendrik_maryns@despammed.com>
Subject: Re: regular expression help with apostrophe
Message-Id: <1110918641.472373@seven.kulnet.kuleuven.ac.be>
Fabian Pilkowski schreef:
> * Hendrik Maryns wrote:
>
>>>>Regular expressions do not "yield" characters.
>>>>
>>>>They either match (succeed), or they don't match (fail).
>>>
>>>This is not always true, e.g.
>>>
>>>perl -n -e '@all = m/(.)/g; print @all'
>>
>>This does nothing at all here. Actually, it just blocks. (And that is
>>after changing the ' to " to work on my Windoze machine.)
>>
>>What should it do?
>
>
> Have you read `perldoc perlvar` to learn more about the »-n« switch?
I presume you meant perldoc perlrun, and I hadn't, but now I have (at
least the part about -n and -p) ;-)
> It
> adds a while loop with the diamond operator around the code which makes
> it iterate over filename arguments. Since there are no arguments in the
> line above the script will block and wait for input. On Windoze machines
> the script will start its work if one hits some keys followed by enter.
> To see the effect a bit better, I'd change the line to
>
> perl -ne "@all = m/(.)/g; print qq{@all\n}"
Ok, this works now, but I still don't see the whole point:
<quote>
>Regular expressions do not "yield" characters.
>>
>> They either match (succeed), or they don't match (fail).
This is not always true, e.g.
perl -n -e '@all = m/(.)/g; print @all'
to give a simple example of a regex that returns characters.
</quote>
This isn't a regex that returns characters, it are the extended Perl
memory functions concerning regexes that make this possible (i.e. (.)
returning a value, $1), but a regex 'an sich' indeed only matches or
doesn't. (One could also see a regex as a description of a certain set
of strings).
> Btw, by hitting Ctrl-Z as input your script terminates regularly ;)
Indeed, I'll remember that!
> regards,
H.
--
Hendrik Maryns
Interesting websites:
www.lieverleven.be (I cooperate)
www.eu04.com European Referendum Campaign
aouw.org The Art Of Urban Warfare
------------------------------
Date: Tue, 15 Mar 2005 15:58:03 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: regular expression help with apostrophe
Message-Id: <slrnd3emjb.7r1.tadmc@magna.augustmail.com>
dmalhotr2001@yahoo.com <dmalhotr2001@yahoo.com> wrote:
> Thanks, thats exactly what i needed.
Which that is that that?
It is customary to quote some context in followups.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 15 Mar 2005 22:55:13 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: regular expression help with apostrophe
Message-Id: <d17p4h$850$1@canopus.cc.umanitoba.ca>
In article <slrnd3emek.7r1.tadmc@magna.augustmail.com>,
Tad McClellan <tadmc@augustmail.com> wrote:
:dmalhotr2001@yahoo.com <dmalhotr2001@yahoo.com> wrote:
:> Jesus christ,
:I am pretty sure that he does not subscribe to this newsgroup.
"Retro me, perlus!" ?
--
'The short version of what Walter said is "You have asked a question
which has no useful answer, please reconsider the nature of the
problem you wish to solve".' -- Tony Mantler
------------------------------
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 7885
***************************************