[7219] in Perl-Users-Digest
Perl-Users Digest, Issue: 844 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 11 12:07:21 1997
Date: Mon, 11 Aug 97 09:00:25 -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 Mon, 11 Aug 1997 Volume: 8 Number: 844
Today's topics:
Re: 2 variables = 1 <rootbeer@teleport.com>
Re: adressing arrays <rootbeer@teleport.com>
changing passwd with perl (UNIX) (Gustav Kristoffer Ek)
Re: Counting Files <drummj@mail.mmc.org>
Re: Finding Files under Windows <dean@tbone.biol.sc.edu>
Re: FTP <rootbeer@teleport.com>
GET and POST limits (David Cheitel)
Re: GET and POST limits <rootbeer@teleport.com>
Re: Help with 'if'. <rootbeer@teleport.com>
Re: Help: perl can't find sub in module Socket (brian d foy)
Re: Heres a dumb question.... (brian d foy)
How can I test perl on a mac without browser and server (Arthur Sauer)
Re: How do I get started with win95? (SJK)
Re: How do you determine program runtime? <jhi@alpha.hut.fi>
Re: Numbers to strings with preceeding 000's <rootbeer@teleport.com>
Parsing help (The Whopper)
Re: Perl5 can not load cgi-lib.pl <rootbeer@teleport.com>
Re: Regex wizard (was: Re: Is there a perl IDE?) <usenet-tag@qz.little-neck.ny.us>
Sleekness (was: Re: Visual representation of UNIX Direc <rootbeer@teleport.com>
Re: Sleekness (was: Re: Visual representation of UNIX D (Tushar Samant)
sleep for a few hundrad milli seconds <aribindi@cig.mot.com>
sleep for a few hundrad milli seconds <aribindi@cig.mot.com>
Re: Sorting this file is killing me <rootbeer@teleport.com>
Re: Sorting this file is killing me (Andrew M. Langmead)
splice <kusterma@htsa.hva.nl>
Substring substitution in PATH variable (Mr. Blue)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 11 Aug 1997 07:01:41 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Pat Trainor <ptrainor@aura.title14.com>
Subject: Re: 2 variables = 1
Message-Id: <Pine.GSO.3.96.970811065718.18561D-100000@julie.teleport.com>
On Sun, 10 Aug 1997, Pat Trainor wrote:
> Newsgroups: comp.lang.perl.misc, comp.lang.perl
If your news administrator still carries comp.lang.perl, please let him
or her know that that newsgroup has not existed since 1995. If you
have such an outdated newsgroup listing, you are probably missing out
on many other valid newsgroups as well. You'll be doing yourself and
many others a favor to use only comp.lang.perl.misc (and other valid
Perl newsgroups) instead.
> I wonder if any of you know how this is done:
>
> variables:
>
> $abcd0001
> $abcd0002
> How can I represent this variable as it changes, with another?
I don't see what you mean by that. Do you want two variables to be
synchronized to have the same values, so that changing $abcd0001 will
change $abcd0002?
> print "key $key has a value of $urlb$count \n";
> } ^^^^^^^^^^^
> Where $urlb would always be: abcd and $count would increment by
> 1 on each pass.
Are you looking for $count++ to increment $count? Or are you trying to do
something like $abcd[$count++] , an array element access? Or do you want a
soft reference?
> The reason this is needed is that the output of this while loop is
> unsorted.
I don't see how any of this could sort anything. But maybe you want Perl's
built-in sort function. Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Mon, 11 Aug 1997 07:15:21 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: denis@mathi.uni-heidelberg.de
Subject: Re: adressing arrays
Message-Id: <Pine.GSO.3.96.970811071317.18561I-100000@julie.teleport.com>
On Mon, 11 Aug 1997 denis@mathi.uni-heidelberg.de wrote:
> i tried to adress the elementes of adresse. adressing them with
> $xxx[13] for example works, but if i use a variable it doesnot work any
> more...
Are you saying that this does not work?
$xxx[13] = "here";
$foo = 13;
print "The value is '$xxx[$foo]'\n";
If that's not it, could you give us some example code which doesn't do
what you think it should? Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Mon, 11 Aug 1997 16:38:47 +0200
From: stoffer@netcetera.dk (Gustav Kristoffer Ek)
Subject: changing passwd with perl (UNIX)
Message-Id: <stoffer-1108971638480001@loke.netcetera.dk>
What is the easiest way to change a password from within a perl script? I
have looked at setpwent() but I dont know if its the right thing to do.
I would really appreciate an example.
Regards
- gustav
---------------------------------------------------------------------
Gustav Kristoffer Ek - Netcetera - Finsensvej 80 - 2000 Frederiksberg
tlf 38 88 32 22 / 20 40 00 05 / 38 88 20 38 ext 341 - Fax 38 88 30 38
Webdesign, Webhotel, Mailhotel, UUCP og mere http://www.netcetera.dk/
------------------------------
Date: 11 Aug 1997 15:32:50 GMT
From: "Jeffrey R. Drumm" <drummj@mail.mmc.org>
Subject: Re: Counting Files
Message-Id: <01bca66c$51449860$111e71c6@ohmigod>
Zenin <zenin@best.com> wrote in article <5sgdo5$17a$1@nntp2.ba.best.com>...
> Mark J. Schaal <mark@tstonramp.com> wrote:
> > If it doesn't have to be a perl program...
> > ls *.dat | wc -l
>
> Or, if you only want to fork one process...
> echo *.dat | wc -w
>
> <grin>
>
> --
> -Zenin
> zenin@best.com
>
Neither of which will work without some 3rd party support in the example
given by the original poster, who has the misfortune to be doing his coding
on one of Bill Gates' little playthings.
--
- Jeffrey R. Drumm - Systems Integration Specialist
Maine Medical Center - IS Department
420 Cumberland Ave - Portland ME 04101
Voice: 207-871-2150 - FAX: 207-871-6440
drummj@mail.mmc.org
------------------------------
Date: 11 Aug 1997 10:26:19 -0400
From: Dean Pentcheff <dean@tbone.biol.sc.edu>
Subject: Re: Finding Files under Windows
Message-Id: <m1hgcwbxtg.fsf@nauplius.psc.sc.edu>
"Reuters Ltd." <shieling@dircon.co.uk> writes:
> Is there a way of using perl to search through directories to find file
> paths with Windows NT4?
>
> Thanks in advance
See the File::Find module (included in the current standard Win95/NT
perl release). It's slightly bizarre, and I had to peek at the code
to figure out that you could feed it any number of starting
directories, but it works just fine.
-Dean
--
N. Dean Pentcheff <pentcheff@acm.org> WWW: http://tbone.biol.sc.edu/~dean/
Biological Sciences, Univ. of South Carolina, Columbia SC 29208 (803-777-3936)
PGP ID=768/22A1A015 Keyprint=2D 53 87 53 72 4A F2 83 A0 BF CB C0 D1 0E 76 C0
Get PGP keys and information with the command: "finger dean@tbone.biol.sc.edu"
------------------------------
Date: Mon, 11 Aug 1997 07:34:19 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Clive McAdam <cmcadam@icl.co.za>
Subject: Re: FTP
Message-Id: <Pine.GSO.3.96.970811073000.18561K-100000@julie.teleport.com>
On Mon, 11 Aug 1997, Clive McAdam wrote:
> How can I let users FTP files into their home directories using Perl and
> a web interface?
Here's one way to do it.
#!/usr/bin/perl
print "Content-type: text/plain\n\nPlease use your FTP
client to upload your files to
your home directory.\n";
:-)
But maybe you're looking to use CGI.pm or a similar module to do something
a little different than you asked. Good luck!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Sun, 10 Aug 1997 13:40:58 GMT
From: david1@earthlink.net (David Cheitel)
Subject: GET and POST limits
Message-Id: <5sn551$dgo@ecuador.earthlink.net>
What are the limits on url size that can be passed via a get and a post. I am
working on a online testing program and need to pass the users answers to 50
questions as well as the question numbers themselves (the test is randomly
generated and questions vary.)
What is the best way to pass such a large amount of information in a form
submission?
Thanks
Reply to david1@earthlink.net
------------------------------
Date: Mon, 11 Aug 1997 07:49:37 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: David Cheitel <david1@earthlink.net>
Subject: Re: GET and POST limits
Message-Id: <Pine.GSO.3.96.970811074348.18561N-100000@julie.teleport.com>
On Sun, 10 Aug 1997, David Cheitel wrote:
> What are the limits on url size that can be passed via a get and a post.
The answer is the same whether you're using Perl or another language, so
that's a clue that maybe it's not a Perl question. In this case, it sounds
like a web programming question, so you probably should check the docs and
FAQs and related standards. If you can't find the answer in those places,
you should probably check a newsgroup about programming for the web, such
as comp.infosystems.www.authoring.cgi. If you have Perl questions which
aren't found in the FAQs and docs, though, those questions are welcome
here. Hope this helps!
news:comp.infosystems.www.authoring.cgi
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Mon, 11 Aug 1997 07:41:32 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Page <page@pageg.demon.co.uk>
Subject: Re: Help with 'if'.
Message-Id: <Pine.GSO.3.96.970811073448.18561L-100000@julie.teleport.com>
On Mon, 11 Aug 1997, Page wrote:
> I am trying to insert an "if" statement into my script so that if fields
> are empty they are not displayed in the emails.
> > if ($FORM{'SubjectEnquiry'} eq "") {
> > goto A;
> > exit;
> > }
> > print "Specific Subject of Enquiry: $FORM{'SubjectEnquiry'}\n";
> > A
Eek! It's a goto! :-)
You can do what you were trying to do with this simpler code.
if ($FORM{'SubjectEnquiry'} ne '') {
print "Specific Subject of Enquiry: $FORM{'SubjectEnquiry'}\n";
}
Or this (even simpler) code.
print "Specific Subject of Enquiry: $FORM{'SubjectEnquiry'}\n"
if $FORM{'SubjectEnquiry'} ne '';
It's a long story, but few (if any) good Perl programs use goto LABEL. You
can always write your script to avoid goto, and most good programmers will
advise you always to do so. But even the people who claim that goto can be
useful don't use it in this case. :-)
Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Mon, 11 Aug 1997 11:18:18 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Help: perl can't find sub in module Socket
Message-Id: <comdog-ya02408000R1108971118180001@alice.walrus.com>
In article <5sg12u$q6l$1@vixen.cso.uiuc.edu>, l-schro@students.uiuc.edu (larry paul schrof) wrote:
>I recently started using the module stuff under perl, and am having
>a difficult problem. At the top of my code, I have a 'use Socket;'
>but further down in the code I do a call such as this:
>
>$addr = inet_atom($machine);
>Undefined subroutine &main::inet_atom called at ./load.pl line 30.
>I have checked the O'Reilly Perl5 book and I know inet_atom() is in
>the Socket module.
are you sure?
maybe you mean inet_aton(), which has an 'n' in place of your 'm'.
this function takes a hostname or dotted decimal IP and returns
a four byte, packed string. see p. 499 of the Blue Camel for
more :)
--
brian d foy <comdog@computerdog.com>
please forgive any posting wierdness - i've recently changed providers
and things are a bit wonky
------------------------------
Date: Mon, 11 Aug 1997 10:52:05 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Heres a dumb question....
Message-Id: <comdog-ya02408000R1108971052050001@alice.walrus.com>
[redirect to comp.lang.perl.misc since this has nothing to do with
the CGI]
In article <5s7fmc$n4f$1@News.Dal.Ca>, dvanwage@tuns.ca (Darren VanWageningen) wrote:
>I have a text file. There are multiple fields in this file. All I want to
>do is assign a variable to the field names. here is a sample line of the file
>
>Eric~Wright~0516948~1-555-2222~USA
>
>So, all the fields are separated by a ~. What I need is to assign the
>Eric to $name, Wright to $lname, etc. (you get the drift)
>But, the code I have now is not recogising the ~ symbol. It is skipping
>them all, and using the last field only.
don't know what you are doing since you didn't show your code, but this
works:
#!/usr/bin/perl
$string = q|Eric~Wright~0516948~1-555-2222~USA|;
($first_name, $last_name, $thingy, $phone_number, $country) =
split /~/, $string, 5;
print <<"TEXT";
First Name: $first_name
Last Name: $last_name
Thingy: $thingy
Phone Number: $phone_number
Country: $country
TEXT
__END__
First Name: Eric
Last Name: Wright
Thingy: 0516948
Phone Number: 1-555-2222
Country: USA
--
brian d foy <comdog@computerdog.com>
please forgive any posting wierdness - i've recently changed providers
and things are a bit wonky
------------------------------
Date: Mon, 11 Aug 1997 15:14:53 +0100
From: arthur@sauer.demon.nl (Arthur Sauer)
Subject: How can I test perl on a mac without browser and server?
Message-Id: <arthur-1108971514540001@sauer.demon.nl>
I'm learning to program in Perl but I want to test my programs on my own
computer so I can see what a program actually does.
How can I send a commandline to the program?
How can I for instance simulate a form sent with post?
Is there a handy program (68k mac) or perlscript to do this?
--
------------------- Arthur Sauer -------------------
------------------------------
Date: Mon, 11 Aug 1997 14:37:08 GMT
From: knetsch@golden.net.no.spam (SJK)
Subject: Re: How do I get started with win95?
Message-Id: <33ef21ab.6553497@news.golden.net>
On 9 Aug 97 07:42:35 GMT, "Richard Butcher" <mailus@web-uk.com> wrote:
>Please don't flame me if this question has been answered a million times
>already - believe me, I've searched for the answer.
>
>Is it possible to get into Perl without a degree in programming other
>languages? !
>
>I've downloaded perl5 and read every faq I can find and monitored this
>newsgroup for a fortnight.
>
>The message I get is that unless you've got enough knowledge and software
>to compile in C or whatever, there's no way forward.
>
<SNIP>
>I cannot be alone! Someone must have asked for this before. I must be part
>of a shareware market.
>
>Help.
>
>richard@web-uk.com
Help is at hand my poor fellow lost soul. Do not despair!
Actually, I went through the same problem when I was looking for the Win32 build
of Perl. After exhaustively searching through the web for over an hour using
the search engines, I found the web site. Then someone conveniently mentioned
the web site address the next day in this newsgroup in one of their posts.
Ahhhh, such is life.
Find the actual compiled version for Windows 95 on Intel based machines at
http://www.perl.hip.com/
Good luck!
Stuart Knetsch
Remove the you know what from my address to send me E-mail
------------------------------
Date: 11 Aug 1997 13:13:24 +0300
From: Jarkko Hietaniemi <jhi@alpha.hut.fi>
To: ils@pipcom.com
Subject: Re: How do you determine program runtime?
Message-Id: <oeelo29m3i3.fsf@alpha.hut.fi>
trockij@transmeta.com (Jim Trocki) writes:
> In article <33ee7756.10233296@news.pipcom.com>,
> Scott Card <ils@pipcom.com> wrote:
> >How can i determine the running time of a program?
> >
> >I have a cron cgi program and need to know exactly how many
> >milliseconds it runs until it terminates.
>
> You'll need to do a "require 'syscall.ph'", and use the getrusage(2)
> system call to get this information. getrusage(2) will return the amount
> of consumed user and system time.
>
> It could be a little tedious to do the rusage structure correctly in Perl.
> Use pack to create the scalar that you pass to getrusage(2), and use
> unpack to separate the results.
getrusage() is available as a part of the
http://www.perl.com/CPAN/modules/by-module/BSD/BSD-Resource-1.06.tar.gz
--
$jhi++; # http://www.iki.fi/~jhi/
# There is this special biologist word we use for 'stable'.
# It is 'dead'. -- Jack Cohen
------------------------------
Date: Mon, 11 Aug 1997 07:12:25 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Brian Lavender <brian@brie.com>
Subject: Re: Numbers to strings with preceeding 000's
Message-Id: <Pine.GSO.3.96.970811071134.18561H-100000@julie.teleport.com>
On Mon, 11 Aug 1997, Brian Lavender wrote:
> I have a list
> @list = 1..30;
>
> I want to make this list into a list of strings so the strings are in
> the format.
> @stringlist =
> ('001','002','003','004','005','006','007','008','009','010','011','012',...,'029','030');
>
> How do I do this?
Use the map function and sprintf with a format containing "03". Hope this
helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 11 Aug 1997 14:28:30 GMT
From: lgw@cs.buffalo.edu (The Whopper)
Subject: Parsing help
Message-Id: <5sn7ie$j5v$1@prometheus.acsu.buffalo.edu>
I need some major help. I wrote a program a few months back that parses
the sys$log.err file on Netware 3.12. It searches for a particular string,
then mails a message to certain people. Recently I've encountered some
problems where the program does not get past certain points in the log
file. I am wondering, is there a limit to the size of a file perl can read
in? If necessary, I can send any help-givers the code and the log file so
they can examine it. Immediate help would be much appreciated.
Thank you,
Larry G. Wapnitsky
lgw@cs.buffalo.edu - SUNY Buffalo Computer Science Department
lgw@cit.buffalo.edu - SUNY Buffalo CIT/LAN Systems
------------------------------
Date: Mon, 11 Aug 1997 07:10:10 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "MS. JONES" <shakes999@huskynet.com>
Subject: Re: Perl5 can not load cgi-lib.pl
Message-Id: <Pine.GSO.3.96.970811070942.18561G-100000@julie.teleport.com>
On Sun, 10 Aug 1997, MS. JONES wrote:
> The error is can not load cgi-lib.=20
Try using CGI.pm instead. Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 11 Aug 1997 14:41:09 GMT
From: Eli the Bearded <usenet-tag@qz.little-neck.ny.us>
Subject: Re: Regex wizard (was: Re: Is there a perl IDE?)
Message-Id: <eli$9708111034@qz.little-neck.ny.us>
Tom Phoenix <rootbeer@teleport.com> wrote:
> I could write at least three dozen which someone could mean by that
> phrase. Gee, I wonder what the wizard comes up with when you type in
> "match an e-mail address"? :-)
/.*/s
Elijah
------
there are a world of addresses out there not RFC822
------------------------------
Date: Mon, 11 Aug 1997 07:09:06 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Tushar Samant <scribble@shoga.wwa.com>
Subject: Sleekness (was: Re: Visual representation of UNIX Directories?)
Message-Id: <Pine.GSO.3.96.970811070422.18561F-100000@julie.teleport.com>
On 10 Aug 1997, Tushar Samant wrote:
> roswell@umbc.edu writes:
> >I'm looking for a visual representation of directories in UNIX. Any
> >solutions are welcome.
>
> Trying to reconstruct a command I had snarfed off the net long ago:
>
> find . -print | sed -e 's,[^/]*/\([^/]*\)$,`--\1,' -e 's,[^/]*/,| ,g'
>
> Perl would of course give more spectacular results, but this one is
> just so sleek ...
Do you mean to say that a perl version of that script would be less sleek
than the existing potentially-buggy version requiring two processes? :-)
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 11 Aug 1997 10:44:58 -0500
From: scribble@shoga.wwa.com (Tushar Samant)
Subject: Re: Sleekness (was: Re: Visual representation of UNIX Directories?)
Message-Id: <5snc1s$cqa@shoga.wwa.com>
rootbeer@teleport.com writes:
>On 10 Aug 1997, Tushar Samant wrote:
>> roswell@umbc.edu writes:
>> >I'm looking for a visual representation of directories in UNIX. Any
>> >solutions are welcome.
>>
>> Trying to reconstruct a command I had snarfed off the net long ago:
>>
>> find . -print | sed -e 's,[^/]*/\([^/]*\)$,`--\1,' -e 's,[^/]*/,| ,g'
>>
>> Perl would of course give more spectacular results, but this one is
>> just so sleek ...
>
>Do you mean to say that a perl version of that script would be less sleek
>than the existing potentially-buggy version requiring two processes? :-)
Yes, don't you think? The messy, non-orthogonal monstrosity of a
language makes everything facile. Where there's facility there's
no sleekness. It offends my sense of frugality, ingenuity, and
everything else that my Yankee ancestors stood for.
------------------------------
Date: Mon, 11 Aug 1997 09:02:05 -0500
From: "Syam P. Aribindi" <aribindi@cig.mot.com>
Subject: sleep for a few hundrad milli seconds
Message-Id: <33EF1B5D.167E@cig.mot.com>
Can anybody help me:
I need to routine which allows a sleep time of less of 1 second. The
sleep time must be a configurable one, just like the one we have for
sleep in seconds.
sub msleep {
$sleep_time = @_;
...
...
}
Thanks in advance.
##################################
Syam Aribindi
Cellular Infrastructure Group
Motorola Inc.
aribindi@cig.mot.com
(630)-305-4519
##################################
------------------------------
Date: Mon, 11 Aug 1997 09:00:11 -0500
From: "Syam P. Aribindi" <aribindi@cig.mot.com>
Subject: sleep for a few hundrad milli seconds
Message-Id: <33EF1AEB.41C6@cig.mot.com>
Can anybody help me:
I need to routine which allows a sleep time of less of 1 second. The
sleep time must be a configurable one, just like the one we have for
sleep in seconds.
sub msleep {
$sleep_time = @_;
...
...
}
Thanks in advance.
##################################
Syam Aribindi
Cellular Infrastructure Group
Motorola Inc.
aribindi@cig.mot.com
(630)-305-4519
##################################
------------------------------
Date: Mon, 11 Aug 1997 07:29:00 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Thomas Wernitz <thomas_wernitz@tait.co.nz>
Subject: Re: Sorting this file is killing me
Message-Id: <Pine.GSO.3.96.970811071822.18561J-100000@julie.teleport.com>
On 11 Aug 1997, Thomas Wernitz wrote:
> In article <871064792.31232@dejanews.com>, paries@advicom.net wrote:
> > Marge Simpson|100.00
> > bart Simpson|1000.00
> > joe simth|300.00
> >
> > I need to read in this file and the sort the pairs by field 2 and then
> > load into either an array of arrays or hash.
> @source = <>; # slurp in the file
>
> map {push @sorted, [$1 => $2]}
> sort {(split(/\|/,$a))[1] <=> (split(/\|/,$b))[1]} @source;
Then again, maybe not. Besides the fact that it's bad form to use map in a
void context (use foreach instead), you're not going to get anything
useful in @sorted with this code. (And, if it worked, you'd be splitting
the lines again and again in the sort.) Nevertheless, this is easily done
with a sort of a map, which may have been what you were thinking about.
You may also want to chomp @source.
Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Mon, 11 Aug 1997 14:00:34 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Sorting this file is killing me
Message-Id: <EEr5Kz.5Bv@world.std.com>
[copy of this article sent to the cited author via e-mail]
Anagrams of the Word <jefpin@bergen.org> writes:
>If you have any trouble, let me know.
yes, I have troubles. Your script emits the folllowing error message:
Type of arg 1 to keys must be hash (not subroutine entry) at test.prog line 16, near "%salary;"
Execution of test.prog aborted due to compilation errors.
Even if it did run, I doubt it would have the intended effect, since
it is putting the result into a hash. Hashes, do not keep the order of
their contents. Your code implies that you have a fundimental lack of
knowledge about perl, like not even having the knowledge of someone
who has read through the "Learning Perl". (I don't have my copy handy,
but according to the online index to "Learning Perl" at
<URL:http://www.ora.com/catalog/lperl2/inx.html> the order of
associative arrays is covered on page 66.) Also, your loading the the
%salary hash does not do what you want it to, (or what the coments say
it does.) And finally, as a minor point, your filling of @data is more
memory inefficient than possible needs to be. (why not read line line
at a time and fill in %salary? Why keep two data structures with
identical data?)
Please, any novice perl programmers reading Jeff's post. If you want
to know about sorting an array based of a computable field, you would
be much better served by reading the the FAQ entry
<URL:http://www.perl.com/CPAN/doc/manual/html/pod/perlfaq4/
How_do_I_sort_an_aray_by_anyth.html> than by Jeff's posting.
--
Andrew Langmead
------------------------------
Date: Mon, 11 Aug 1997 17:24:21 -0100
From: Jeroen Kustermans <kusterma@htsa.hva.nl>
Subject: splice
Message-Id: <33EF58D5.237C@htsa.hva.nl>
Hee Dude's
I've got the following problem:
I open a file for reading and are putting the content in a array:
--
open(ALIASFILE, "<$alias") || die "Can't open $alias\n";
@aliasfile = <ALIASFILE>;
close(ALIASFILE);
--
next, I want to scan all the lines of my array to see if some var is
there.
If it's there, remove that entry from my array
--
$counter=0;
foreach (@aliasfile) {
print "$_ : $counter\n";
if (/test/) {
splice(@aliasfile, $counter, 1);
}
$counter++;
}
--
Now I want to write my array to a new file.
--
open(ALIASFILE, ">$alias2") || die "Can't open for writing\n"
print ALIASFILE @aliasfile;
close(ALIASFILE);
--
If I got a file like this:
test:test
piet:piet
jan:jan
test:test
It's working real fine. But if I got a file like this:
test:test
test:test
piet:piet
jan:jan
test:test
I'll get the next result:
test:test
piet:piet
jan:jan
How is this possible and how should I solve this.
Greetings
Jeroen
------------------------------
Date: 11 Aug 1997 10:53:37 -0400
From: car@access2.digex.net (Mr. Blue)
Subject: Substring substitution in PATH variable
Message-Id: <5sn91h$qip@access2.digex.net>
Hello, I'm new to perl. ANy help appreciated with the following.
We need a perl script that will substitute substrings within the
PATH environment variable. Our users can have several "playpens" where
they develop code. The PATH variable has to pick up the binaries that
they build. If they change playpens, we want them to pick up the binaries
in the NEW playpen. What we need is esentially a script that will "zap"
parts of their path and replace them.
Example: (We're using K shell now)
// current playpen is /home/fred/playpen2
export PATH=.:/usr/bin:/home/fred/playpen2/bin:/usr/local/foo:/usr/local/bar
The user runs a command as follows:
setPlayPen /home/fred/playpen2
We want the PATH to be updated to:
export PATH=.:/usr/bin:/home/fred/playpen2/bin:/usr/local/foo:/usr/local/bar
Email replies appreciated.
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.
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 844
*************************************