[11843] in Perl-Users-Digest
Perl-Users Digest, Issue: 5443 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 21 18:07:26 1999
Date: Wed, 21 Apr 99 15:00:26 -0700
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, 21 Apr 1999 Volume: 8 Number: 5443
Today's topics:
Re: Arrays problem <jglascoe@giss.nasa.gov>
Re: CGI programmer wanted <uri@sysarch.com>
Re: CGI programmer wanted <uri@sysarch.com>
Re: CGI programmer wanted (I R A Aggie)
Re: CGI programmer wanted <cassell@mail.cor.epa.gov>
Re: circular references, destructor redux <sb@sdm.de>
Re: combining multiple grep statements into one... (Larry Rosler)
Comp PERL5 for BSDI3.1 kamez@my-dejanews.com
cookies & perl <larsplessmann@gmx.de>
date & time modules? djones@walcoff.com
Re: date & time modules? <sb@sdm.de>
DJGPP Port for DOS (Was Re: for (my $i;;) doesn't work <gellyfish@gellyfish.com>
Re: elegant way of assembling array of arrays? <Allan@due.net>
Re: Evaluating User Input (Larry Rosler)
Re: Evaluating User Input <jglascoe@giss.nasa.gov>
Re: Evaluating User Input <tchrist@mox.perl.com>
Re: Evaluating User Input <emschwar@rmi.net>
Re: FAQ 3.24: How can I get C<#!perl> to work on [MS-DO (Jeff Zeitlin)
Re: How can I execute non cgi PERL script under NT? <gellyfish@gellyfish.com>
Re: How to change an array to a list? scraig@my-dejanews.com
Re: How to get rid of the tailing spaces? <gellyfish@gellyfish.com>
Re: How to get rid of the tailing spaces? <emschwar@rmi.net>
Re: How to join <tripix@tdi-net.freeserve.co.uk>
Re: How to join (Larry Rosler)
Re: How to join <tripix@tdi-net.freeserve.co.uk>
Re: How to join <uri@sysarch.com>
Re: how to merge? (Larry Rosler)
Re: Is it possible to "reset" the ?? pattern search? (Tad McClellan)
last item in associative array. (Multimax)
Re: last item in associative array. (Larry Rosler)
Re: last item in associative array. <jglascoe@giss.nasa.gov>
Re: last item in associative array. (Larry Rosler)
Re: last item in associative array. <tchrist@mox.perl.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 21 Apr 1999 16:55:28 -0400
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: Greg Griffiths <greg2@surfaid.org>
Subject: Re: Arrays problem
Message-Id: <371E3B40.E9A6418E@giss.nasa.gov>
Greg Griffiths wrote:
>
> Firstly I will need to place each 'real name' and 'email address' in an
> array and pass that over to this script and then sort through them on
# a list of hash references
my @stuff = ({ name => "Fred", email => 'fred@foo.com' },
{ name => "Bob", email => 'goofball@aol.biz' });
my @sorted_by_name = sort { $a->{name} cmp $b->{name} } @stuff;
my @sorted_by_mail = sort { $a->{email} cmp $b->{email} } @stuff;
Jay Glascoe
------------------------------
Date: 21 Apr 1999 17:14:23 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: CGI programmer wanted
Message-Id: <x7yajld6c0.fsf@home.sysarch.com>
>>>>> "RLS" == Randal L Schwartz <merlyn@stonehenge.com> writes:
>>>>> "David" == David Cassell <cassell@mail.cor.epa.gov> writes:
David> Of course I deliberately picked those two names, since they are perhaps
David> the two people who have had the most to say about naked pictures of
David> themselves appearing on the net. I saw Alyssa Milano testifying on
David> CSPAN about it last year.
RLS> But not in the CPAN. :)
RLS> <ducking>
you can duck but you can't hide. we will get you at the tutes next week!
are you coming to the pm bash we are holding?
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: 21 Apr 1999 17:16:24 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: CGI programmer wanted
Message-Id: <x7u2u9d68n.fsf@home.sysarch.com>
>>>>> "DC" == David Cassell <cassell@mail.cor.epa.gov> writes:
DC> Tad McClellan wrote:
>>
>>
>> I fear we are just a bunch of slow learners...
DC> Is there no hope for us? Based on some postings, perhaps
DC> a good lobotomy would do the trick. :-)
well you just made me say this:
i'd rather have a bottle in front of me than a frontal lobotomy!
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: 21 Apr 1999 18:25:53 GMT
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: CGI programmer wanted
Message-Id: <slrn7hs66e.gnr.fl_aggie@stat.fsu.edu>
On Wed, 21 Apr 1999 10:05:47 -0700, David Cassell
<cassell@mail.cor.epa.gov>, in <371E056B.F48CDFAA@mail.cor.epa.gov> wrote:
+ I saw Alyssa Milano testifying on CSPAN about it last year.
Yes, yes, but did she have any clothes on while testifying?
James - and was she given an invitation to visit the Oval Office?
------------------------------
Date: Wed, 21 Apr 1999 14:59:04 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: CGI programmer wanted
Message-Id: <371E4A28.DDA7620F@mail.cor.epa.gov>
David Cassell wrote:
>
> [a bunch of nonsense, as usual]
Yes, I'm posting to my own post, in a thread which is already far
off-topic,
and taking it even farther off-topic. 3 bads in 2 lines.
Has anyone else received as a reward for participating in this thread,
a spam invitation to a porn site from a user at binarycity.net?
Or did I just say the magic words?
You know, it's always a really smart move to spam those *.gov e-mail
addresses. Perhaps they thought it stood for
`Going Overly Venereal'. :-)
David
--
David Cassell, OAO
cassell@mail.cor.epa.gov
Senior Computing Specialist phone: (541)
754-4468
mathematical statistician fax: (541)
754-4716
------------------------------
Date: 21 Apr 1999 20:39:49 GMT
From: Steffen Beyer <sb@sdm.de>
Subject: Re: circular references, destructor redux
Message-Id: <7fld2l$9at$1@solti3.sdm.de>
In article <7fhvf3$ip5$1@nnrp1.dejanews.com>, martin@cutup.de wrote:
> I basically have four questions:
> 1. In a data structure where an object holds a back reference to its parent,
> how is the allocated memory to be reclaimed?
> [...]
> The suggested solution to this problem is to instantiate a class that wraps
> this circular structure and can undef it "from the outside". In a lot of my
> classes this would lead to an added level of structural complexity I'm not too
> keen on. Before someone says: "This isn't about your personal _preferences_,
> yogurthead!" I would like to ask:
I had a similar problem to solve in the new upcoming version (5.0) of my module
"Data::Locations" where the objects necessarily contain self-references and the
objects may be interlinked in an almost arbitrary fashion.
If weak references had already been implemented in Perl (they are planned for
the next release of Perl, 5.006, AFAIK), I could have solved my problem with
them.
But since the module should be able to run on Perl 5.004 and 5.005, I had to
resort to more drastic measures:
Once an object is completely built (by its constructor method), I artificially
set its reference count to 1.
When its last reference goes out of scope, the DESTROY method gets called,
which restores the original refcount and then goes on to dismount the object
in question.
Might sound like a dirty hack, but actually works cleanly because the original
refcount is restored at the right time (which is indeed critical) and this
scheme only takes advantage of the "call DESTROY when the refcount goes down
to zero" mechanism in the usual way.
Moreover, the objects may contain additional self- and/or cross-references
between them, which are implemented as symbolic references (this is where
weak references would do the trick more nicely), in order not to unduly
increase the reference count of the objects in question.
I'll send you a preliminary version of this module (its docs aren't complete
yet) by mail.
Hope this might help you.
Best regards,
--
Steffen Beyer <sb@engelschall.com>
http://www.engelschall.com/u/sb/whoami/
http://www.engelschall.com/u/sb/download/
http://www.perl.com/CPAN/authors/id/STBEY/
http://www.oreilly.de/catalog/perlmodger/bnp/
------------------------------
Date: Wed, 21 Apr 1999 13:23:12 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: combining multiple grep statements into one...
Message-Id: <MPG.1187d38d1efb8ee69898fe@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <7fl99n$8u7$1@shell18.ba.best.com> on 21 Apr 1999 12:35:19 -
0700, Jim Matzdorff <syran@best.com> says...
> I am wondering if there's a neat perl trick to combine multiple perl
> grep statements into one.
...
> is there some way I can just do a:
>
> if (my ($found) == grep /<$search,Search_Param,OK>/, @lines)
> {
> print "Line is $found\n";
> }
>
> ??? The strings I am searching on can be in any order in the strings.
The expression used by grep can be arbitrarily complex, including even a
block of statements. In your case, it is relatively simple:
if (my ($found) = grep /$search/ && /Search_Param/ && /OK/, @lines)
I corrected your typo == to =, since you want to capture the first line
that matches. A 'foreach/last' loop would be more efficient. See
perlfaq4: "How can I tell whether a list or array contains a certain
element?" which explicitly warns against this use of grep.
Also, if speed matters, I think constant strings can be matched more
efficiently by index() than by a regex, but a benchmark would be better
than conjecture.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 21 Apr 1999 20:46:01 GMT
From: kamez@my-dejanews.com
Subject: Comp PERL5 for BSDI3.1
Message-Id: <7flde7$pqp$1@nnrp1.dejanews.com>
when i try the "make" (for the PERL installation ) , i got a bench of error
messages , here's a sample
---------------------------------------------------------------------------
regexec.o: Undefined symbol __DefaultRuneLocale referenced from text segment
regexec.o: Undefined symbol __DefaultRuneLocale referenced from text segment
regexec.o: Undefined symbol __DefaultRuneLocale referenced from text segment
regexec.o: Undefined symbol __DefaultRuneLocale referenced from text segment
regexec.o: Undefined symbol __DefaultRuneLocale referenced from text segment
regexec.o: Undefined symbol __DefaultRuneLocale referenced from text segment
regexec.o: Undefined symbol __DefaultRuneLocale referenced from text segment
regexec.o: Undefined symbol __DefaultRuneLocale referenced from text segment
regexec.o: More undefined symbol __DefaultRuneLocale refs follow
perlio.o: Undefined symbol _tmpfile referenced from text segment
perlio.o: Undefined symbol _vsprintf referenced from text segment
perlio.o: Undefined symbol _fputs referenced from text segment
*** Error code 1
----------------------------------------------------------------------------
anyone has a clue about how to get rid of this problem...???
thanks.
Khalid.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 21 Apr 1999 21:10:25 GMT
From: Lars Plessmann <larsplessmann@gmx.de>
Subject: cookies & perl
Message-Id: <371E3EFD.5F0FD6DE@gmx.de>
is it possible to read the cookies of a browser by perl?
if so, how can I do that? (larsplessmann@gmx.de)
------------------------------
Date: Wed, 21 Apr 1999 20:27:39 GMT
From: djones@walcoff.com
Subject: date & time modules?
Message-Id: <7flcbl$on3$1@nnrp1.dejanews.com>
I'm looking for a module that allows date and time math. It would be nice if
it could also take into accout timezones also. I looked on CPAN under the
date and time modules and found a bunch of them but none of them had readme
files that explained the functionality. I didn't want to download them all
only to find out it wasn't what I was looking for. Any suggestions
-david
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 21 Apr 1999 20:55:34 GMT
From: Steffen Beyer <sb@sdm.de>
Subject: Re: date & time modules?
Message-Id: <7fle06$ef2$1@solti3.sdm.de>
In article <7flcbl$on3$1@nnrp1.dejanews.com>, djones@walcoff.com wrote:
> I'm looking for a module that allows date and time math. It would be nice if
> it could also take into accout timezones also. I looked on CPAN under the
> date and time modules and found a bunch of them but none of them had readme
> files that explained the functionality. I didn't want to download them all
> only to find out it wasn't what I was looking for. Any suggestions
Date::Calc and Date::Manip are mostly the standard for date math.
Date::Calc allows for easy date/time math but doesn't take TZ into account
automatically (but it shouldn't be hard to do that yourself by adding/sub-
tracting the right amount of hours given by the TZ difference).
AFAIK, Date::Manip offers built-in TZ support, but I haven't used this
module yet.
HTH.
Yours,
--
Steffen Beyer <sb@engelschall.com>
http://www.engelschall.com/u/sb/whoami/
http://www.engelschall.com/u/sb/download/
http://www.perl.com/CPAN/authors/id/STBEY/
http://www.oreilly.de/catalog/perlmodger/bnp/
------------------------------
Date: 21 Apr 1999 21:34:11 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: DJGPP Port for DOS (Was Re: for (my $i;;) doesn't work like I think it should)
Message-Id: <7flg8j$pm$1@gellyfish.btinternet.com>
On Wed, 21 Apr 1999 19:10:00 GMT Bart Lateur wrote:
>
> The DJGPP DOS port is at least at level 5.004. 5.005 is
> in the making, if it's not available yet. (BTW is 5.005 Ready For The
> World (TM) yet?)
>
Yes 5.005.02 is the version that is currently available from the djgpp
archives.
/J\
--
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Wed, 21 Apr 1999 16:08:24 -0400
From: "Allan M. Due" <Allan@due.net>
Subject: Re: elegant way of assembling array of arrays?
Message-Id: <7flb85$2or$1@nntp4.atl.mindspring.net>
Burton Kent wrote in message <371E0A8D.4127D82D@lucent.com>...
:I have a list of strings, such as:
: @stringlist = [ "one two three", "eleven twelve thirteen", "twentyone"];
:which I would like to convert to a list of lists such as:
: @stringlistlist [ ["one", "two", "three"], ["eleven", "twelve",
"thirteen"],
:["twentyone"] ];
:
:(Note that the use of numbers is arbitrary, has nothing
:to do with the actual problem)
perldoc prelref
perldoc perlol
#!/usr/local/bin/perl -w
use strict;
my $stringlistlist;
my @stringlist = ("one two three", "eleven twelve thirteen", "twentyone");
push(@$stringlistlist,[split]) foreach @stringlist;
print "@$_\n" foreach @$stringlistlist;
print "$stringlistlist->[0][1]";
--
$email{'Allan M. Due'} = ' All@n.Due.net ';
--random quote --
"Help save the world!"
- Larry Wall in README
------------------------------
Date: Wed, 21 Apr 1999 13:09:31 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Evaluating User Input
Message-Id: <MPG.1187d059cf5591089898fd@nntp.hpl.hp.com>
In article <7fl9pc$1vq$1@news8.svr.pol.co.uk> on Wed, 21 Apr 1999
20:36:06 +0100, Wayne Keenan <tripix@tdi-net.freeserve.co.uk> says...
> Chunsheng Ban wrote in message ...
> >I would like to write a program to accept user input that is
> >an arithmetic expression and the program evaluate it and print
> >out the result.
...
> >If a user enters 2+3, I want the program to output 5 instead of
> >2+3.
>
> change the last line to:
> print "The result is ", eval $userinput ,".\n";
Chunsheng Ban's next homework assignment (well, maybe next+several :-)
should be to make that program behave rationally if the users's input is
not a valid arithmetic expression.
perldoc -f eval
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 21 Apr 1999 16:26:37 -0400
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: Chunsheng Ban <ban.1@osu.edu>
Subject: Re: Evaluating User Input
Message-Id: <371E347D.196AF79B@giss.nasa.gov>
Chunsheng Ban wrote:
>
> If a user enters 2+3, I want the program to output 5 instead of
> 2+3.
try "eval()", but cross your fingers and hope the
user hasn't entered, e.g. "`rm -rf /foo`"
Jay Glascoe
------------------------------
Date: 21 Apr 1999 15:22:45 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Evaluating User Input
Message-Id: <371e41a5@cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, jglascoe@giss.nasa.gov writes:
:> If a user enters 2+3, I want the program to output 5 instead of
:> 2+3.
:
:try "eval()", but cross your fingers and hope the
:user hasn't entered, e.g. "`rm -rf /foo`"
That's why you use a Safe compartment's ->reval() method.
--tom
--
Marriage is the only adventure open to the cowardly.
-- Voltaire
------------------------------
Date: 21 Apr 1999 15:58:15 -0600
From: Eric The Read <emschwar@rmi.net>
Subject: Re: Evaluating User Input
Message-Id: <xkfr9pdiqko.fsf@valdemar.col.hp.com>
ban.1@osu.edu (Chunsheng Ban) writes:
> If a user enters 2+3, I want the program to output 5 instead of
> 2+3.
perldoc -f eval
-=Eric
------------------------------
Date: 21 Apr 1999 15:24:11 -0500
From: jzeitlin@cyburban.com (Jeff Zeitlin)
Subject: Re: FAQ 3.24: How can I get C<#!perl> to work on [MS-DOS,NT,...]?
Message-Id: <371e349a.432139247@news.cyburban.com>
Tom Christiansen <perlfaq-suggestions@perl.com> wrote:
>(This excerpt from perlfaq3 - Programming Tools
> ($Revision: 1.35 $, $Date: 1999/04/16 01:38:05 $)
>part of the standard set of documentation included with every
>valid Perl distribution, like the one on your system.
>See also http://language.perl.com/newdocs/pod/perlfaq3.html
>if your negligent system adminstrator has been remiss in his duties.)
>
> How can I get `#!perl' to work on [MS-DOS,NT,...]?
> The Win95/NT installation, when using the ActiveState port of Perl,
> will modify the Registry to associate the `.pl' extension with the
> perl interpreter. If you install another port (Gurusamy Sarathy's
> is the recommended Win95/NT port), or (eventually) build your own
> Win95/NT Perl using a Windows port of gcc (e.g., with cygwin32 or
> mingw32), then you'll have to modify the Registry yourself. In
> addition to associating `.pl' with the interpreter, NT people can
> use: `SET PATHEXT=%PATHEXT%;.PL' to let them run the program
> `install-linux.pl' merely by typing `install-linux'.
Users of JPSoftware's command interpreters (4DOS, 4NT, 4OS2, Take
Command) can also create an 'executable extension':
SET .pl=C:\path\to\perl.exe
This will allow you to run 'foo.pl' by just typing 'foo', much as
with the SET PATHEXT method from Windows/NT.
Alternatively, 4DOS etc. users can create a command alias
ALIAS #!perl C:\path\to\perl.exe
then add a %& at the end of the shebang line in a perl program,
and rename the file to have a .BAT or .BTM extension.
Note that neither of these methods will allow mouse-click
execution from the MS/IBM GUIs; they are effective in the 4*
command line environment only.
--
Jeff Zeitlin
jzeitlin@cyburban.com
------------------------------
Date: 21 Apr 1999 21:15:31 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: How can I execute non cgi PERL script under NT?
Message-Id: <7flf5j$pf$1@gellyfish.btinternet.com>
On Wed, 21 Apr 1999 14:19:19 +0200 Vincent Vanbiervliet wrote:
>
> This has also the advantage you can use switches, like:
> perl -w myscript.pl
>
Bear in mind that because of Perls cleverness if you put a shebang line
like:
#!perl -w
As the first line of your script then Perl will invoke itself with any
switches it finds there.
See the perlrun manpage for more on this.
/J\
--
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Wed, 21 Apr 1999 20:13:43 GMT
From: scraig@my-dejanews.com
Subject: Re: How to change an array to a list?
Message-Id: <7flbhi$nvo$1@nnrp1.dejanews.com>
In article <7fl24f$eip$1@nnrp1.dejanews.com>,
yong321@yahoo.com wrote:
> the user enters the string "a@b.com c@d.com" which is passed in as $email, I
> want this:
>
> if ($email =~ / /)
> { @email = split / /,$email;
> $smtp->to(@email); #doesn't seem to work
> }
> else
> { $smtp->to($email);
> }
>
> I know $smtp->to("a\@b.com", "c\@d.com") works, but $smtp->to
> ("a\@b.com,c\@d.com") does not. Please help. Thanks.
It appears that the problem is the missing backslashes in $email. Try
$email =~ s/@/\\@/g; before the split.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 21 Apr 1999 20:03:58 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: How to get rid of the tailing spaces?
Message-Id: <7flave$nb$1@gellyfish.btinternet.com>
On Wed, 21 Apr 1999 22:20:22 +0300 Jukka Juslin wrote:
> du_bing@my-dejanews.com wrote:
>>
>> Hello there,
>>
>> $test="hello ";
>>
>> What's the best way to get rid of those extra spaces in the string $test to
>> make it like "hello".
>
> Probably like this:
>
Probably - I take it that you didnt test it then ?
> #!/usr/bin/perl
>
> $name = "jukka ";
> $name =~ s/\s.*//;
> print ($name);
>
Er. I would like you to test what happens when the string has other spaces
in it as well as at the end :
$name = " I wonder what will happen to this string ";
/J\
--
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: 21 Apr 1999 15:56:50 -0600
From: Eric The Read <emschwar@rmi.net>
Subject: Re: How to get rid of the tailing spaces?
Message-Id: <xkfu2u9iqn1.fsf@valdemar.col.hp.com>
Jukka Juslin <jtjuslin@wannabe.mit.edu> writes:
> du_bing@my-dejanews.com wrote:
> > What's the best way to get rid of those extra spaces in the string $test to
> > make it like "hello".
>
> Probably like this:
>
> #!/usr/bin/perl
>
> $name =~ s/\s.*//;
This won't work. Internal spaces will be removed as well-- if $name was
"My friend Bob ", then your solution would leave "My". Replacing the
'.*' with '+' would give you 'Myfriend Bob '.
The FAQ lists a much better solution. Why not consult it, instead of
coming up with your own answers? A lot of time and effort has gone into
creating it; not taking advantage of that time and effort is almost
insulting to the people who wrote it.
-=Eric
------------------------------
Date: Wed, 21 Apr 1999 20:57:25 +0100
From: "Wayne Keenan" <tripix@tdi-net.freeserve.co.uk>
Subject: Re: How to join
Message-Id: <7flb17$ft8$1@news4.svr.pol.co.uk>
#!/usr/bin/perl
my @list = ( "sep", "by", "a", "char");
my $sep = " ";
$joined1 = join($sep,@list);
$joined2 = my_join($sep,@list);
print "perls built in which can be found with perdoc -f split and perldoc -f
join says: $joined1\n";
print "roll your own says: $joined2\n";
exit;
sub my_join
{
my $sep = shift;
my @list = @_;
my $ret = "";
foreach $item (@list)
{
$ret .= $item.$sep;
}
return ($ret);
}
------------------------------
Date: Wed, 21 Apr 1999 13:48:41 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: How to join
Message-Id: <MPG.1187d9813e3c7a1c989900@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <7flb17$ft8$1@news4.svr.pol.co.uk> on Wed, 21 Apr 1999
20:57:25 +0100, Wayne Keenan <tripix@tdi-net.freeserve.co.uk> says...
...
> $joined1 = join($sep,@list);
> $joined2 = my_join($sep,@list);
...
> sub my_join
> {
> my $sep = shift;
> my @list = @_;
> my $ret = "";
>
> foreach $item (@list)
> {
> $ret .= $item.$sep;
> }
> return ($ret);
> }
My newsreader didn't hook this to a previous post and there are no
references and there is no such article on DejaNews, so I'm not sure
what you are getting at. Note that the two results differ (your test
didn't show the trailing space from the subroutine; try 'eq' or wrap the
variables with |s in the printout).
But a benchmark is enlightening:
Benchmark: timing 65536 iterations of Join, My_Join...
Join: 1 wallclock secs ( 0.81 usr + 0.00 sys = 0.81 CPU)
My_Join: 7 wallclock secs ( 6.34 usr + 0.00 sys = 6.34 CPU)
Now tell us what your point is???
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 21 Apr 1999 22:21:43 +0100
From: "Wayne Keenan" <tripix@tdi-net.freeserve.co.uk>
Subject: Re: How to join
Message-Id: <7flfu3$k79$1@news4.svr.pol.co.uk>
>My newsreader didn't hook this to a previous post and there are no
>references and there is no such article on DejaNews, so I'm not sure
>what you are getting at. Note that the two results differ (your test
>didn't show the trailing space from the subroutine; try 'eq' or wrap the
>variables with |s in the printout).
>
>But a benchmark is enlightening:
>
>Benchmark: timing 65536 iterations of Join, My_Join...
> Join: 1 wallclock secs ( 0.81 usr + 0.00 sys = 0.81 CPU)
> My_Join: 7 wallclock secs ( 6.34 usr + 0.00 sys = 6.34 CPU)
>
>Now tell us what your point is???
>
This should have been a follow on to the recently posted:
"How to Merge " (or close)
sorry.
The extra (okay, buggy) code was just there as a 30 second knock-up of how
to do it if the
original poster didnt bother to take the "longer shorter" path (i.e. reading
the docs first)
and wanted a merge mechanism. (initialy intended as a piss take)
Regards
Wayne
------------------------------
Date: 21 Apr 1999 17:46:13 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: How to join
Message-Id: <x7ogkhd4uy.fsf@home.sysarch.com>
>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:
LR> [Posted and a courtesy copy mailed.]
LR> In article <7flb17$ft8$1@news4.svr.pol.co.uk> on Wed, 21 Apr 1999
LR> 20:57:25 +0100, Wayne Keenan <tripix@tdi-net.freeserve.co.uk> says...
LR> ...
>> $joined1 = join($sep,@list);
>> $joined2 = my_join($sep,@list);
LR> ...
>> sub my_join
>> {
>> my $sep = shift;
>> my @list = @_;
>> my $ret = "";
>>
>> foreach $item (@list)
>> {
>> $ret .= $item.$sep;
>> }
>> return ($ret);
>> }
LR> My newsreader didn't hook this to a previous post and there are no
LR> references and there is no such article on DejaNews, so I'm not sure
LR> what you are getting at. Note that the two results differ (your test
LR> didn't show the trailing space from the subroutine; try 'eq' or wrap the
LR> variables with |s in the printout).
not only that, and the benchmark, but it appends an extra $sep to the
string.
a much simpler sub without using join and it is correct is:
sub my_join {
local( $" ) = shift ;
"@_"
}
or even
do{ local( $" ) = $sep ; "@_" }
but join is semantically better and probably faster.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Wed, 21 Apr 1999 13:25:43 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: how to merge?
Message-Id: <MPG.1187d425ae18f6159898ff@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <7fl9gq$lt6$1@nnrp1.dejanews.com> on Wed, 21 Apr 1999
19:39:07 GMT, bing-du@tamu.edu <bing-du@tamu.edu> says...
> I know how to use 'split' to cut a string. How to merge all the elements (but
> seperated by space) of a list?
perldoc -f join
Looking once or many times over the list of functions in perlfunc will
answer many of your questions.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 21 Apr 1999 10:00:54 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Is it possible to "reset" the ?? pattern search?
Message-Id: <mmlkf7.bt5.ln@magna.metronet.com>
rogDH (rogdh@iname.com) wrote:
: I have a pattern search of ?GOTO? in a sub-routine.
: Can I reset the ?? to an "initial"state each time I enter the sub?
Is this a late April Fool's joke or something?
The very first sentence of the description of ?PATTERN? in
perlop.pod says how to do that, complete with example code.
You can't really be posting about ?PATTERN? without spending
the two minutes it takes to read up on ?PATTERN? in the
standard Perl docs on your hard disk, can you?
Sheesh!
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 21 Apr 1999 16:08:42 -0400
From: multimax@mulmax.com (Multimax)
Subject: last item in associative array.
Message-Id: <multimax-2104991608420001@read-rfc1918-for-details.iana.net>
Keywords: associative arrays
How can I find the last item in an associative array?
Is there an equivalent of $#myArray (the last item in @myArray)?
Stephane
------------------------------
Date: Wed, 21 Apr 1999 13:51:32 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: last item in associative array.
Message-Id: <MPG.1187da2c36dae4ac989901@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <multimax-2104991608420001@read-rfc1918-for-details.iana.net>
on Wed, 21 Apr 1999 16:08:42 -0400, Multimax <multimax@mulmax.com>
says...
> How can I find the last item in an associative array?
>
> Is there an equivalent of $#myArray (the last item in @myArray)?
No. Hashes are not ordered. There is no 'last item'. Period.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 21 Apr 1999 16:59:43 -0400
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: sjose@mulmax.com
Subject: Re: last item in associative array.
Message-Id: <371E3C3F.DCB1DCA2@giss.nasa.gov>
Multimax wrote:
>
> How can I find the last item in an associative array?
hashes are unordered, so the term "last" cannot be
meaningfully applied to them.
Jay Glascoe
------------------------------
Date: Wed, 21 Apr 1999 14:07:15 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: last item in associative array.
Message-Id: <MPG.1187dde1c7d8a619989903@nntp.hpl.hp.com>
In article <multimax-2104991608420001@read-rfc1918-for-details.iana.net>
on Wed, 21 Apr 1999 16:08:42 -0400, Multimax <multimax@mulmax.com>
says...
> How can I find the last item in an associative array?
>
> Is there an equivalent of $#myArray (the last item in @myArray)?
No. Hashes are not ordered.
But you might want to read this in perlfaq4: "How can I always keep my
hash sorted?"
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 21 Apr 1999 15:24:38 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: last item in associative array.
Message-Id: <371e4216@cs.colorado.edu>
Keywords: associative arrays
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, sjose@mulmax.com writes:
:How can I find the last item in an associative array?
Your question does not apply. Repeat the following
pair of mantras until you Believe:
Hashes contain UNORDERED ASSOCIATIONS of key/value pairs.
Arrays contain ORDERED LISTS of values.
Hashes are for SEARCHING.
Arrays are for ORDERING.
--tom
--
/* dbmrefcnt--; */ /* doesn't work, rats */
--Larry Wall in hash.c from the v4.0 perl source code
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 5443
**************************************