[17533] in Perl-Users-Digest
Perl-Users Digest, Issue: 4953 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 22 18:14:29 2000
Date: Wed, 22 Nov 2000 15:10:21 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <974934621-v9-i4953@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 22 Nov 2000 Volume: 9 Number: 4953
Today's topics:
Perl version change question tlynch001@my-deja.com
Re: Perl version change question (Tony L. Svanstrom)
Re: Perl version change question (Tad McClellan)
Re: Perl XS (Ilya Zakharevich)
Re: permissions issue...i think (Honza Pazdziora)
Re: permissions issue...i think akothek@my-deja.com
Printing out a file in reverse... dan@karran.net
Re: Printing out a file in reverse... <jeff@vpservices.com>
Re: Printing out a file in reverse... <soeder@ai-lab.fh-furtwangen.de>
Re: Printing out a file in reverse... <uri@sysarch.com>
Re: Problem r/w binary files (Honza Pazdziora)
Re: Problem with simple del file script <mischief@velma.motion.net>
Proper HTTP_REFERER Usage... <webmaster@860.org>
Re: Proper HTTP_REFERER Usage... <webmaster@860.org>
Re: Proper use of $ENV{HTTP_REFERER} (Jon Bell)
Re: Proper use of $ENV{HTTP_REFERER} <crowj@aol.com>
Re: receive email and process via perl (Honza Pazdziora)
Re: rounding with "printf %f" <iltzu@sci.invalid>
Re: Simple Question :) <peter.sundstrom@eds.com>
Re: Sort runtime 5.005 vs 5.004 (Garry Williams)
Re: Sort runtime 5.005 vs 5.004 <jimharrison3@home.com>
Re: Sort strings before numbers <hbhb@gmx.de>
splitting a word <thanh.q.lam@alcatel.com>
Re: splitting a word <soeder@ai-lab.fh-furtwangen.de>
Re: splitting a word (Tad McClellan)
Re: Tom Christiansons' 'style' <mischief@velma.motion.net>
trouble with Image::Magick annotate() dtbaker_dejanews@my-deja.com
Re: What is the difference in these??? <ves@ves.net>
Re: What is the difference in these??? (Garry Williams)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 22 Nov 2000 19:07:51 GMT
From: tlynch001@my-deja.com
Subject: Perl version change question
Message-Id: <8vh5i5$3ie$1@nnrp1.deja.com>
I submitted homework to my teacher on 11/2. I'm sure it worked.
On 11/21 he calls me into his office. My Perl program doesn't work.
The program doesn't seem to calculate checksums properly anymore.
It appears that the school upgraded from 5.00503 to 5.6.0 on Nov 17th.
I don't even know who is responsible for this server, and it is the
holiday, so not much luck yet in finding out exactly what happened.
If this upgrade occurred, could it be responsible for my program's
sudden inability to work? Or did gremlins scrabble my files?
Any insight you can give me will be appreciated.
-tl
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 22 Nov 2000 20:27:11 GMT
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: Perl version change question
Message-Id: <1ekiowq.emt1es640pgcN%tony@svanstrom.com>
<tlynch001@my-deja.com> wrote:
> I submitted homework to my teacher on 11/2. I'm sure it worked.
> On 11/21 he calls me into his office. My Perl program doesn't work.
> The program doesn't seem to calculate checksums properly anymore.
>
> It appears that the school upgraded from 5.00503 to 5.6.0 on Nov 17th.
>
> I don't even know who is responsible for this server, and it is the
> holiday, so not much luck yet in finding out exactly what happened.
>
> If this upgrade occurred, could it be responsible for my program's
> sudden inability to work? Or did gremlins scrabble my files?
>
> Any insight you can give me will be appreciated.
Show the script and people might help ya...
/Tony
--
/\___/\ Who would you like to read your messages today? /\___/\
\_@ @_/ Protect your privacy: <http://www.pgpi.com/> \_@ @_/
--oOO-(_)-OOo---------------------------------------------oOO-(_)-OOo--
on the verge of frenzy - i think my mask of sanity is about to slip
---ôôô---ôôô-----------------------------------------------ôôô---ôôô---
\O/ \O/ ©99-00 <http://www.svanstrom.com/?ref=news> \O/ \O/
------------------------------
Date: Wed, 22 Nov 2000 15:21:48 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Perl version change question
Message-Id: <slrn91oams.nbf.tadmc@magna.metronet.com>
On Wed, 22 Nov 2000 20:27:11 GMT, Tony L. Svanstrom <tony@svanstrom.com> wrote:
><tlynch001@my-deja.com> wrote:
>
>> I submitted homework to my teacher on 11/2. I'm sure it worked.
>> On 11/21 he calls me into his office. My Perl program doesn't work.
>> The program doesn't seem to calculate checksums properly anymore.
>>
>> It appears that the school upgraded from 5.00503 to 5.6.0 on Nov 17th.
>> Any insight you can give me will be appreciated.
>
>Show the script and people might help ya...
And check:
perldoc perldelta
( on the machine with 5.6 )
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 22 Nov 2000 20:33:23 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Perl XS
Message-Id: <8vhaij$q9m$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Soumen Das
<soumen.das@cp.net>],
who wrote in article <t1o5vnclqurq58@corp.supernews.com>:
> On NT :
> - There are multiple cpp files and .h files.
> - the exported interfaces are consolidated in one header file.
> - i need to build the perl wrappers over these exported interfaces.
> - the .c file generated by xubpp is he interface file that got generated but
> it failed to compile with the rest of the .cpp files.
If you want to make your life simple, make an independent .lib of your
C/C++ files, and make the XS extension link against this library.
When things mature, you may want to make a daughter Makefile.PL in a
subdirectory to build the library.
Ilya
------------------------------
Date: Wed, 22 Nov 2000 17:27:42 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: permissions issue...i think
Message-Id: <G4FsI6.GvE@news.muni.cz>
On Wed, 22 Nov 2000 15:53:30 GMT, akothek@my-deja.com <akothek@my-deja.com> wrote:
> this should have a simple solution.
>
> i have written a perl program that is basically a wrapper around a
> bunch of perl and shell scripts. runs fine when i or other users cd to
> the dir and run it. but cant run the program from other dirs...it does
> not find the inner scripts...my question is:
> do i need to explicitly specify the complete pathname in all the inner
> scripts?
No, you can also set the PATH environment variable.
> can i add some code to the wrapper script that will fake the cd and run
No need to fake. Just do chdir to where you want to be today.
> OK...clearly this option is preferable because it would amount to
> lesser work and easier to maintain...i tried system("cd /home/mydir")
It worked but only in the process you called.
> but that did not do it...also tried ENV{PWD} = "home/mydir" and that
> didnt work either!!!
Expected -- setting the PWD doesn't affect the pwd.
Yours,
--
------------------------------------------------------------------------
Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
.project: Perl, DBI, Oracle, MySQL, auth. WWW servers, MTB, Spain.
Petition for a Software Patent Free Europe http://petition.eurolinux.org
------------------------------------------------------------------------
------------------------------
Date: Wed, 22 Nov 2000 21:14:41 GMT
From: akothek@my-deja.com
Subject: Re: permissions issue...i think
Message-Id: <8vhcvv$8n6$1@nnrp1.deja.com>
nevermind...should have used chdir...
In article <8vgq5m$qk0$1@nnrp1.deja.com>,
akothek@my-deja.com wrote:
> this should have a simple solution.
>
> i have written a perl program that is basically a wrapper around a
> bunch of perl and shell scripts. runs fine when i or other users cd
to
> the dir and run it. but cant run the program from other dirs...it
does
> not find the inner scripts...my question is:
> do i need to explicitly specify the complete pathname in all the
inner
> scripts?
> or
> can i add some code to the wrapper script that will fake the cd and
run
> OK...clearly this option is preferable because it would amount to
> lesser work and easier to maintain...i tried system("cd /home/mydir")
> but that did not do it...also tried ENV{PWD} = "home/mydir" and that
> didnt work either!!!
>
> pls advise...
>
> thanks!
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 22 Nov 2000 19:42:10 GMT
From: dan@karran.net
Subject: Printing out a file in reverse...
Message-Id: <8vh7ii$52h$1@nnrp1.deja.com>
Hi,
I am currently using code similar to the following to print out the
contents of a text file, line by line:
foreach $i (@data) {
chomp($i);
($name,$email) = split(/\|/,$i);
print "$name - $email";
}
How can I alter this so it prints out the entries in reverse (ie the
last line of the file first, and so on)?
Dan
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 22 Nov 2000 11:56:37 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Printing out a file in reverse...
Message-Id: <3A1C24F5.ACC82720@vpservices.com>
dan@karran.net wrote:
> I am currently using code similar to the following to print out the
> contents of a text file, line by line:
>
> foreach $i (@data) {
> chomp($i);
> ($name,$email) = split(/\|/,$i);
> print "$name - $email";
> }
>
> How can I alter this so it prints out the entries in reverse (ie the
> last line of the file first, and so on)?
In keeping with Perl's tradition of obfuscation and cryptically named
functions, the function to reverse the order of an array is named
"reverse". Go figure! What you want is:
foreach $i(reverse @data) { ... }
Or, perhaps you want the File::ReadBackwards module on CPAN.
--
Jeff
------------------------------
Date: Wed, 22 Nov 2000 21:02:35 +0100
From: Oliver =?iso-8859-1?Q?S=F6der?= <soeder@ai-lab.fh-furtwangen.de>
Subject: Re: Printing out a file in reverse...
Message-Id: <3A1C265B.FEB2F04B@ai-lab.fh-furtwangen.de>
dan@karran.net wrote:
>
> Hi,
>
> I am currently using code similar to the following to print out the
> contents of a text file, line by line:
>
@data2=reverse(@data);
> foreach $i (@data) {
> chomp($i);
> ($name,$email) = split(/\|/,$i);
> print "$name - $email";
> }
>
> How can I alter this so it prints out the entries in reverse (ie the
> last line of the file first, and so on)?
>
> Dan
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
------------------------------
Date: Wed, 22 Nov 2000 21:19:46 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Printing out a file in reverse...
Message-Id: <x7pujnd7ri.fsf@home.sysarch.com>
>>>>> "d" == dan <dan@karran.net> writes:
d> How can I alter this so it prints out the entries in reverse (ie the
d> last line of the file first, and so on)?
use File::ReadBackwards, found on CPAN
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Wed, 22 Nov 2000 17:31:59 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: Problem r/w binary files
Message-Id: <G4FspB.n4H@news.muni.cz>
On Wed, 22 Nov 2000 15:58:08 GMT, toby_m_kramer@my-deja.com <toby_m_kramer@my-deja.com> wrote:
>
> you can reproduce the problem, let me know. I am
> using ActivePerl on Win32.
Function binmode (perldoc -f binmode) is your friend, on these evil
systems that put EOFs to random places of your files.
Yours,
--
------------------------------------------------------------------------
Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
.project: Perl, DBI, Oracle, MySQL, auth. WWW servers, MTB, Spain.
Petition for a Software Patent Free Europe http://petition.eurolinux.org
------------------------------------------------------------------------
------------------------------
Date: Wed, 22 Nov 2000 21:05:19 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Problem with simple del file script
Message-Id: <t1od8f6qkb8t78@corp.supernews.com>
jkipp@mbna.com wrote:
> In article <slrn91nnv7.l5d.rgarciasuarez@rafael.kazibao.net>,
> rgarciasuarez@free.fr (Rafael Garcia-Suarez) wrote:
>> jkipp@mbna.com wrote in comp.lang.perl.misc:
>> > I am trying to go through a directory and delete files that are
> older
>> > than 30 days. Here is what I have, it will print the files, no
> problem,
>> > but will not delete. Thanks for any suggestion
>> > Jim
>> > ------
>> > $path='h:\dbm\mediacreate';
[snip most of non-working script]
Bad.
> Thanks I got it working now. Here is what I have:
> $path='h:\\dbm\\mediacreate';
Very bad.
> opendir (WDIR, "$path") or die "Can't open $path : $!";
> while ($file= readdir WDIR) {
> next if $file=~/^\./;
> $age= -M "$path/$file";
Here you use forward slashes. You could in the above sections, too.
Just because Windows has broken directory delimeters on the command
line (due to hysterical raisins) doesn't mean you have to use the
backslashes from within programs. Windows NT in fact claims POSIX
compliance. I haven't seen any extensive research about NT being
or not being POSIX compliant, but my guess (and what I've heard),
is that it comes pretty close in some areas.
In any case, use forward slashes. It works, is less typing, is
more portable, and looks nicer to boot.
> if ($age > 30) {
> unlink ("$path/$file") or die "Could not delete: $path/$file:
> $!";
> }
> }
Chris
--
Chris Stith - mischief@motion.net
"What is it that puts the spark of an idea into someone's head
for no apparent reason?" asked the student.
"Why do you ask?" replied the teacher.
------------------------------
Date: Wed, 22 Nov 2000 16:08:29 -0500
From: "_Thomas" <webmaster@860.org>
Subject: Proper HTTP_REFERER Usage...
Message-Id: <ZDWS5.53156$KI6.11685371@typhoon.snet.net>
Cross post. Woohoo.
Thanks for the great help btw. :)
> Or however its spelled .. thats not the case ... its more of a "theory"
> thing ...
>
> If I have a script called as follows ...
>
> <img src="/cgi-bin/image.pl" width=1 height=1 border=1>
> on page .. index.html
>
> And I'm checking $ENV{HTTP_REFERER}, recording it to a log .. for ovbious
> reasons, it will record index.html as the referring page most often
because
> technically, thats the file that called the script. I want to know what
> page the user was at BEFORE index.html, so I can tell where they clicked
to
> GET to index.html ..
>
> Any ideas?
>
> Thanks a bunch,
>
> _Thomas
> webmaster@860.org
>
>
>
>
------------------------------
Date: Wed, 22 Nov 2000 16:14:09 -0500
From: "_Thomas" <webmaster@860.org>
Subject: Re: Proper HTTP_REFERER Usage...
Message-Id: <hJWS5.53157$KI6.11686225@typhoon.snet.net>
Gaa ... wrong group. Darn. So sorry.
_Thomas <webmaster@860.org> wrote in message
news:ZDWS5.53156$KI6.11685371@typhoon.snet.net...
> Cross post. Woohoo.
>
> Thanks for the great help btw. :)
>
>
>
> > Or however its spelled .. thats not the case ... its more of a "theory"
> > thing ...
> >
> > If I have a script called as follows ...
> >
> > <img src="/cgi-bin/image.pl" width=1 height=1 border=1>
> > on page .. index.html
> >
> > And I'm checking $ENV{HTTP_REFERER}, recording it to a log .. for
ovbious
> > reasons, it will record index.html as the referring page most often
> because
> > technically, thats the file that called the script. I want to know what
> > page the user was at BEFORE index.html, so I can tell where they clicked
> to
> > GET to index.html ..
> >
> > Any ideas?
> >
> > Thanks a bunch,
> >
> > _Thomas
> > webmaster@860.org
> >
> >
> >
> >
>
>
------------------------------
Date: Wed, 22 Nov 2000 18:42:24 GMT
From: jtbell@presby.edu (Jon Bell)
Subject: Re: Proper use of $ENV{HTTP_REFERER}
Message-Id: <G4Fvyp.MAs@presby.edu>
In article <B8US5.53139$KI6.11666437@typhoon.snet.net>,
_Thomas <webmaster@860.org> wrote:
>
>First: What would the cgi newsgroup be? I did a quick search for cgi and
>perl and didnt come up with much more than comp.lang.perl.misc
comp.infosystems.www.authoring.cgi
--
Jon Bell <jtbell@presby.edu> Presbyterian College
Dept. of Physics and Computer Science Clinton, South Carolina USA
[ Questions about newsgroups? Visit http://www.geocities.com/nnqweb/ ]
[ or ask in news:news.newusers.questions ]
------------------------------
Date: Wed, 22 Nov 2000 15:02:30 -0500
From: John Crowley <crowj@aol.com>
Subject: Re: Proper use of $ENV{HTTP_REFERER}
Message-Id: <3A1C2656.1676C146@aol.com>
_Thomas wrote:
>
> >
> > Do not count on "Referer:" at all. (How can you count on anything
> > that isn't even spelled properly? :) It's trivially faked,
> > sometimes wrong, and is even stripped by some security firewalls.
> > Log it, use it as a hint about how people are going through your
> > site, but DO NOT USE IT FOR AUTHENTICATION OR AUTHORIZATION.
>
> Ok, 2 questions .. :)
>
> First: What would the cgi newsgroup be? I did a quick search for cgi and
> perl and didnt come up with much more than comp.lang.perl.misc
>
> (First++): If I can trust http_referer, what should I use? Its nothing
> important I'm just curious as to what to do and who's coming from where to
> my page.
>
> The renaming index.html -> index.cgi thing wouldnt really be a soltion as
> I'd like to track multiple sites thru the cgi call from the <img ...> tag.
>
> ?
>
> _Thomas
Ihe internet is stateless and practically designed for anonymity.
Whatever you try will be difficult and largely inaccurate.
comp.infosystems.www.authoring.cgi
------------------------------
Date: Wed, 22 Nov 2000 17:24:45 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: receive email and process via perl
Message-Id: <G4FsD9.CsD@news.muni.cz>
On Wed, 22 Nov 2000 15:28:51 GMT, x_y_u@my-deja.com <x_y_u@my-deja.com> wrote:
> I have a domain name and can set up email address. I want to have all
> mail sent to process@myhost.com to be processed by a perl script. I
> pretty sure this *can* be done, I'm just not sure *how*
Edit your $HOME/.forward file and add |/full/path/script record.
> Modules I should use would be cool, but some example scripts would be
> great!
Depends on what you'd like to do with those emails. But MIME* and Mail*
modules (to be found on your favorite CPAN mirror) would definitely be
a good start.
Yours,
--
------------------------------------------------------------------------
Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
.project: Perl, DBI, Oracle, MySQL, auth. WWW servers, MTB, Spain.
Petition for a Software Patent Free Europe http://petition.eurolinux.org
------------------------------------------------------------------------
------------------------------
Date: 22 Nov 2000 20:30:31 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: rounding with "printf %f"
Message-Id: <974924264.25862@itz.pp.sci.fi>
In article <3A1B9A94.9EC5DA9C@orga.com>, Felix Drüke wrote:
>
>I expect 6.5 also to be rounded to 7. Why doesn't perl do this?
>Is there another way for rounding, which gives me the result
>that I expect?
sub round ($) { int $_[0] + ($_[0] < 0 ? -.5 : .5) }
Note that it's still possible for the result of a calculation to be
something like 1.499_999_999_999_999, which will round to 1 but will
show up as 1.5 when printed without explicit rounding.
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post
something, we discuss its implications. If the discussion happens to
answer a question you've asked, that's incidental." -- nobull in clpm
------------------------------
Date: Thu, 23 Nov 2000 10:46:00 +1300
From: "Peter Sundstrom" <peter.sundstrom@eds.com>
Subject: Re: Simple Question :)
Message-Id: <8vheqp$3jh$1@hermes.nz.eds.com>
Ron Hartikka <ronh@iainc.com> wrote in message
news:3A1BDD8B.3B9437B0@iainc.com...
> First, you need to read perlfaq's and perlre and perlop.
>
> Here is one of many ways:
>
> $old = "tn_shortname.jpg";
> ($new = $old) =~ s/^...(.*)/$1/;
Which is the same as doing
($new = $old) =~ s/^...//;
------------------------------
Date: Wed, 22 Nov 2000 19:29:45 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Sort runtime 5.005 vs 5.004
Message-Id: <J8VS5.1345$xb1.85927@eagle.america.net>
On Wed, 22 Nov 2000 11:51:52 -0600, Jim Harrison
<jimharrison3@home.com> wrote:
>########################################################
># Read stdin into array
>@array = (<STDIN>);
>
># sort array using normal sort
># and print to stdout
>
>print sort(@array);
>##########################################################
>
>We are sorting a file that is 162.5 MB with 638,278 records.
That code applied to that file is absurd. Solaris has a fine sort
program already: /bin/sort . Why not use it? It would run in a
fraction of the time and memory no matter what version of perl you
were using.
--
Garry Williams
------------------------------
Date: Wed, 22 Nov 2000 16:03:59 -0600
From: "Jim Harrison" <jimharrison3@home.com>
Subject: Re: Sort runtime 5.005 vs 5.004
Message-Id: <8vhfld$c4s$1@tilde.csc.ti.com>
1st of all I was trying to find out why qsortsv was choosen over the old
qsort and was there a way to use the old code or something that would
produce a better answer. Our code is more complicated than I showed, but
this code segment illustrated the problem. In the case sited, the runtime
for the sort was 50 times slower using qsortsv vs the qsort. (3360 sec vs 56
sec).
Now as far as Solaris is concerned. I ran /bin/sort against the same file
and the runtime was 591 seconds vs 50 seconds using the perl 5.004 program,
i.e. 10 TIMES SLOWER. That is why we wrote the sort in the first place, so
we could speed up the run time for sorts on large files.
Jim Harrison
Garry Williams <garry@ifr.zvolve.net> wrote in message
news:J8VS5.1345$xb1.85927@eagle.america.net...
> On Wed, 22 Nov 2000 11:51:52 -0600, Jim Harrison
> <jimharrison3@home.com> wrote:
>
> >########################################################
> ># Read stdin into array
> >@array = (<STDIN>);
> >
> ># sort array using normal sort
> ># and print to stdout
> >
> >print sort(@array);
> >##########################################################
> >
> >We are sorting a file that is 162.5 MB with 638,278 records.
>
> That code applied to that file is absurd. Solaris has a fine sort
> program already: /bin/sort . Why not use it? It would run in a
> fraction of the time and memory no matter what version of perl you
> were using.
>
> --
> Garry Williams
------------------------------
Date: Wed, 22 Nov 2000 23:24:03 +0100
From: Holger <hbhb@gmx.de>
Subject: Re: Sort strings before numbers
Message-Id: <ervn1t813t89qa65het9fbjnohu2qgsma3@4ax.com>
On Mon, 20 Nov 2000 18:58:39 -0500, tadmc@metronet.com (Tad McClellan)
wrote:
>Select ones that contain alphas and sort them, then select those
>that are only digits and sort them:
>
> foreach ( sort(grep /[a-z]/i, keys %config),
> sort {$a <=> $b} grep /^\d+$/, keys %config) {
> print "$_\n";
> }
>
>but grep()ing twice has got to be a waste, so
>
> my(@alphas, @nums);
> foreach (keys %config) {
> if ( /[a-z]/i )
> { push @alphas, $_ }
> else
> { push @nums, $_ }
> }
> foreach ( sort(@alphas), sort {$a <=> $b} @nums ) {
> print "$_\n";
> }
Now I have benchmarked the versions and found out that grep()ing is better.
The condition inside of the loop takes twice the time. Obviously, grep() is
more optimized than a manual loop.
Regards,
Holger
------------------------------
Date: Wed, 22 Nov 2000 14:37:25 -0500
From: Thanh Q Lam <thanh.q.lam@alcatel.com>
Subject: splitting a word
Message-Id: <3A1C2075.9D9553A7@alcatel.com>
Hi,
Can you help to split a word into two parts?
inputs:
abc.def.h
txt.def.hh
output should look like this:
def.h
def.hh
thanks in advance!
-Thanh
------------------------------
Date: Wed, 22 Nov 2000 20:58:51 +0100
From: Oliver =?iso-8859-1?Q?S=F6der?= <soeder@ai-lab.fh-furtwangen.de>
Subject: Re: splitting a word
Message-Id: <3A1C257B.6D4303F7@ai-lab.fh-furtwangen.de>
chomp($in=<STDIN>);
@feld=split(/./,$in,4);
print @feld, "\n";
learn to use the help!!!!!!!!
Thanh Q Lam wrote:
>
> Hi,
>
> Can you help to split a word into two parts?
>
> inputs:
> abc.def.h
> txt.def.hh
>
> output should look like this:
> def.h
> def.hh
>
> thanks in advance!
>
> -Thanh
------------------------------
Date: Wed, 22 Nov 2000 15:41:27 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: splitting a word
Message-Id: <slrn91obrn.nbf.tadmc@magna.metronet.com>
On Wed, 22 Nov 2000 20:58:51 +0100, Oliver Söder
<soeder@ai-lab.fh-furtwangen.de> wrote:
>chomp($in=<STDIN>);
>@feld=split(/./,$in,4);
You don't need the $in temporary variable.
@feld=split(/./,<STDIN>,4);
Where do you insert the space-hyphen-space as given in the requirements?
Why generate 3 leading null fields to discard when you need to discard 4?
>print @feld, "\n";
No need for either of the $in or @feld temporary variables:
print split(/./, <STDIN>, 5), "\n";
But that is a very obfuscated way to discard the first 4 chars,
substr() would be more clear:
print substr(<STDIN>, 4), "\n";
>learn to use the help!!!!!!!!
Learn to test your code before you post your code!!!!!
(it fails miserably)
Learn to follow the specification!!!!!
Learn to use whitespace to make your code easier to read!!!!!
Learn how time normally progresses and maintain quotes in
chronological order!!!!!
>Thanh Q Lam wrote:
>>
>> Can you help to split a word into two parts?
>>
>> inputs:
>> abc.def.h
>> txt.def.hh
>>
>> output should look like this:
>> def.h
>> def.hh
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 22 Nov 2000 20:21:43 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Tom Christiansons' 'style'
Message-Id: <t1oamn9mogincd@corp.supernews.com>
Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>>>>>> "Chris" == Chris Stith <mischief@velma.motion.net> writes:
> Chris> Just because Unix was the birthplace of Perl doesn't mean any Unix
> Chris> question is relevant to a Perl newsgroup. You don't ask questions
> Chris> about Windows in a Photoshop group, do you?
> To complete the analogy, that'd be "..._MacOS_ questions in a
> Photoshop group...", wouldn't it? (Photoshop ran on Macs first, then
> got ported to Windows later when it looked like PHBs were requiring
> those poor artists to finally cope with Windows.)
> How quickly we forget. :)
Yes, being a very poor excuse for a Macintosh user, though I've
used a few, I would be guilty of this. I completely forgot the
origins of Photoshop. I thank Randall for pointing out this error,
since it is a very important distinction between an OS that is
Insanely Great and one that's just insane. ;)
I do remember, however, that Wizard's Crown was originally created
for the Atari 400,600, and 800 series of home computers, and I wish
I could find an 800XL emulator that ran it properly, since my 600XL
no longer functions.
It's all a matter of perspective and remembering what's important to
one's self, I guess.
Sorry, everyone, for the inaccurate analogy. The point I think is still
clear, though. The OS and the application (or language system, if you
resist calling a compiler/interpreter/translator an application), are two
different topics.
Chris
--
Chris Stith - mischief@motion.net
"Whoa." - Neo in _The_Matrix_
------------------------------
Date: Wed, 22 Nov 2000 21:58:38 GMT
From: dtbaker_dejanews@my-deja.com
Subject: trouble with Image::Magick annotate()
Message-Id: <8vhfid$adp$1@nnrp1.deja.com>
I just recently started using Image::Magick to size and add annotations
to some .jpgs via the PerlMagick interface. I have everything working in
my home ActivePerl environment, but not on my remost host domain running
LINUX.
On the LINUX host I have installed the ImageMagic v 5.2.4 from
ImageMagic, not CPAN... and
other functions seem to be working fine. However, when I attempt to use
the annotate() function, I get an error 320 about missing a FreeType
library.
On my PC, I copied a .ttf file into te same dir as my script,and it was
happy. I thought .ttf files are portable, so I copied the same file up
to my LINUX server.... but I still get the error.
One thing I am really not sure of is the allowable syntax for the
annotate() method. The docs indicate one thng, but some other example
showed slightly different syntax. Here is the code I am using:
$ErrMsg = $image->Annotate( text=>$cAnnotateText ,
font=>'@Comic.ttf' ,
pointsize=>$cAnnotatePointsize ,
y=>5 ,
box=>'gray' ,
stroke=>'white' ,
fill=>'black' ,
gravity=>'South'
) ;
On the PC, I have noticed that if I change
font=>'@Comic.ttf' , to font=>'Comic.ttf' ,
it does NOT work, but I dont know if it needs to be different on LINUX?
Any ideas?
Dan
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 22 Nov 2000 11:45:25 -0800
From: Vespasian <ves@ves.net>
Subject: Re: What is the difference in these???
Message-Id: <9iEcOiq6kvCP+TkyiKcHBwNWCyUR@4ax.com>
$a=`print "echo hi"`; is not a valid command
if you are trying to produce the same result with
both statements, change the 2nd one to
$a= print `echo hi`;
scott
On Wed, 22 Nov 2000 18:05:53 GMT, webbgroup@my-deja.com wrote:
>Hey what is the difference in these two statements??
>
>$a=system("echo hi");
>
>-AND-
>
>$a=`print "echo hi"`;
>
>What does the system call do that the other doesn't??
>
>
>Sent via Deja.com http://www.deja.com/
>Before you buy.
------------------------------
Date: Wed, 22 Nov 2000 20:27:04 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: What is the difference in these???
Message-Id: <s_VS5.1347$xb1.85833@eagle.america.net>
[Please don't post upside-down]
On Wed, 22 Nov 2000 11:45:25 -0800, Vespasian <ves@ves.net> wrote:
>On Wed, 22 Nov 2000 18:05:53 GMT, webbgroup@my-deja.com wrote:
>
>>Hey what is the difference in these two statements??
>>
>>$a=system("echo hi");
>>
>>-AND-
>>
>>$a=`print "echo hi"`;
>>
>>What does the system call do that the other doesn't??
>
>$a=`print "echo hi"`; is not a valid command
This is not true. (Well, for one meaning of "not a valid command",
that is. The Perl *statement* is certainly valid.) From print(1):
DESCRIPTION
ksh
The shell output mechanism. With no flags or with flag - or
-, the arguments are printed on standard output as described
by echo(1).
I suspect that bash has the same built-in command.
The statement above will result in the string "echo hi\n" being
assigned to $a.
>if you are trying to produce the same result with
>both statements, change the 2nd one to
>
>$a= print `echo hi`;
This assigns the return value of perl's print() operator to the $a
variable. In most cases that would result $a being equal to 1 since
that is the true value returned by print(). Then there's the question
of what will be printed...
But all this nonsense doesn't answer the original poster's question.
The original poster would do well to read the perlfunc manual page on
system() and the perlop manual page on qx//.
The first statement assigns the return value from system() to the
variable $a (which will most of the time be zero since the externally
executed echo command will usually complete without errors). The
shell command "echo hi" will be executed and it will usually result in
"hi\n" being printed to the stdout.
The second statement (as I mentioned above) assigns the string "echo
hi\n" to the variable $a (since the externally executed print command
will produce that line of output -- most of the time).
--
Garry Williams
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 4953
**************************************