[23056] in Perl-Users-Digest
Perl-Users Digest, Issue: 5277 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 27 03:05:41 2003
Date: Sun, 27 Jul 2003 00:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 27 Jul 2003 Volume: 10 Number: 5277
Today's topics:
Re: "theory vs practice" ceases power <ramen@lackingtalent.com>
Re: "theory vs practice" ceases power <ramen@lackingtalent.com>
Re: Called as method or subroutine? <grazz@pobox.com>
Re: Called as method or subroutine? <mgjv@tradingpost.com.au>
Re: can this one-liner be squeezed any shorter? <pinyaj@rpi.edu>
Re: can this one-liner be squeezed any shorter? <ddunham@redwood.taos.com>
Re: can this one-liner be squeezed any shorter? <pinyaj@rpi.edu>
Re: cpan problems with 02packages.details.txt.gz and 03 <dpchrist@holgerdanske.com>
Re: document ID tracking (slash)
Re: FTP in ASCII mode from UNIX to NT <cat@no-spam.com>
Re: Help needed with basic Perl math commands <ducott@hotmail.com>
Re: Help needed with basic Perl math commands <jurgenex@hotmail.com>
Re: Help needed with basic Perl math commands <dha@panix.com>
Re: How to find out installed packages on Unix <nowhere@nowhere.com>
How to pick out words from a non-delimited string? (Julian Hsiao)
Re: Need help chopping data in Perl <ducott@hotmail.com>
Re: Need help chopping data in Perl <REMOVEsdnCAPS@comcast.net>
Re: Newbie Question <bdonlan@bd-home-comp.no-ip.org>
Re: Tracking Number <mgjv@tradingpost.com.au>
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 27 Jul 2003 05:20:31 -0000
From: Dave Benjamin <ramen@lackingtalent.com>
Subject: Re: "theory vs practice" ceases power
Message-Id: <slrnbi6ofk.tju.ramen@lackingtalent.com>
In article <l18yql64vv.fsf@budvar.future-i.net>, Ed Avis wrote:
> "Dave Benjamin" <dave@3dex.com> writes:
>
>>Perl supports anonymous subrotines, closures, map/filter, currying,
>
> Currying - hardly. You _can_ do it:
>
> sub curry( $ ) {
> my $f = $_[0];
> sub( $ ) { my $x = $_[0]; sub( $ ) { $f->($x, $_[0]) } };
> }
>
> sub uncurry( $ ) {
> my $f = $_[0];
> sub( $$ ) { $f->($_[0])->($_[1]) };
> }
>
> sub plus( $$ ) { $_[0] + $_[1] }
>
> my $plus_curried = curry(\&plus);
> my $plus_five = $plus_curried->(5);
> print $plus_five->(1), "\n";
>
> but no libraries are written in a curried style. You cannot, for
> example, partially apply the 'map' function to get the function that
> adds 1 to every element of a list. Not unless you write the necessary
> machinery yourself.
Well, I'd define curry a little differently, in a way more in line with how
I usually do it in Python (I like being able to make functions self-currying
as well, however, and your example is a nice way of doing that). Here's what
I would use:
sub curry {
my $func = shift;
my @args = @_;
return sub { $func->(@args, @_) };
}
It curries in any number of arguments, and produces a function that handles
the rest. Then, I'd define my own map that takes a function reference
instead of a code block:
sub fmap {
my $func = shift;
my @args = @_;
my @result = ();
for my $arg (@args) {push @result, $func->($arg)}
return @result;
}
Now, the code to do what you describe is pretty simple and elegant:
$add = sub { $_[0] + $_[1] };
@nums = (1, 2, 3);
print "(" . join(', ', fmap(curry($add, 1), @nums)) . ")\n";
Granted, truly functional languages don't require writing either of the
above functions yourself, but it's not like there's a lot of work to do. By
comparison, consider implementing the same technique in Java. (I've tried.)
Your point about libraries not being designed in a curried style is totally
valid, however. Thinking about currying in advance causes you to write
functions that take arguments in a particular, thought-out order, usually
reducing or eliminating the need to right-curry for example. So, it's not a
perfect environment for FP, but it at least lays some essential groundwork.
>>but there's no reason Perl has to be an "imperative language", at
>>least no more than OCaml is, since it provides imperative features as
>>well.
>
> But most 'functional languages', even if they are not pure, usually
> provide help for the functional style. With type checking, or a
> reasonably clean syntax, or things like function composition in the
> standard library. With Perl the syntax is not that clean (though
> manageable once you get used to it) but the lack of any strong type
> checking does make life difficult for complex programs.
Perl's syntax can be a bit unusual and surprising, but I think the example I
gave above is pretty readable. I don't think type checking is that important
to the functional style, however. It may be good for other things, like
proving correctness, that may be of value to you. However, lambda calculus
does not require type checking, and neither does LISP (and let's not get
into whether LISP is functional... ;)
> A rudimentary Scheme-to-Perl translator is at
><http://www.venge.net/graydon/scm2p.html>. It doesn't have
> continuations, but I think it does manage closures (since Perl
> supports them). I think the vapourware Perl 6 will have
> continuations, I don't know if it's possible to get them in Perl 5.
I'll check that out. Thanks for the link and the comments.
Peace,
Dave
------------------------------
Date: Sun, 27 Jul 2003 05:56:03 -0000
From: Dave Benjamin <ramen@lackingtalent.com>
Subject: Re: "theory vs practice" ceases power
Message-Id: <slrnbi6qi8.tju.ramen@lackingtalent.com>
In article <slrnbi6ofk.tju.ramen@lackingtalent.com>, Dave Benjamin wrote:
> $add = sub { $_[0] + $_[1] };
> @nums = (1, 2, 3);
> print "(" . join(', ', fmap(curry($add, 1), @nums)) . ")\n";
It just occurred to me that I didn't do exactly what Ed was describing. He
said that it wasn't possible to "partially apply the 'map' function to get
the function that adds 1 to every element of a list" without writing
"necessary machinery" yourself. I'm not sure if the fmap/curry definitions
I gave are "machinery", but they are plenty abstract for practical purposes
(in theory <grin>). Here's a more proper solution:
$add = sub { $_[0] + $_[1] };
@nums = (1, 2, 3);
$mapadd1 = curry(\&fmap, curry($add, 1));
print "(" . join(', ', $mapadd1->(@nums)) . ")\n";
I imagine what Ed would prefer would be something more like:
$mapadd1 = map (add 1);
$mapadd1->(@nums);
And this is clearly impossible, given that neither "map", my "fmap", nor the
"add" function I defined above are self-currying. So, the currying is
explicit instead of implicit. There are benefits and tradeoffs to that, but
the fact remains that it is possible and not that hard to do.
Dave
------------------------------
Date: Sun, 27 Jul 2003 05:51:01 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: Called as method or subroutine?
Message-Id: <9LJUa.5910$cM6.2491@nwrdny01.gnilink.net>
Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
> Tassilo v. Parseval <tassilo.parseval@rwth-aachen.de> wrote:
> > Hmmh, just a sec. Plain functions are subject to inheritance in Perl
> > (they also trigger AUTOLOAD if it exists):
>
> $ cat /tmp/foo.pl
> use strict;
> use warnings;
>
> package Foo;
> sub foo { print "Foo::foo called\n"; }
If you had defined Foo::AUTOLOAD() then all the examples would
have succeeded -- albeit with this warning:
% perldoc perldiag
Use of inherited AUTOLOAD for non-method %s() is deprecated
(D deprecated) As an (ahem) accidental feature, "AUTOLOAD" subrou-
tines are looked up as methods (using the @ISA hierarchy) even when
the subroutines to be autoloaded were called as plain functions
(e.g. "Foo::bar()"), not as methods (e.g. "Foo->bar()" or
"$obj->bar()").
This bug will be rectified in future by using method lookup only
for methods' "AUTOLOAD"s. However, there is a significant base of
existing code that may be using the old behavior. So, as an
interim step, Perl currently issues an optional warning when non-
methods use inherited "AUTOLOAD"s.
The simple rule is: Inheritance will not work when autoloading
non-methods. The simple fix for old code is: In any module that
used to depend on inheriting "AUTOLOAD" for non-methods from a base
class named "BaseClass", execute "*AUTOLOAD = \&Base-
Class::AUTOLOAD" during startup.
In code that currently says "use AutoLoader; @ISA =
qw(AutoLoader);" you should remove AutoLoader from @ISA and change
"use AutoLoader;" to "use AutoLoader 'AUTOLOAD';".
--
Steve
------------------------------
Date: Sun, 27 Jul 2003 16:04:16 +1000
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Called as method or subroutine?
Message-Id: <slrnbi6qr0.rlm.mgjv@martien.heliotrope.home>
On Sun, 27 Jul 2003 05:51:01 GMT,
Steve Grazzini <grazz@pobox.com> wrote:
> Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
>> Tassilo v. Parseval <tassilo.parseval@rwth-aachen.de> wrote:
>> > Hmmh, just a sec. Plain functions are subject to inheritance in Perl
>> > (they also trigger AUTOLOAD if it exists):
>>
>> $ cat /tmp/foo.pl
>> use strict;
>> use warnings;
>>
>> package Foo;
>> sub foo { print "Foo::foo called\n"; }
>
> If you had defined Foo::AUTOLOAD() then all the examples would
> have succeeded -- albeit with this warning:
I know. And as that warning explains, that's by accident, and should
never be relied on. Even if it was not accidental, that still doesn't
mean that a normal subroutine call is subject to inheritance.
So my point remains: A normal subroutine call is not subject to the
inheritance mechanism in the way a method call is. AUTOLOAD's accidental
features don't alter that point.
Martien
--
|
Martien Verbruggen | If it isn't broken, it doesn't have enough
| features yet.
|
------------------------------
Date: Sat, 26 Jul 2003 23:31:43 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: Dan Jacobson <jidanni@jidanni.org>
Subject: Re: can this one-liner be squeezed any shorter?
Message-Id: <Pine.SGI.3.96.1030726232310.215348A-100000@vcmr-64.server.rpi.edu>
[posted & mailed]
On Sun, 27 Jul 2003, Dan Jacobson wrote:
>Say, can this one-liner be squeezed any shorter, aside from removing
>spaces or hardwiring $q's value?
Well, you ARE hardwiring $q's value. Or do you mean using the expression
instead of $q?
>perl -anlwe 'BEGIN{$q=7.2*3600};printf "%4d %s\n",$q/shift @F,"@F"'
You don't need the -l switch, the ; after BEGIN{}, and whitespace is
ALWAYS expendable. The -w switch might be extra too.
perl -ane 'BEGIN{$q=7.2*3600}printf"%4d %s\n",$q/shift@F,"@F"
--
Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: Sun, 27 Jul 2003 03:46:18 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: can this one-liner be squeezed any shorter?
Message-Id: <eWHUa.133$Hj3.9526405@newssvr14.news.prodigy.com>
Dan Jacobson <jidanni@jidanni.org> wrote:
> Say, can this one-liner be squeezed any shorter, aside from removing
> spaces or hardwiring $q's value?
> perl -anlwe 'BEGIN{$q=7.2*3600};printf "%4d %s\n",$q/shift @F,"@F"'
> Reference: http://jidanni.org/geo/taipower/meter_en.html
Depending on if you really need the formatting of the printf, I might
try these...
perl -pwe 's#(\d+)#7.2*3600/$1#e'
perl -pwe 's#(\d+)#sprintf("%4d",7.2*3600/$1)#e'
--
Darren Dunham ddunham@taos.com
Unix System Administrator Taos - The SysAdmin Company
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >
------------------------------
Date: Sun, 27 Jul 2003 00:16:03 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: can this one-liner be squeezed any shorter?
Message-Id: <Pine.SGI.3.96.1030727001501.228940A-100000@vcmr-64.server.rpi.edu>
On Sun, 27 Jul 2003, Darren Dunham wrote:
>Dan Jacobson <jidanni@jidanni.org> wrote:
>> Say, can this one-liner be squeezed any shorter, aside from removing
>> spaces or hardwiring $q's value?
>> perl -anlwe 'BEGIN{$q=7.2*3600};printf "%4d %s\n",$q/shift @F,"@F"'
>> Reference: http://jidanni.org/geo/taipower/meter_en.html
>
>Depending on if you really need the formatting of the printf, I might
>try these...
>
> perl -pwe 's#(\d+)#7.2*3600/$1#e'
One-liners are $&-friendly:
perl -pe 's%\d+%7.2*3600/$&%e'
> perl -pwe 's#(\d+)#sprintf("%4d",7.2*3600/$1)#e'
perl -pe 's%\d+%sprintf"%4d",7.2*3600/$&%e'
--
Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: Sun, 27 Jul 2003 04:33:13 GMT
From: "David Christensen" <dpchrist@holgerdanske.com>
Subject: Re: cpan problems with 02packages.details.txt.gz and 03modlist.data.gz
Message-Id: <dCIUa.5661$dk4.260731@typhoon.sonic.net>
"Randy Kobes" wrote:
> Perhaps Cygwin perl gets confused with the '~', sometimes thinking it
> a real directory (eg, presence of a C:\~) and other times expanding it
> to a home directory (/home/dpchrist/). It might be worth trying to
> again remove C:\~, and then start the CPAN.pm shell but first
> reconfigure it:
> cpan> o conf init
> and try choosing the build and source directories with a root
> directory of something like C:/.cpan/.
Thanks for the reply! :-)
Here's what I did:
1. Blow away C:\~
2. Run cpan:
cpan> o conf init
...
CPAN build and cache directory? [/home/dpchrist/.cpan] /cygdrive
/c/.cpan/
...
File to save your history? [/home/dpchrist/.cpan/histfile] /cygd
rive/c/.cpan/histfile
It worked! :-)
Thank you,
David
------------------------------
Date: 26 Jul 2003 19:59:43 -0700
From: satishi@gwu.edu (slash)
Subject: Re: document ID tracking
Message-Id: <30fe9f1e.0307261859.6a69e899@posting.google.com>
Thanks for the help again and sorry for the confusion. I really
appreciate the time people are taking out of their busy schedules to
help me out here. I just don't get references well enough to be able
to figure out how I can get what I want.
What I was trying to do (so ineffectively) was to have a 5gram first
for all the words and then the filenames next to them so that I can
select specific columns for display.
I will try to explain this with more detail:
My input is essentially bunch of text files that I am currently
passing in to the script as: perl -n script.pl ./*.TXT
fox.txt
quick brown fox jumped over lazy dog tripped over resting fox
My badly written program was trying to achieve three things:
produce complete 5grams, then
select specific columns from that 5grams,
third part has to do with document tracking that I just can't seem to
get it in.
First part: 5grams
=================
. . . . quick
. . . quick brown
. . quick brown fox
. quick brown fox jumped
quick brown fox jumped over
brown fox jumped over lazy
fox jumped over lazy dog
jumped over lazy dog tripped
over lazy dog tripped over
lazy dog tripped over resting
dog tripped over resting fox
tripped over resting fox
over resting fox
2nd part: select columns
=====================
quick brown fox
brown quick
brown fox jumped
fox brown quick
fox jumped over
fox resting over
jumped fox brown
jumped over lazy
over jumped fox
over lazy dog
lazy over jumped
lazy dog tripped
dog lazy over
dog tripped over
tripped dog lazy
tripped over resting
over tripped dog
over resting fox
resting tripped over
resting fox
Third part: filenames
===================
quick brown fox fox.txt
brown quick fox.txt
brown fox jumped fox.txt
fox brown quick fox.txt
fox jumped over fox.txt
fox resting over fox.txt
jumped fox brown fox.txt
jumped over lazy fox.txt
over jumped fox fox.txt
over lazy dog fox.txt
lazy over jumped fox.txt
lazy dog tripped fox.txt
dog lazy over fox.txt
dog tripped over fox.txt
tripped dog lazy fox.txt
tripped over resting fox.txt
over tripped dog fox.txt
over resting fox fox.txt
resting tripped over fox.txt
resting fox fox.txt
Any help you could give me to move this forward would be greatly
appreciated.
many thanks,
slash
"A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu> wrote in message news:<Xns93C4A044A8D34asu1cornelledu@132.236.56.8>...
> satishi@gwu.edu (slash) wrote in
> news:30fe9f1e.0307260943.1f4352b1@posting.google.com:
>
> > Thanks so much for all the helpful responses. (Sinan, this is not a HW
> > problem! :) I didn't get any helpful responses in another related
> > postiing so I am adding this as a followup here hoping that it will
> > get reviewed.
>
> You'll need to post something that can be run locally (make sure some
> sample input data are included).
>
> ...
>
> > undef $/;
>
> Are you sure you want to this here?
>
> > my @words = split /\W+/, <> ;
> > my $line_number = 2;
> > my $n;
> > my $line_num = 2;
>
> What is the difference between $line_number and $line_num and what purpose
> do they serve?
>
> > my $n_cols = 5;
> > my $col = { align => 'left'}; # no title, left alignment
> > my $tb = Text::Table->new( ( $col) x $n_cols);
> > my @stack = ( '*' ) x $n_cols;
> > foreach $word ( @words ) {
> > shift @stack;
> > push @stack, $word;
> > $tb->add(@stack);
> > }
>
> What on earth is going on in here?
>
> > my @lines = $tb->add("$stack[-4]", "$stack[-3]", "$stack[-2]",
> > "$stack[-1]", "*");
> > my @lines = $tb->add("$stack[-3]", "$stack[-2]", "$stack[-1]","*",
> > "*");
> > my @lines = $tb->table($line_number, $n);
>
> Why do you keep redeclaring and redefining @lines before you do anything
> with it?
>
> > #print @lines;
> > my $t1 = $tb->select(2, {is_sep => 2, body => " "}, 1,0,
> > {is_sep => 2, body => "\n"},
> > 2, {is_sep =>2, body => " "}, 3,4);
> > #foreach $textID (@textID) {
> > #$t1 = $t1->add($ARGV); }#adds one data line at the end of ngrams not
> > a col
>
> I do not understand this comment. Is it supposed to do something else? Did
> you read the docs for Text::Table?
>
> add()
> adds a data line to the table, returns the table.
>
> > my $input = $t1->table($line_num, $n);
> > print $input;
> ...
> > To recap, I don't know if I really need an inverted index. Perhaps an
> > array of arrays might help instead of the table module. Where I can
> > have @lines and $ARGV. Would that work? In other words, an array
> > consisting of the following:(first line of ngram, $ARGV)
> > (Second line of ngram, $ARGV)
> > .
> > .
> > .
> > (Last line of ngram, $ARGV)
> > And perhaps I could put this into a table and do the select statemetns
> > over them to display the desired output. Is this possible or I am just
> > dreaming?
>
> No, you are just rambling. The way this works is, you post a specific
> problem, and people try to help you solve it. We cannot figure out for you
> your requirements etc because we do not have the information you have
> regarding the overall picture.
>
> So, I do not know why you decided the previous solutions we posted to the
> problem of associating each word with the file(s) it came from were
> inadequate. Before people can help you, you have to clearly communicate
> what problem you are trying to solve.
>
> > Any suggestions on how to achieve this would be very much appreciated.
>
> I do not know what you mean by "this". But, would the following help?
>
> # fubar.pl
>
> use strict;
> use warnings;
>
> use Text::Table;
>
> my $cols = 5;
> my $col = { 'align' => 'left' };
> my $table = Text::Table->new(($col) x $cols);
>
> {
> local $/;
> while(my @words = split /\W+/, <ARGV>) {
> while (@words) {
> my @row = splice (@words, 0, $cols - 1);
> if(@row < $cols - 1) {
> push @row, (undef)x($cols - @row - 1);
> }
> push @row, ($ARGV);
> $table->add(@row);
> }
> }
> }
>
> print ($table->body());
> __END__
>
> C:\Home> cat file1
> file1a file1b
> file1c
> file1d
> file1e file1f
> file1g
>
> C:\Home>cat file2
> file2a
> file2b
> file2c
> file2d
> file2e
> file2f
>
> C:\Home>fubar.pl file1 file2
> file1a file1b file1c file1d file1
> file1e file1f file1g file1
> file2a file2b file2c file2d file2
> file2e file2f file2
------------------------------
Date: Sun, 27 Jul 2003 14:58:21 +1000
From: Cat <cat@no-spam.com>
Subject: Re: FTP in ASCII mode from UNIX to NT
Message-Id: <3F235BED.6943632C@no-spam.com>
jiju wrote:
>
> I can't open up a text file that I FTP'd from UNIX to Windows 2000
> even though I set the type to ASCII mode ($ftp->ascii();). I guess it
> has to do with carriage return character not encoding correctly on
> 2000 machine. Is there any work around to fix this problem so I could
> open this file up in Notepad?? Need to have it in Notepad to use with
> MS Access
Just a note. W2K has a bug. Have you installed Service Pack 3?
------------------------------
Date: Sun, 27 Jul 2003 02:06:53 GMT
From: "\"Dandy\" Randy" <ducott@hotmail.com>
Subject: Re: Help needed with basic Perl math commands
Message-Id: <1tGUa.556297$Vi5.13989964@news1.calgary.shaw.ca>
Jue, first off thanx for the reply. I, of course, know how to do the math on
paper, but am unfamiliar with the perl syntax to complete such a function.
How do I tell Perl that the information gathered from the text file are
integers and not strings ... by this I mean ... what if the text file had
words and not numbers ... then I tried calculating a percentage from words
... see where I'm going? Maybe I'm thinking too hard and perl will just
figure out that the data are numbers and not words ... if you have any input
on this matter, you are most welcomed to reply. TIA
R
> > Now I need help writting a set of commands that will calculate the
> > percentages of this data. I would like to have it in this format:
> >
> > print "Total was $total";
> > print "Bought was $boughtpercentage"; # % of $bought vs $total
> > print "Sold was $soldpercentage"; # % of $sold vs $total
> >
> > Can someone please help me with the commands to calculate
> > $boughtpercentage & $soldpercentage. Thanx to all who read or
> > respond.
>
> Oh come on. That is second or at most third grade math!
> How would you do that with paper and pencil? Write it down. Explicitly!
> And then just type that formula into your computer.
>
> For the actual syntax check 'perldoc perlop' for the Perl operators.
> Hint: multiplication is "*" and division is "/".
>
> jue
>
>
------------------------------
Date: Sun, 27 Jul 2003 05:08:12 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Help needed with basic Perl math commands
Message-Id: <07JUa.6644$FP5.2731@nwrddc02.gnilink.net>
[Please do not top post; re-arranged into chronological sequence]
"Dandy" Randy wrote:
>>> Now I need help writting a set of commands that will calculate the
>>> percentages of this data. I would like to have it in this format:
>>>
>>> print "Total was $total";
>>> print "Bought was $boughtpercentage"; # % of $bought vs $total
>>> print "Sold was $soldpercentage"; # % of $sold vs $total
>>>
>>> Can someone please help me with the commands to calculate
>>> $boughtpercentage & $soldpercentage. Thanx to all who read or
>>> respond.
>>
>> Oh come on. That is second or at most third grade math!
>> How would you do that with paper and pencil? Write it down.
>> Explicitly! And then just type that formula into your computer.
>>
>> For the actual syntax check 'perldoc perlop' for the Perl operators.
>> Hint: multiplication is "*" and division is "/".
> Jue, first off thanx for the reply. I, of course, know how to do the
> math on paper, but am unfamiliar with the perl syntax to complete
> such a function. How do I tell Perl that the information gathered
> from the text file are integers and not strings ... by this I mean
> ... what if the text file had words and not numbers ... then I tried
> calculating a percentage from words ... see where I'm going?
Ahhh, now we are getting somewhere. This remark of yours is sort of an eye
opener.
> Maybe
> I'm thinking too hard and perl will just figure out that the data are
> numbers and not words ...
Yes, you do and yes Perl does.
Or actually it is the other way round: Perl does not distinguish between
numbers and text. There are only scalars (plus compound data types, but
let's ignore those for the time being) and any scalar has (at least) a
numerical value, a textual value, and a boolean value.
So the number 25 is not only a number, but when used in a textual context
(e.g. in print() or string concatenation or string comparison) it also has
the string value of '25'.
And the string 'foobar' when used in numerical context like in a
multiplication also has a numerical value which happens to be 0. The rule is
that the numerical value is the value of any leading number, e.g.
'234foobar' has the numerical value of 234.
And all four, 25, 'foobar', '25', or '234foobar' have a boolean value of
true.
So, just multiply your text numbers, Perl will do the right thing
automatically.
jue
------------------------------
Date: Sun, 27 Jul 2003 05:11:27 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: Help needed with basic Perl math commands
Message-Id: <slrnbi6nnv.aj6.dha@panix2.panix.com>
In article <1tGUa.556297$Vi5.13989964@news1.calgary.shaw.ca>, "Dandy"
Randy wrote:
> Jue, first off thanx for the reply. I, of course, know how to do the math on
> paper, but am unfamiliar with the perl syntax to complete such a function.
> How do I tell Perl that the information gathered from the text file are
> integers and not strings ... by this I mean ... what if the text file had
> words and not numbers ... then I tried calculating a percentage from words
> ... see where I'm going? Maybe I'm thinking too hard and perl will just
> figure out that the data are numbers and not words ...
Unless you mean words such as "one", "two", "three" etc., yes, perl will
figure it out.
If a variable contains the string "1" it will convert it to a number
if necessary if it's used in a mathematical context. And similarly the
other way for a string context.
I'm sure someone will pick at this, as I'm probably simplifying
horribly, but it should be enough to deal with this particular problem.
:-)
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
I believe myself to be the daughter of a one-eyed space robot named
Malcolm. -Fallon Young, http://www.bobbins.org/d/20000915.html
------------------------------
Date: Sat, 26 Jul 2003 21:36:06 -0400
From: Jeremy <nowhere@nowhere.com>
Subject: Re: How to find out installed packages on Unix
Message-Id: <MPG.198cf69086ec270c98969e@news.starpower.net>
"Wang, Vincent" <viwang@nortelnetworks.com> wrote in message
> Do you know how to find out the Perl packages that already installed on
> my UNIX or Linux, like "ppm query" does on win32?
You could list the contents of the directories in @INC. It won't
tell you the version numbers, but at least you'll see the files.
Drop something like this in your cgi-bin directory, and then
access it from your browser:
#!/usr/bin/perl -w
use strict;
use CGI;
my $q = new CGI;
print $q->header(-type => 'text/html');
print $q->start_html(-title => 'Contents of @INC');
print $q->h2('Contents of @INC');
foreach (@INC) {
print $q->h4($_);
print $q->pre(`ls -FR $_`);
}
print $q->end_html();
-- Jeremy Kuris
------------------------------
Date: 26 Jul 2003 23:21:52 -0700
From: madoka@novastar.com (Julian Hsiao)
Subject: How to pick out words from a non-delimited string?
Message-Id: <159063bc.0307262221.4b8c47a2@posting.google.com>
Hi,
Since Perl excels at string parsing, I thought this would be the right
group to ask my question. If not, I apologize for the confusion.
I want to know if there's an algorithm that picks out the words from a
string that doesn't delimit each words. For example, given
"helloworld" outputs "hello world". Ideally, it should also be
resistant to spelling errors.
So, does such algorithm exist? Better yet, has someone already
implemented it?
Thanks.
Julian Hsiao
madoka@novastar.com
------------------------------
Date: Sun, 27 Jul 2003 02:07:39 GMT
From: "\"Dandy\" Randy" <ducott@hotmail.com>
Subject: Re: Need help chopping data in Perl
Message-Id: <LtGUa.526588$3C2.13810303@news3.calgary.shaw.ca>
Thank you Gunnar, I will give this a try.
R
"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:bfv4ve$j494g$1@ID-184292.news.uni-berlin.de...
> "Dandy" Randy wrote:
> > I'm needing a set of commands that will take the variable $name ...
> > and remove any data that appears after the first space it
> > encounters - including the space itself.
>
> $name =~ s/^(\S+).*/$1/;
>
> --
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl
>
------------------------------
Date: Sat, 26 Jul 2003 23:12:03 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Need help chopping data in Perl
Message-Id: <Xns93C521282BC5sdn.comcast@206.127.4.25>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
"\"Dandy\" Randy" <ducott@hotmail.com> wrote in
news:9sEUa.527551$ro6.12239594@news2.calgary.shaw.ca:
> I'm needing a set of commands that will take the variable $name ...
> and remove any data that appears after the first space it encounters -
> including the space itself. The result would be if I printed $name,
> only John or Jane would be shown, the last name was removed. Hope I
> have explained this ok. Thanx to all who read or respond. Code
> examples are greatly appriciated.
$name =~ s/ .*//;
- --
Eric
$_ = reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBPyNRG2PeouIeTNHoEQKtBwCfQStyLwDWOWA7n6CKj4TNfXIY+4UAn317
HJC9MkXjVLshFWFT7iMn1Nba
=wGtE
-----END PGP SIGNATURE-----
------------------------------
Date: Sat, 26 Jul 2003 21:58:20 -0400
From: bd <bdonlan@bd-home-comp.no-ip.org>
Subject: Re: Newbie Question
Message-Id: <pan.2003.07.27.01.58.20.201260@bd-home-comp.no-ip.org>
On Sat, 26 Jul 2003 22:24:20 +0200, wrote:
> Hey. Im new to programming and need some basic Perl help.
>
> my($var1,$var2) = @_;
> I understand that the "my" defines the two variables as private to the
> enclosing block of code. I dont understand the "@_". My book says its
> a special local array. Its been used in the following:
>
> ## Beginning of login.pl
[snip]
> ## EOF
>
> Could someone please explain this speical local array to me in more
> detail.
> Thank you in advance for your help.
The arguments passed to a function are stored in @_. Ex:
&foo(1,2,"foo");
sub foo {
# @_ is (1,2,"foo")
}
--
Freenet distribution not available
Men freely believe that what they wish to desire.
-- Julius Caesar
------------------------------
Date: Sun, 27 Jul 2003 10:56:23 +1000
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Tracking Number
Message-Id: <slrnbi68pn.rlm.mgjv@martien.heliotrope.home>
On 25 Jul 2003 16:50:07 -0700,
Jeff Mott <mjeff1@twcny.rr.com> wrote:
>> It has really nothing to do with Perl at all,
>
> I know. I had already said that, and I apologize. If you know of an
> appropriate group, please let me know. I couldn't find one.
I don't know of a better newsgroup, but the ultimate source of this sort
of information would be the people who provide the service, Fedex, and
UPS. Not everything has a newsgroup.
>> but it turns out someone
>> has already done a lot of this work. Go to search.cpan.org, and look
>> for modules with Fedex and UPS in the name.
>
> I already had. I found none that had a method for testing the validity
> of each's respective tracking number. If you see one I did not, please
> let me know.
I figured that something called Business::UPS would have some validation
rules in it. If not, the only alternative I see is to see whether
something is available on the Fedex and UPS web sites, and if not,
contact someone there.
Martien
--
|
Martien Verbruggen | In the fight between you and the world, back
| the world - Franz Kafka
|
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 5277
***************************************