[16900] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4312 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 13 14:05:39 2000

Date: Wed, 13 Sep 2000 11:05:16 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <968868316-v9-i4312@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 13 Sep 2000     Volume: 9 Number: 4312

Today's topics:
        (OpenVMS) EOF with autoflushed file <coucoureux.p@fr.ibm.com>
        Aliasing problem <thutchings@hoteldiscounts.com>
    Re: Another novice question - host equivalent? <bd83h@bedford.waii.com>
    Re: avoiding do {} while() <gopalan@cs.sc.edu>
        Character Class in Regex - Despecify What? (Sean McAfee)
    Re: convert date -> unixtime <stephenk@cc.gatech.edu>
        Debugging not working <g.soper@soundhouse.co.uk>
    Re: Eliminate Duplicates <mischief@motion.net>
    Re: email form script <russ_jones@rac.ray.com>
        File name with space in Net::FTP put scarlzong@my-deja.com
    Re: Finding maximum length (Sean McAfee)
    Re: Finding maximum length <ren.maddox@tivoli.com>
    Re: Finding maximum length <ren.maddox@tivoli.com>
    Re: Finding maximum length <aqumsieh@hyperchip.com>
    Re: Finding maximum length (Craig Berry)
    Re: Finding subdirectories on Windows Systems <FX@hasnomail.com>
        Function to convert whole + fractions to decimal number <davesisk@ipass.net>
    Re: Function to convert whole + fractions to decimal nu <randy@theoryx5.uwinnipeg.ca>
    Re: Function to convert whole + fractions to decimal nu (Abigail)
    Re: Function to convert whole + fractions to decimal nu <yanick@babyl.sympatico.ca>
    Re: Getting started w/ Perl (Chris Fedde)
        grep in perl <flyboy@optushome.com.au>
    Re: grep in perl (Abigail)
    Re: Hash of Hash of Hash <ren.maddox@tivoli.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 13 Sep 2000 19:07:45 +0200
From: BibiLoloDeSaintMalo <coucoureux.p@fr.ibm.com>
Subject: (OpenVMS) EOF with autoflushed file
Message-Id: <39BFB461.EE7B9963@fr.ibm.com>

Hello,

When I do a 'print' in a file in autoflush mode I receive an error : end
of file detected.
Why?
And how can do to write in my file

My code is the following:
  open LOG, ">flush.log";
  $oldfh = select(LOG);$| = 1;select($oldfh);
  print LOG "Hello world" or print "Error $!\n";
  close LOG;

This problem is, maybe, specific to OpenVMS.

Thanks,

Pierre



------------------------------

Date: Wed, 13 Sep 2000 11:14:20 -0500
From: "Thomas Hutchings" <thutchings@hoteldiscounts.com>
Subject: Aliasing problem
Message-Id: <8po94g$8lp@library2.airnews.net>

I'm having a bit of trouble understanding why the following code works the
way it does.  I've got two modules, Lang.pm and B.pm (I apologize for the
length, but want to be thorough):

# Lang.pm
package Lang;

sub import
{
    my $self  = shift;
    my $class = ref($self) || $self;
    my ($type, $sym);
    my $pkg   = 'Lang';

    undef %{Lang::};
    foreach $sym (@$self)
    {
          (*{"${pkg}::$sym"} = \&{"${class}::$sym"}, next)
            unless $sym =~ s/^(\W)//;
        $type = $1;
        *{"${pkg}::$sym"} =
            $type eq '&' ? \&{"${class}::$sym"} :
            $type eq '$' ? \${"${class}::$sym"} :
            $type eq '@' ? \@{"${class}::$sym"} :
            $type eq '%' ? \%{"${class}::$sym"} :
            $type eq '*' ?  *{"${class}::$sym"} :
            do { warn "Could not associate $class :: $sym to Lang" };
    }
}

1;

# B.pm
package B;

use Lang();
use vars qw(@ISA $Test);

@ISA = qw(Lang);
$Test = 'Hello World';

sub new
{
    my $proto = shift;
    my $class = ref($proto) || $proto;
    my $self  = [qw($Test)];

    return bless $self;
}

1;

My client code is this:

#Client
use B();

my $obj = B->new();
$obj->import();  # import vars into Lang namespace

print "$B::Test is the string directly.\n";
print "$Lang::Test is the string from Lang, aka " . ${"Lang::Test"} . "\n";

Which on execution prints out:

Hello World is the string directly.
 is the string from Lang, aka Hello World

Why does the symbolic reference ${"Lang::Test"} print correctly, while the
direct reference $Lang::Test does not?  My perl is 5.00503 on AIX.

Thanks very much for your help.
--
_________
 |homas




------------------------------

Date: Wed, 13 Sep 2000 16:13:47 +0100
From: Steve Drewell <bd83h@bedford.waii.com>
To: Jeff Pinyan <japhy@pobox.com>
Subject: Re: Another novice question - host equivalent?
Message-Id: <1000913161231.58376H-100000@bisv3.bedford.waii.com>

Thanks Jeff.

Steve

Western Geophysical, Bedford, UK
Tel: +44 (0) 1234 224404
Fax: +44 (0) 1234 224517

On Wed, 13 Sep 2000, Jeff Pinyan wrote:

=AF [posted & mailed]
=AF=20
=AF On Sep 13, Steve Drewell said:
=AF=20
=AF >variable=3D`host 111.222.333.444` ?
=AF >Is there a way of doing it without using "system"?
=AF=20
=AF   use Socket;
=AF   $addr =3D gethostbyaddr(inet_aton($IP), AF_INET);
=AF=20
=AF --=20
=AF Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy=
/
=AF PerlMonth - An Online Perl Magazine            http://www.perlmonth.com=
/
=AF The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com=
/
=AF CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org=
/



------------------------------

Date: Wed, 13 Sep 2000 11:26:22 -0400
From: Gopi Sundaram <gopalan@cs.sc.edu>
Subject: Re: avoiding do {} while()
Message-Id: <Pine.OSF.4.21.0009131116550.9558-100000@pearl.cs.sc.edu>

On Mon, 11 Sep 2000, Larry Rosler wrote:

>   my @try = my @sigs = </path/to/files/*>;
>   my $found;
>   1 while @try && ! -T ($found = splice @try, rand @try, 1);
>   @try or die "All files tried!\n";
>   ^^^^^^^^^^^
> The name of the desired file is in $found.

Unfortunately, the last test you do is not correct. If $found was the
last element of the array, @try would be empty, and the test would
fail, whereas $found does indeed contain a correct value.

I changed it to

die "No valid files found!\n" unless defined $found && -T $found;

I added the defined so that even if the /path/to/files is empty, I
won't get a warning about uninitialized values. I could of course
remove it, and run without the -w flag.

Gopi.

-- 
Gopi Sundaram
gopi@cs.sc.edu



------------------------------

Date: Wed, 13 Sep 2000 16:09:16 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Character Class in Regex - Despecify What?
Message-Id: <MENv5.3185$O5.64445@news.itd.umich.edu>

In article <8po41a$34k$1@wanadoo.fr>,
Elisa Roselli <e.roselli@volusoft.com> wrote:
>I've set myself the exercise of creating a simple Perl program that would
>extract the lines of any given character in a play, together with the
>leading cue. In the input file, the characters' names appear in all caps,
>followed by a tab, followed by their lines; two new lines separate the
>chunks.

>LYSANDER  Why should he stay, whom love doth press to go?

>HERMIA  What love could press Lysander from my side?

>Within any character's speech, there can be any kind of alpabetic character,
>plus spaces, single new lines and tabs. My problem is that I am trying to
>express that with a character class, and I kept getting syntax errors.

Perhaps I'm not understanding correctly, but if the delimiter is multiple
newline characters, no character class can find that on its own.

It doesn't seem to me that a character class is the answer here.  If you
set $/ (Perl's input record separator) to the value "", Perl will read
input in blocks delimited by multiple newlines ("paragraph mode").

Try this:

----------------------------------------------------------------------
$/ = "";
my $character = shift @ARGV;

while (<>) {
    my ($speaker) = /^([A-Z]*)/;
    print if $speaker eq $character;
}
----------------------------------------------------------------------

If you save this as, say, filter.pl, and run it as

perl filter.pl LYSANDER inputfile

 ...it should print out all of Lysander's lines from the file.

If you already have the entire play in a single big variable, you can parse
through it like this:

while ($play =~ /(([A-Z]+).*?\n{2,})/gs) {
    print $1 if $2 eq $character;
}

-- 
Sean McAfee                                                mcafee@umich.edu
print eval eval eval eval eval eval eval eval eval eval eval eval eval eval
q!q@q#q$q%q^q&q*q-q=q+q|q~q:q? Just Another Perl Hacker ?:~|+=-*&^%$#@!


------------------------------

Date: Wed, 13 Sep 2000 11:41:38 -0400
From: Stephen Kloder <stephenk@cc.gatech.edu>
Subject: Re: convert date -> unixtime
Message-Id: <39BFA031.49E70EC7@cc.gatech.edu>

gumbygumbygumby@my-deja.com wrote:

> Hi, how do i do this conversion, is there some function i can use or do
> i have to code it myself?
>
>

perldoc Time::Local

--
Stephen Kloder               |   "I say what it occurs to me to say.
stephenk@cc.gatech.edu       |      More I cannot say."
Phone 404-874-6584           |   -- The Man in the Shack
ICQ #65153895                |            be :- think.




------------------------------

Date: Wed, 13 Sep 2000 17:47:59 +0100
From: Geoff Soper <g.soper@soundhouse.co.uk>
Subject: Debugging not working
Message-Id: <49fd7a10e3g.soper@soundhouse.co.uk>

After having problems using a script I'm attempting to debug it by setting
the content-type to text/plain:

if (param("action") eq "check") {

    print "content-type: text/plain\n\n";

    $form_data{$_} = [param($_)] for param();
    %original_users = import_form("original",%form_data);
print $original_users{"john.doe"}{"telephone"};

This doesn't seem to be working as it has before.

The script is located at http://www.soundhouse.co.uk/cgi-bin/2.cgi and
also as text at http://www.soundhouse.co.uk/geoff/

If you load it once it will display a form and if you submit this form the
perameter reqired by the if loop will be set.

I'd be grateful for help as this means I can't progress with working out
what is going wrong!

Thanks as ever

-- 
Geoff Soper
g.soper@soundhouse.co.uk
Take a look at the Soundhouse page http://www.soundhouse.co.uk/


------------------------------

Date: Wed, 13 Sep 2000 12:12:31 -0500
From: "Chris Stith" <mischief@motion.net>
Subject: Re: Eliminate Duplicates
Message-Id: <srvd91udct627@corp.supernews.com>


"Iain Chalmers" <bigiain@mightymedia.com.au> wrote in message
news:bigiain-1209001859540001@dhcp-135.goop.org...
> In article <39be4716@cs.colorado.edu>, tchrist@perl.com (Tom Christiansen)
> wrote:
>
> > Here's a tip for you.  Whenever you hear, especially if used in
> > conjunction with the notion of an array or list, any of the words
> > "in", "unique", "record", "node", "structure", "first", or "duplicate",
> > you should in a flurry of Pavlovian salivation, free-associate
> > immediately to
>

[removed noisyness]

|                                                |
> >             |     A hash! I should be using a hash for this! |

[removed noisyness]

>
> "in", "unique", "duplicate" - yes, but "first"??? _really_???

If you always use:

### code
if(defined) {
    #leave it alone
} else {
    #set the value associated with the key
}
### endcode

then the value you get back out of the hash will indeed be the first value.
If not, it will be the last value assigned. These hold true, of course, only
if you haven't created a workaround for colliding key names.

> cheers,
>
> big

Bottoms up.

> (failing to salivate over being asked to produce the "first" entry in a
hash :-)

Well, if you mean "first" as in according to a sorted order, then I see your
point. I think Tom was referring to the first occurrence of the same value,
or the same named reference to a value in the case that you do use a hash.

Chris
---
Christopher E. Stith
mischief@(pikenet.net|motion.net)




------------------------------

Date: Wed, 13 Sep 2000 10:14:07 -0500
From: Russ Jones <russ_jones@rac.ray.com>
Subject: Re: email form script
Message-Id: <39BF99BF.C8F0FF6C@rac.ray.com>

Lincoln Marr wrote:
> 
> > I have a need for a cgi/perl script that will take a forms data, then
> > generate an email.
> 
> Check out matts script archive (you can use a search engine can't you?),
> it's got a script called formmail which will do what you want....
> stylistically speaking it's not too good as it's written for Perl 4, but it
> still works and is simple to set up.


And it has more errors in it than an early Mets game. More errors in
it than a Godzilla post.





-- 
Russ Jones - HP OpenView IT/Operatons support
Raytheon Aircraft Company, Wichita KS
russ_jones@rac.ray.com 316-676-0747

Quae narravi, nullo modo negabo. - Catullus


------------------------------

Date: Wed, 13 Sep 2000 17:26:41 GMT
From: scarlzong@my-deja.com
Subject: File name with space in Net::FTP put
Message-Id: <8podbk$33j$1@nnrp1.deja.com>

Hi,

a quick question concerning Nert::FTP.

I have a script using ftp to transfer files but put("$file") does not
work if the file name contains space. The remote computer is a RH6.2 so
it does  support for example touch "qa dd", but $ftp->put("qa dd") does
not work. Any ideas anyone ?


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Wed, 13 Sep 2000 15:38:51 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: Finding maximum length
Message-Id: <fcNv5.3179$O5.64447@news.itd.umich.edu>

In article <8pn8vq$490$1@provolone.cs.utexas.edu>,
Logan Shaw <logan@cs.utexas.edu> wrote:
>In article <5TEv5.3168$O5.63702@news.itd.umich.edu>,
>Sean McAfee <mcafee@waits.facilities.med.umich.edu> wrote:
>>In article <8pmkss$1it$1@nnrp1.deja.com>,  <greg_sands@my-deja.com> wrote:
>>>I'm trying to find the maximum length of the elements of an array.

>>Here's an idiom I like:
>>sub maximum (&@) {
>>    my $sub = shift;
>>    my ($max, $value);
>>    foreach (@_) {
>>        $value = $sub->();

>Don't you want to give some sort of argument to &$sub, i.e. shouldn't
>you do something like
>	$value = $sub->($_);
>instead?  Or does that actually work and it's just really obfuscated?

Yes, it works, and no, it's not obfuscated.  The "foreach (@_)" aliases $_
to each element of @_ successively, and the subroutine referred to be $sub
is presumed to get its argument in $_ instead of via the usual argument
array @_.  This is convenient because so many Perl functions use $_ as
their default argument:

my $greatest_int    = maximum { int }    @int_list;
my $greatest_char   = maximum { ord }    @char_list;
my $latest_filetime = maximum { -M }     @file_list;
my $most_x          = maximum { tr/x// } @string_list;

>>        !defined $max || $max < $value and $max = $value;

>Wouldn't it be simpler to just do this?
>	$max = $value if $max < $value;

>When $max is undef, it should evaluate as less than $value.

Unless $value can be negative.  It can't be when we're looking at string
lengths, but in general it could be.  $sub could return anything.

-- 
Sean McAfee                                                mcafee@umich.edu
print eval eval eval eval eval eval eval eval eval eval eval eval eval eval
q!q@q#q$q%q^q&q*q-q=q+q|q~q:q? Just Another Perl Hacker ?:~|+=-*&^%$#@!


------------------------------

Date: 13 Sep 2000 00:14:42 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Finding maximum length
Message-Id: <m366o0euv1.fsf@dhcp11-177.support.tivoli.com>

Bob Walton <bwalton@rochester.rr.com> writes:

> greg_sands@my-deja.com wrote:
> > 
> > I'm trying to find the maximum length of the elements of an array.  Both
> > of the following work, but can anyone come up with a simpler or more
> > elegant solution?
> > 
> > ===
> > 
> > my $maxlen=0;
> > foreach my $element (@array) {
> >     if ($maxlen < length($element)) {
> >         $maxlen = length($element);
> >     }
> > }
> > 
> > ===
> > 
> > my $maxlen = (sort {$a <=> $b} map {length} @array)[-1];
> > 
> > ===
> > 
> > Any other ideas?
> 
> my $maxlen;
> map {length($_)>$maxlen and $maxlen=length($_)} @array;

my $maxlen;
$maxlen ^= "$_" for @array;
$maxlen = length $maxlen;

I'm not certain the quotes are required.  The documentation would seem
to state that they are if some of the data could be numeric, but my
(very limited) testing did not seem to bare this out.

Golf version:
$m^="$_"for@array;$maxlen=length$m

compared to these:
$maxlen=(sort{$a<=>$b}map length,@array)[-1]
map{length>$maxlen and$maxlen=length}@array
length>$maxlen and$maxlen=length for@array
y///c>$maxlen and$maxlen=y///c for@array


Here's some test and benchmark code for these:

perl -l -MBenchmark <<'EOD'
@array=qw/one two 3 four fifteen 2000/;
for my $code (<DATA>) {
   my $maxlen;
   chomp $code;
   eval $code;
   print length $code, ":$maxlen:$code";
   $code{$code}=$code;
}
timethese 100_000, \%code;
__DATA__
$maxlen=(sort{$a<=>$b}map length,@array)[-1]
map{length>$maxlen and$maxlen=length}@array
length>$maxlen and$maxlen=length for@array
y///c>$maxlen and$maxlen=y///cfor@array
$m^="$_"for@array;$maxlen=length$m
$m^=$_ for@array;$maxlen=length$m
EOD
44:7:$maxlen=(sort{$a<=>$b}map length,@array)[-1]
43:7:map{length>$maxlen and$maxlen=length}@array
42:7:length>$maxlen and$maxlen=length for@array
39:7:y///c>$maxlen and$maxlen=y///cfor@array
34:7:$m^="$_"for@array;$maxlen=length$m
33:7:$m^=$_ for@array;$maxlen=length$m
Benchmark:
timing 100000 iterations of
 $m^="$_"for@array;$maxlen=length$m, $m^=$_
for@array;$maxlen=length$m, $maxlen=
(sort{$a<=>$b}map length,@array)[-1], length>$maxlen and$maxlen=length
for@array
, map{length>$maxlen and$maxlen=length}@array, y///c>$maxlen
and$maxlen=y///cfor
@array
 ...

$m^="$_"for@array;$maxlen=length$m:
  3 wallclock secs ( 2.32 usr + 0.00 sys = 2.32 CPU) @ 43103.45/s (n=100000)

$m^=$_ for@array;$maxlen=length$m:
  2 wallclock secs ( 2.07 usr + 0.01 sys = 2.08 CPU) @ 48076.92/s (n=100000)

$maxlen=(sort{$a<=>$b}map length,@array)[-1]:
  5 wallclock secs ( 4.55 usr + 0.00 sys = 4.55 CPU) @ 21978.02/s (n=100000)

length>$maxlen and$maxlen=length for@array:
  2 wallclock secs ( 1.71 usr + 0.00 sys = 1.71 CPU) @ 58479.53/s (n=100000)

map{length>$maxlen and$maxlen=length}@array:
  4 wallclock secs ( 3.84 usr + 0.00 sys = 3.84 CPU) @ 26041.67/s (n=100000)

y///c>$maxlen and$maxlen=y///cfor@array:
  3 wallclock secs ( 2.53 usr + 0.00 sys = 2.53 CPU) @ 39525.69/s (n=100000)


Not surprisingly, the straight-forward for loop is the fastest and the
sort is the slowest.  That the XOR is faster than the MAP is a bit
surprising.

-- 
Ren Maddox
ren@tivoli.com


------------------------------

Date: 13 Sep 2000 00:25:35 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Finding maximum length
Message-Id: <m33dj4eucw.fsf@dhcp11-177.support.tivoli.com>

jason <elephant@squirrelgroup.com> writes:

> Jeff Pinyan <jeffp@crusoe.net> wrote ..
> >On Sep 13, jason said:
> >
> >>Jeff Pinyan <jeffp@crusoe.net> wrote ..
> >>>[posted & mailed]
> >>>
> >>>On Sep 13, greg_sands@my-deja.com said:
> >>>
> >>>>I'm trying to find the maximum length of the elements of an array.  Both
> >>>>of the following work, but can anyone come up with a simpler or more
> >>>>elegant solution?
> >>>>
> >>>  $len < $_ and ($len = $_) for @array;
> >>
> >>I thought the originator was after the element with the longest length - 
> >>not the numerically largest element
> >
> >  s'$_'length'g;
> 
> now you're left with $len containing the longest length .. not the 
> element *with* the longest length

And that is what the OP wanted, the longest length not the longest
element.

-- 
Ren Maddox
ren@tivoli.com


------------------------------

Date: Wed, 13 Sep 2000 16:03:12 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: Finding maximum length
Message-Id: <7an1hcp9dp.fsf@merlin.hyperchip.com>


greg_sands@my-deja.com writes:

> I'm trying to find the maximum length of the elements of an array.  Both
> of the following work, but can anyone come up with a simpler or more
> elegant solution?
> 
> ===
> 
> my $maxlen=0;
> foreach my $element (@array) {
>     if ($maxlen < length($element)) {
>         $maxlen = length($element);
>     }
> }

I would also use this for clarity.

> ===
> 
> my $maxlen = (sort {$a <=> $b} map {length} @array)[-1];

This can be made shorter:

	my $maxlen = (sort {$b <=> $a} map {length} @array);

--Ala


------------------------------

Date: Wed, 13 Sep 2000 16:35:04 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Finding maximum length
Message-Id: <srvb5omqct6169@corp.supernews.com>

greg_sands@my-deja.com wrote:
: I'm trying to find the maximum length of the
: elements of an array.  Both of the following work,
: but can anyone come up with a simpler or more
: elegant solution?

Less elegant than silly, but at least it's O(N)... ;)

  $len = do { my $s; $s |= $_ for @array; length $s };

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Every force evolves a form."
   |              - Shriekback


------------------------------

Date: Wed, 13 Sep 2000 17:07:51 +0200
From: "FX" <FX@hasnomail.com>
Subject: Re: Finding subdirectories on Windows Systems
Message-Id: <8po543$c2j$1@front7.grolier.fr>

Well when isaid verbose I meant with a tiny little sample :-)

I'm quite new to perl

so thanks for your answer but it doesn't help me much.

FX

Thorbjørn Ravn Andersen a écrit dans le message
<39BF9390.EE9FA023@bigfoot.com>...
>FX wrote:
>>
>> Hi,
>>
>> How can I find the subdirectories from base directory on a windows
machine?
>
>Look into File::Find where you test with a "-d".
>
>--
>  Thorbjørn Ravn Andersen         "...plus...Tubular Bells!"
>  http://bigfoot.com/~thunderbear




------------------------------

Date: Wed, 13 Sep 2000 15:58:08 GMT
From: "David Sisk" <davesisk@ipass.net>
Subject: Function to convert whole + fractions to decimal numbers?
Message-Id: <kuNv5.2847$IV1.896394@typhoon.southeast.rr.com>

I'm thinking in terms of stock quotes here.   Does Perl have any built-in
functions to convert (for example) "67 3/4" to "67.75"?

Best regards,
Dave





------------------------------

Date: 13 Sep 2000 16:08:29 GMT
From: Randy Kobes <randy@theoryx5.uwinnipeg.ca>
Subject: Re: Function to convert whole + fractions to decimal numbers?
Message-Id: <8po8pt$3og$1@canopus.cc.umanitoba.ca>

In comp.lang.perl.misc, David Sisk <davesisk@ipass.net> wrote:
> I'm thinking in terms of stock quotes here.   Does Perl have any built-in
> functions to convert (for example) "67 3/4" to "67.75"?

Take a look that the Math::Fraction module - see, eg,
http://theoryx5.uwinnipeg.ca/mod_perl/cpan-search?doc=Math::Fraction
for a synopsis.

best regards,
randy kobes


------------------------------

Date: 13 Sep 2000 16:43:01 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Function to convert whole + fractions to decimal numbers?
Message-Id: <slrn8rvbil.jp6.abigail@alexandra.foad.org>

David Sisk (davesisk@ipass.net) wrote on MMDLXX September MCMXCIII in
<URL:news:kuNv5.2847$IV1.896394@typhoon.southeast.rr.com>:
@@ I'm thinking in terms of stock quotes here.   Does Perl have any built-in
@@ functions to convert (for example) "67 3/4" to "67.75"?


No. But a simple substitution and an eval can solve the above problem.
Of course, you might have other data too.


Abigail
-- 
perl  -e '$_ = q *4a75737420616e6f74686572205065726c204861636b65720a*;
          for ($*=******;$**=******;$**=******) {$**=*******s*..*qq}
          print chr 0x$& and q
          qq}*excess********}'


------------------------------

Date: Wed, 13 Sep 2000 16:55:35 GMT
From: Yanick Champoux <yanick@babyl.sympatico.ca>
Subject: Re: Function to convert whole + fractions to decimal numbers?
Message-Id: <bkOv5.258532$1h3.5068947@news20.bellglobal.com>

David Sisk <davesisk@ipass.net> wrote:
: I'm thinking in terms of stock quotes here.   Does Perl have any built-in
: functions to convert (for example) "67 3/4" to "67.75"?

	Built-in? I don't think so. But there's maybe ways to do the 
	convertion. Like

	perl -e'$_=shift; y/ /+/; print eval' '67 3/4'

Joy,
Yanick

-- 
eval" use 'that poor Yanick' ";
print map{ (sort keys %{{ map({$_=>1}split'',$@) }})[hex] }
qw/8 b 15 1 9 10 11 15 c b 13 1 12 b 13 f 1 c 9 a e b 13 0/;


------------------------------

Date: Wed, 13 Sep 2000 16:09:13 GMT
From: cfedde@u.i.sl3d.com (Chris Fedde)
Subject: Re: Getting started w/ Perl
Message-Id: <JENv5.128$W3.171024384@news.frii.net>

In article <8pi6hp$ndf$1@nnrp1.deja.com>, Phil  <gphil111@my-deja.com> wrote:
>
>Im really serious about learning this.  I absorb general computing info
>rather quickly, so just how long (approx), spending several hours a
>day, should getting it down take.... from now to pumping out working
>cgi scripts for my sites?
>

Pumping out CGI scripts can be done in no time and without any
programming skills at all.  Learning programming is a different
matter all together.  I think that Perl can be a great first
programming language.  It allows the novice wonderfull opportunities
to see many similar solutions to a problem.  A couple good books
can help to get started on the right track though.

    Learning Perl by Schwartz

Then there are lots of ways to go.

    Mastering Algorithms With Perl by Jon Orwant, et al

is a great "second semester" programming book using perl,

    Effective Perl Programming by Joseph N. Hall.
    Mastering Algorithms With Perl by Jon Orwant, et al
    Object Oriented Perl by Damian Conway
    Perl Cookbook by Tom Christiansen, et al

Are all good continuations of the theme.

While you are studying these in front of the computer get and read
these others while you are sitting on the bus (or where ever it is that you
have time to just read)

    Extreme Programming Explained by Kent Beck
    Introduction to the Personal Software Process by Watts S. Humphrey
    The Mythical Man-Month by Frederick P. Brooks

Of course none of this has anything to do with CGI programming.  You can
learn the issues surrounding that by reading resources on the web, the
documentation of CGI.pm and studying master programmers code.

chris
-- 
    This space intentionally left blank


------------------------------

Date: Wed, 13 Sep 2000 15:27:12 GMT
From: "Brad" <flyboy@optushome.com.au>
Subject: grep in perl
Message-Id: <k1Nv5.5938$gg.17366@news1.rivrw1.nsw.optushome.com.au>

Hi,
      Well I can honestly say I know nothing of perl. The thing is I need a
script, and I guess perl would be the answer.
 I need this script to do a "netstat -M |grep keyword" and then output each
instance of this into another logfile...say output.log, complete with
timestamp. If there is no instances of the keyword, then it should not
output anything at all into the other log file. This is just so I can see
who is doing things they should not be doing on the network at time
intervals. I plan on executing this through cron.
 As this is only relatively small, is there a simple way of doing this?
 Any help would be very much appreciated.
 Thanks.
 Brad





------------------------------

Date: 13 Sep 2000 16:41:20 GMT
From: abigail@foad.org (Abigail)
Subject: Re: grep in perl
Message-Id: <slrn8rvbfg.jp6.abigail@alexandra.foad.org>

Brad (flyboy@optushome.com.au) wrote on MMDLXX September MCMXCIII in
<URL:news:k1Nv5.5938$gg.17366@news1.rivrw1.nsw.optushome.com.au>:
{} Hi,
{}       Well I can honestly say I know nothing of perl. The thing is I need a
{} script, and I guess perl would be the answer.

Wrong guess. It's far better to write any program in a language you
already know.

{}  I need this script to do a "netstat -M |grep keyword" and then output each
{} instance of this into another logfile...say output.log, complete with
{} timestamp. If there is no instances of the keyword, then it should not
{} output anything at all into the other log file. This is just so I can see
{} who is doing things they should not be doing on the network at time
{} intervals. I plan on executing this through cron.
{}  As this is only relatively small, is there a simple way of doing this?

Yes. It's about 3 lines of shell code, most of which you already have
in your posting. No need for Perl.


Abigail
-- 
perl -we '$| = 1; $_ = "Just another Perl Hacker\n";  print
          substr  $_ => 0, 1 => "" while $_ && sleep 1 => 1'


------------------------------

Date: 12 Sep 2000 22:57:49 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Hash of Hash of Hash
Message-Id: <m3d7i9djuq.fsf@dhcp11-177.support.tivoli.com>

"news.t-online.de" <nico.rittner@h-pro.de> writes:

> Hi,
> 
> one small question about combining hashes.
> 
> What i already know is that the following works:
> 
> %hash=(student => {name=> "nico"},
>                     {age => "23},
> ...
> and so on

OK, so it appears that you are aware of the need for curly braces to
create a hash reference to be stored in another hash.

> but does it also work to extend the "hash depth"

Yes, it does.

> %site_cfg = (
> 
> tbl_firmenindex=>   ("name"    =>  "_swbpark_newsflash"),
> 
>                     ("fields"  =>(  "name"  => "Name",
>                                     "strasse" => "Strasse")),
> ....
> 
> and accessing it by %site_cfg{'fields'}{'name'}
> 
> i tried it out , but did not get it working.

Well, if you tried it as you have shown, then you forgot the curly
braces and just used parens, which isn't going to work.

Based on the way you want to access it (which isn't quite right, you
don't use "%" to get at members of a hash, just "$" -- the braces
"{...}" are what lets Perl know you are accessing a hash), you want
something like:

%site_cfg = (
              name   => "_swbpark_newsflash",
              fields => {
                          "name"    => "Name",
                          "strasse" => "Strasse",
                        },
            );

Note that the extra commas and the particular formatting style are
intended to make it easier to maintain this initialization over time
as fields are added or changed or reordered (for code clarity, as the
order does not make a difference unless duplicates exist).

Access would be via:

$site_cfg{fields}{name}

Of course, this isn't really any deeper than your original example,
probably because I ignored "tbl_firmenindex" since you didn't seem to
use it in your description of access.  Still, once you have the
concept of using curly braces for hash references down, extending this
deeper is straight-forward.

For more information, see the following documentation:
perldoc perlref   # covers references
perldoc perllol   # list of lists; similar to hashes of hashes
perldoc perldsc   # data structures cookbook; section on hashes of hashes

HTH...

print map{chop}sort split/(..)/,"aJe fagnqllrhoprcsvkxrshnPbuucjhkedty,z
wem tar oeit"
-- 
Ren Maddox
ren@tivoli.com


------------------------------

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 4312
**************************************


home help back first fref pref prev next nref lref last post