[18027] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 187 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 31 21:05:34 2001

Date: Wed, 31 Jan 2001 18:05:09 -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: <980993109-v10-i187@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 31 Jan 2001     Volume: 10 Number: 187

Today's topics:
        any tips on using Image::Magick sharpen() dtbaker_dejanews@my-deja.com
    Re: Cant gunzip pmtools-1.00.tar.gz (David Efflandt)
    Re: cgi: multiple file-upload (David Efflandt)
        Display URL with perl? Quick question. pcrev@my-deja.com
    Re: format <mjcarman@home.com>
    Re: format <chrisw@dynamite.com.au>
        Help with headers in IE?? <gorgano@altavista.com>
    Re: How do you set a timer on a script? <ccx138@coventry.ac.uk>
    Re: Net::Telnet, How do i 'print' Arrow Keys? (Garry Williams)
    Re: Perl script for Cisco <anonymous@anonymous.anonymous>
        Perl sockets with suid C wrapper buckwld76@my-deja.com
    Re: question about sort k9boy@my-deja.com
    Re: question about sort k9boy@my-deja.com
    Re: question about sort <mischief@velma.motion.net>
    Re: question about sort <mischief@velma.motion.net>
    Re: Question on appending to file dtbaker_dejanews@my-deja.com
    Re: Question on appending to file <ccx138@coventry.ac.uk>
        question on external functions <bob@trg.saic.com>
    Re: Referencing module functions query. <mjcarman@home.com>
    Re: Referencing module functions query. (Eric Bohlman)
    Re: Seeking timezone conversion advice (James Weisberg)
        sorting through a hash of arrays onarasim@my-deja.com
        TOOLS Europe 2001 alexander_prigozhin@my-deja.com
    Re: Using global var in subroutine <wyzelli@yahoo.com>
        WebCT (just for intrest) <ccx138@coventry.ac.uk>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 01 Feb 2001 00:55:21 GMT
From: dtbaker_dejanews@my-deja.com
Subject: any tips on using Image::Magick sharpen()
Message-Id: <95ac5l$eq4$1@nnrp1.deja.com>

I have been using Magick to scale some images, and it fuzzes up the
edges quite a bit. I am wondering what the best technique to retain the
best clarity might be?

First, is it best to convert to .tiff before sizing?

Second, the docs on sharpen are a bit sketchy. The parameters are listed
as
geometry=>geometry,
radius=>double, sigma=>double

but i dont really know what range of values might be good, or how to
determine a good value to correct for agiven degree of sizing. Any tips
on "Average" values would be appreciated.

Initially, I am working with reducing .jpgs from about 1024xN to 600xN,
but later I'll have some higher resolution originals from a 3MP camera
so the images will be 2048xN

thanx,

Dan


Sent via Deja.com
http://www.deja.com/


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

Date: Thu, 1 Feb 2001 01:15:18 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Cant gunzip pmtools-1.00.tar.gz
Message-Id: <slrn97he3r.rk4.efflandt@efflandt.xnet.com>

On Wed, 31 Jan 2001, blackpike@my-deja.com <blackpike@my-deja.com> wrote:
>Hello everyone,
>   I'm trying to install pmtools-1.00, but every version I've
>downloaded fails to gunzip.
>I'm using Redhat Linux 5.2 and Gunzip verion 1.2.4 (18 Aug 93)

RH5.2 is quite old.  What error do you get from gunzip.  If you ran this
file though a Windows box, make sure that you downloaded it in binary
mode, and transfer it to your Linux box as binary.

Since you have GNU tar you can usually just cd to the dir you want to
unpack it and use tar xzvf:

su -
cd /usr/src
tar xzvf /home/blackpike/pmtools-1.00.tar.gz

(or wherever the original file is)

-- 
David Efflandt  efflandt@xnet.com  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Thu, 1 Feb 2001 01:24:55 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: cgi: multiple file-upload
Message-Id: <slrn97helr.rk4.efflandt@efflandt.xnet.com>

On 31 Jan 2001 12:20:09 +0000, nobull@mail.com <nobull@mail.com> wrote:
>peter pilsl <pilsl_@goldfisch.at> spams:
>
>> Is it possible to realize a multi-upload-field (a form-element where the 
>> user can select more than one files for uploading) in perl ?
>
>Please don't spam.  Not ever.  Not even a little bit.  Post your
>question once only.  Crosspost iff approriate.  Never post again
>immediately in another newsgroup.
>
>Answer given in comp.lang.perl.modules.

I have seen that newsgroup mentioned here, but it is apparently not on my
ISP's news server.  In fact this seems to be the only *perl* newsgroup
left that slrn can find for me.

CGI.pm can do multple file upload, but each needs a different variable
name.  For example I might have a submit button called 'upload' with file
upload fields: 'upload1', 'upload2', ...) and start the routine to handle
them:

# File upload routine
if (param('upload')) {
    for $i (1..5) {
        if ($upload = param('upload'.$i)) {

-- 
David Efflandt  efflandt@xnet.com  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Wed, 31 Jan 2001 23:08:28 GMT
From: pcrev@my-deja.com
Subject: Display URL with perl? Quick question.
Message-Id: <95a5t6$9b5$1@nnrp1.deja.com>

Hi I need to use a perl SSI, that will basically display the URL of the
page you are viewing. Does anyone know how this is done? If anyone does,
 please email me ASAP: pete at pcrev dot com

Thanks a lot!


Sent via Deja.com
http://www.deja.com/


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

Date: Wed, 31 Jan 2001 16:41:42 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: format
Message-Id: <3A7894A6.351F17B3@home.com>

nandagopalj@hotmail.com wrote:
> 
> Hello:
> 
> I am using a format statement to print out a report.
> 
> format DOUT =
> @<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<< @<<<<
> $ONE,$TWO,$THREE,$FOUR
> .
> 
> when the variable $FOUR has the value less than four characters
> e.g. "12" then the new line character is printed immediately
> after 12. What I want is that 12 must be padded with blank spaces
> and then a new line must be printed.
> 
> Is there any format related intricacy that can help do this?

Off the top of my head, I'm not sure. I don't think so, but I've never
used formats much. Check the perlform manpage. If you can do it, it
should be mentioned in there.

Of course, you could always do something like this:

$FOUR = sprintf("%-4s", $FOUR);

-mjc


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

Date: Thu, 1 Feb 2001 11:01:08 +1100
From: "Chris W" <chrisw@dynamite.com.au>
Subject: Re: format
Message-Id: <yI1e6.20$zt5.1618@news0.optus.net.au>


<nandagopalj@hotmail.com> wrote in message
news:959vf6$3b6$1@nnrp1.deja.com...
> Hello:
>
> I am using a format statement to print out a report.
> format DOUT =
> @<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<< @<<<<
> $ONE,$TWO,$THREE,$FOUR
> .

The > format caharcter is what you seek:

#!perl -w
use strict;
my ($one, $two, $three, $four) = (12,34,56,78);
format STDOUT =
@<<<<<<<*@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*@<<<<*@>>>>*
$one,$two,$three,$four
 .
write;
__END__





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

Date: Thu, 01 Feb 2001 01:01:04 GMT
From: Jason Hurst <gorgano@altavista.com>
Subject: Help with headers in IE??
Message-Id: <95acgb$f6k$1@nnrp1.deja.com>

ok, here is a fun one. I've got these binary files i want to send to
the browser.  Now because of sercurity stuff i'm using a perl script to
read in the file and then send it on it's way.  Pretty basic, open the
file, bindmod it and stdout, then do a read() and simply print out the
data a little bit at a time.  Works fine in netscape, but for some
reason when i'm using IE, it First prompts if i want to save or open
the script file, if you hit open, it then asks if you want to save or
open the script file AGAIN, hit open, and THEN it asks if you want to
save the file.  Anyone seen anything like this?  the headers i'm using
are like this:

Content-Disposition: attachment; filename="addbook-1.0.tar.gz"
Content-Type: application/octet-stream

NOte this also happens on text/plain, but not with text/html..

any guesses?  Thanks for your help!

-jason JAPH


Sent via Deja.com
http://www.deja.com/


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

Date: Wed, 31 Jan 2001 22:44:21 +0000
From: John Tutchings <ccx138@coventry.ac.uk>
Subject: Re: How do you set a timer on a script?
Message-Id: <3A789545.5C86FF02@coventry.ac.uk>

With NT or Windows,  try wincron you can get it from winfiles.
"At" on NT is a bit strange as to who it fires the process off as,
especially if you have something like Netware sitting as the servers.

Brendon Caligari wrote:

> In article <Fx%d6.49531$_8.1469389@news1.rdc1.bc.home.com>,
>   "cam" <cam@home.com> wrote:
>
> > How can I get a perl script to execute at a specific time?
> > For example:
> >
> > At 6am -> run this script "parseNews.pl"
> >
>
> using unix:
> man cron
>
> using win2000
> help at     (but i have never tried it)
>
> Brendon
>
> Sent via Deja.com
> http://www.deja.com/



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

Date: Wed, 31 Jan 2001 23:13:51 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: Net::Telnet, How do i 'print' Arrow Keys?
Message-Id: <P_0e6.87$Sn3.4605@eagle.america.net>

On Wed, 31 Jan 2001 15:47:44 +0100, Stefan Bach <stefan.bach@web.de>
wrote:
>"Garry Williams" <garry@zvolve.com> schrieb im Newsbeitrag
>news:WmVd6.17$Sn3.1968@eagle.america.net...
>> On Wed, 31 Jan 2001 14:30:06 +0100, Stefan Bach <stefan.bach@web.de>
>> wrote:
>> >I'm connecting to a Switch via Telnet.
>> >Unfortunately the Switch has a menu-based user interface.
>> >How can I send ($obj->print();) Keys like the arrow Keys?
>> >Are there ESC-Codes or how can it be done?
>>
>> What does the program at the other end expect?
>
>I want to disable ports at the switch, using a script. Though there is only
>a menu-based interface I have to tell the telnet server the down key was
>pressed to select the right port.

No.  What charater codes does the switch expect?  I would assume that
the switch vendor would have documentation about this.  

>> This doesn't seem to be a Perl issue at all, does it?
>
>Well... I use Perl (net::telnet) to communicate with the server.
>And I don't think there is a
>comp.telnet.whichcodedoihavetosendtotellthedownarrowwaspressed newsgroup.

Oh, now I see.  If there's no appropriate Usenet group, clpm must be
okay.  Hmmm.  

>A simple link to a Webpage with a list of all codes would be enough.
>Perhabs somebody experienced the same problem and can help me.

Why don't you consult your vendor's documentation?  Alternatively, go
look up the codes a VT100 generates and under what conditions it will
do that.  

>> [off topic]
>>
>> Even so, you might want to look at snoop(1) or its equivalent on your
>> client machine.  That would enable you to "see" what is being sent to
>> the server when you type it on the client.
>
>Currently I'm using a Win2k machine. I don't think it is available here.

Then put a Unix host on a hub with your Win2k machine and snoop the
traffic there.  Or get a traffic analyzer and plug it into a hub with
the Win2k thing.  Or download one of a zillion snoops for Windows and
use it.  Or write a Perl script to snoop the traffic...

You really need to take this somewhere else.  It's *not* Perl.  

-- 
Garry Williams


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

Date: Wed, 31 Jan 2001 20:12:47 -0500
From: Anonymous <anonymous@anonymous.anonymous>
Subject: Re: Perl script for Cisco
Message-Id: <cvdh7t88u22jq57f4fr2l45f568b8b6eui@4ax.com>

On 29 Jan 2001 08:01:57 GMT, "Jerome" <jmeyer@pax.ch> wrote:

>
snip...
>
>Do anyone know what perl's module or perl's command I must to use to access
>my router?
>Is really possible to make that??
>

Try Net::Telnet::Cisco at CPAN.


  --------== Posted Anonymously via Newsfeeds.Com ==-------
     Featuring the worlds only Anonymous Usenet Server
    -----------== http://www.newsfeeds.com ==----------


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

Date: Thu, 01 Feb 2001 00:49:45 GMT
From: buckwld76@my-deja.com
Subject: Perl sockets with suid C wrapper
Message-Id: <95abr6$ejk$1@nnrp1.deja.com>

I'm trying to get two perl scripts to talk back and forth to one
another.  Using ports over 10000 I can have a normal user open up a
socket and send some text, no problem.  Now, if I put the same script
inside of a suid C wrapper, it can create the socket, but fails to print
to it due to a Broken Pipe.

I'd appreciate if you write me directly if you know how to fix this
problem.  (dopheide@uiuc.edu)

Thanks,
Mike


Sent via Deja.com
http://www.deja.com/


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

Date: Wed, 31 Jan 2001 22:57:08 GMT
From: k9boy@my-deja.com
Subject: Re: question about sort
Message-Id: <95a580$8pk$1@nnrp1.deja.com>

Okay, maybe I'm too new to all this, but what FAQ? I was not aware that
one existed. Thanks for mentioning it - I found it on google. BTW, this
is not a homework excercise (a class in perl would be amazing and
extremely useful for me right now), though I can see how it does
resemble one.

I searched google - quite a bit actually - and read up on a bunch of
sort, but I never actually saw an example that answered my question. I
was too busy for extensive reading since I only needed this one thing
to save me time from writing my own sort. My question was really
concerning syntax of sort with a hash list. It'll take a while before I
fully understand perl's robust sort. As for the rounding, it was a
question that I knew I'd probably stumble upon in my search. But as
long as I was asking this, I'd figure I'd nail to birds with one stone.
Isn't the rounding question fairly typical though? When you think
round, you think ceil and floor.

Well, thanks for making me aware of an FAQ. Didn't mean to come off as
a lazy bum :)

In article <u93ddzpq37.fsf@wcl-l.bham.ac.uk>,
  nobull@mail.com wrote:
> k9boy@my-deja.com writes:
>
> > I intend to have a list with elements like so:
> >
> > a[0] = {
> > NAME => "Joe",
> > AGE => "25"
> > };
> >
> > Is it possible to use the perl's sort to sort the list by NAME, AGE,
> > etc? Meaning, the entire element a[0] is moved to its proper
position,
> > not just a[0]->{NAME}. If it can be done, what would it look like?
>
> FAQ: "How do I sort an array by (anything)?"
>
> > While I'm at it, is there a round, ceil, floor function for perl?
>
> FAQ: "Does Perl have a round() function?  What about ceil() and
> floor()? ..."
>
> Two unrelated questions.  Both from the FAQ.  The second lifted almost
> verbatim from the FAQ.
>
> Do I smell a homework exercise?
>
> If so, then I suspect the purpose of the exercise was to test your
> ability to use the documentation.  Were you expressly asked to do this
> without reading the FAQ?  If so I suspect your teacher also didn't
> want you to come here and ask someone else to read the FAQ to you.  I
> think the idea was probably that you should work it out for yourself.
>
> --
>      \\   ( )
>   .  _\\__[oo
>  .__/  \\ /\@
>  .  l___\\
>   # ll  l\\
>  ###LL  LL\\
>


Sent via Deja.com
http://www.deja.com/


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

Date: Wed, 31 Jan 2001 23:01:52 GMT
From: k9boy@my-deja.com
Subject: Re: question about sort
Message-Id: <95a5gq$8uq$1@nnrp1.deja.com>

didn't know there was an faq. I do now. Thanks a lot.

In article <3A784EA4.28BD7BA5@home.com>,
  Michael Carman <mjcarman@home.com> wrote:
> k9boy@my-deja.com wrote:
> >
> > I intend to have a list with elements like so:
> >
> > a[0] = {
> > NAME => "Joe",
> > AGE => "25"
> > };
> >
> > Is it possible to use the perl's sort to sort the list by NAME, AGE,
> > etc? Meaning, the entire element a[0] is moved to its proper
position,
> > not just a[0]->{NAME}.
>
> Certainly. Did you miss the FAQ entry "How do I sort an array by
> (anything)?" You did check the FAQ before posting, didn't you?
>
> BTW: please use proper syntax. It's '$a[0]' not 'a[0]'.
>
> > If it can be done, what would it look like?
>
> @a = sort {$a->{NAME} cmp $b->{NAME} ||
>            $a->{AGE}  <=> $b->{AGE}    } @a;
>
> > Otherwise, I have to write my own quicksort.
>
> No, just your own sortsub.
>
> > While I'm at it, is there a round, ceil, floor function for perl?
>
> Not built-in, but you can easily write your own.
>
> -mjc
>


Sent via Deja.com
http://www.deja.com/


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

Date: Wed, 31 Jan 2001 23:58:21 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: question about sort
Message-Id: <t7h9ktg1fg5u6b@corp.supernews.com>

tigra@sky.deep.ru wrote:
> In article <959d7i$h16$1@nnrp1.deja.com>,
>   k9boy@my-deja.com wrote:
>> I intend to have a list with elements like so:
>>
>> a[0] = {
>> NAME => "Joe",
>> AGE => "25"
>> };
>>
>> Is it possible to use the perl's sort to sort the list by NAME, AGE,
>> etc? Meaning, the entire element a[0] is moved to its proper position,
>> not just a[0]->{NAME}. If it can be done, what would it look like?
>> Otherwise, I have to write my own quicksort.

> No need for own quicksorts. Just use:
> (@array is your @a, just for clarity)

> sort {$array[$a]{'AGE'} <=> $array[$b]{'AGE'}} @array; # Sort @array by
> in ascending order

Okay. This sorts by age (or does it? ).

> sort {$array[$b]{'AGE'} <=> $array[$b]{'AGE'}} @array; # The same, but
> in descending order

How is that? Comparing $b to itself is descending? That's news.

> sort {$array[$a]{'NAME'} cmp $array[$b]{'NAME'}} @aaray; # by name
> alphabetically ascending

Are you sure? I believe this does character set order unless you set
a locale that handles things otherwise. Besides, you have another typo
in this code.

sort {$array[$a]{lc('NAME')} cmp $array[$b]{lc('NAME')}} @array;

Even this code doesn't seem to work. The hashes don't move around
within the array. They just stay where they are. Bracketing the
terms of the cmp doesn't seem to help, either. Perhaps the return
value of the sort needs to be assigned to something, since you
call it in a void context.( Warnings and strictures would help
you find this sort of thing. They are requested of people posting
problems and should be required when posting "solutions". )

Please test your code before posting, and cut and paste the code
to avoid ttypos.

Just below is a program made using the above suggestions, and its
output. For demonstrative purposes, I defined the elements of the
array separately, although this isn't likely in a real program.

#######################
$array[0] = {
NAME => "Joe",
AGE => "25"
};

$array[1] = {
NAME => "Ian",
AGE => "26"
};

$array[2] = {
NAME => "Kyle",
AGE => "24"
};

sort { $array[$a]{lc('NAME')} cmp $array[$b]{lc('NAME')} } @array;

print $array[0]->{'NAME'} . " " . $array[0]->{'AGE'} . "\n";
print $array[1]->{'NAME'} . " " . $array[1]->{'AGE'} . "\n";
print $array[2]->{'NAME'} . " " . $array[2]->{'AGE'} . "\n";

sort {$array[$a]{'NAME'} cmp $array[$b]{'NAME'}} @array;

print $array[0]->{'NAME'} . " " . $array[0]->{'AGE'} . "\n";
print $array[1]->{'NAME'} . " " . $array[1]->{'AGE'} . "\n";
print $array[2]->{'NAME'} . " " . $array[2]->{'AGE'} . "\n";
#######################

OUTPUT:
#######
Joe 25
Ian 26
Kyle 24
Joe 25
Ian 26
Kyle 24
#######

Notice the use of sort with no left-hand side, and the fact that
nothing changes.

The below code may work better, but with 32 megabytes of free main
memory left on my test machine without touching swap, it ran out of
memory every time I tried to run it (with or without the conversion
to lowercase).

#####################
$array[0] = {
NAME => "Joe",
AGE => "25"
};

$array[1] = {
NAME => "Ian",
AGE => "26"
};

$array[2] = {
NAME => "Kyle",
AGE => "24"
};

@array = sort { $array[$a]{lc('NAME')} cmp $array[$b]{lc('NAME')} } @array;
print $array[0]->{'NAME'} . " " . $array[0]->{'AGE'} . "\n";
print $array[1]->{'NAME'} . " " . $array[1]->{'AGE'} . "\n";
print $array[2]->{'NAME'} . " " . $array[2]->{'AGE'} . "\n";
#####################


I took the initiative here to write a subroutine which breaks the
reference handling and the sorting apart and still uses Perl's
built-in sort function. It takes a reference to the array of hashes
and the key upon which to sort. It returns a reference to the sorted
array of hashes.

####################################################################
#!/usr/bin/perl -w
use strict;

my @array;

$array[0] = {
NAME => "Joe",
AGE => "25"
};

$array[1] = {
NAME => "Ian",
AGE => "26"
};

$array[2] = {
NAME => "Kyle",
AGE => "24"
};

###
### The soubroutine invoked in the line below takes a reference
### to an array of hashes and a scalar of the key on which to
### sort. It returns a reference to the array, sorted by the
### desired key.
###
### usage:
###    array_of_hashes_sort( arrayref, key_on_which_to_sort );
###
my $sorted_names_ref = array_of_hashes_sort( \@array, 'NAME' );
@array = @{$sorted_names_ref};

print $array[0]->{'NAME'} . " " . $array[0]->{'AGE'} . "\n";
print $array[1]->{'NAME'} . " " . $array[1]->{'AGE'} . "\n";
print $array[2]->{'NAME'} . " " . $array[2]->{'AGE'} . "\n";

###
### Note the only difference here is the key on which to sort.
###
$sorted_names_ref = array_of_hashes_sort( \@array, 'AGE' );
@array = @{$sorted_names_ref};


print $array[0]->{'NAME'} . " " . $array[0]->{'AGE'} . "\n";
print $array[1]->{'NAME'} . " " . $array[1]->{'AGE'} . "\n";
print $array[2]->{'NAME'} . " " . $array[2]->{'AGE'} . "\n";

exit(0);

sub array_of_hashes_sort($$) {
    my $ref = shift;
    my $key = shift;
    my @array = @{$ref};

    my @x;
    my @y;

    for( my $i = 0; $i < @array; $i++ ) {
        push( @x, $array[$i]->{$key} );
        push( @y, $i );
    }
    my @sorted_indexes = sort { $x[$a] cmp $x[$b] } @y;
    my @sorted_hashes;
    foreach( @sorted_indexes ) {
        push( @sorted_hashes, $array[$_] );
    }
    return( \@sorted_hashes );
}
#################################################################


The output is as below:
#######################
Ian 26
Joe 25
Kyle 24
Kyle 24
Joe 25
Ian 26
#######################

Notice that the first call sorts by name and the second by age.
This is determined wholly by which hash key you pass to it.

I'm sure someone can find another and probably even a better way,
(and may have before I finish this post, since I left my desk for
a couple of hours in the middle of this response) but this has been
tested and does work.

HTH,
Chris


-- 
Christopher E. Stith

Even in the worst of times, there is always someone who's
never had it better. Even in the best of times, there is
always someone who's never had it worse.



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

Date: Thu, 01 Feb 2001 00:08:49 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: question about sort
Message-Id: <t7ha8h4c9i6d30@corp.supernews.com>

Michael Carman <mjcarman@home.com> wrote:
> k9boy@my-deja.com wrote:
>> 
>> I intend to have a list with elements like so:
>> 
>> a[0] = {
>> NAME => "Joe",
>> AGE => "25"
>> };
>> 
>> Is it possible to use the perl's sort to sort the list by NAME, AGE,
>> etc? Meaning, the entire element a[0] is moved to its proper position,
>> not just a[0]->{NAME}.

> Certainly. Did you miss the FAQ entry "How do I sort an array by
> (anything)?" You did check the FAQ before posting, didn't you?

> BTW: please use proper syntax. It's '$a[0]' not 'a[0]'.

>> If it can be done, what would it look like?

> @a = sort {$a->{NAME} cmp $b->{NAME} ||
>            $a->{AGE}  <=> $b->{AGE}    } @a;


Much more simple than my original kludged response in another portion
of the thread. It doesn't use references like mine does either, which
can be a plus. (Yes, I'm aware it is an implicit reference to the
user-supplied sort sub, but that's different from passing around
explicit hard refs). If one did like the calling method I used for
some reason, it wouldn't be hard to wrap around this, either.

Good job, Michael. I really do need to brush up on a few things. I
should have had this in mind myself.

Chris

-- 
Christopher E. Stith

If they can get you asking the wrong questions, they don't
have to worry about the answers.
  -- Thomas Pynchon, Gravity's Rainbow



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

Date: Thu, 01 Feb 2001 00:40:37 GMT
From: dtbaker_dejanews@my-deja.com
Subject: Re: Question on appending to file
Message-Id: <95aba3$e51$1@nnrp1.deja.com>

In article <3A77EB92.2A0E00C0@free.fr>,
  Jerome Abela <Jerome.Abela@free.fr> wrote:
> dtbaker_dejanews@my-deja.com wrote :
> > In article <956n4u$608$1@nnrp1.deja.com>,
> >   igotlooks.com <rbfitzpa@my-deja.com> wrote:
> > >  for(<*>) {
> > >    open(FILE,"<$_");
> > >    <FILE>;
> > >    if(!defined(<FILE>)) {
> > >        close(FILE);
> > >        open(FILE, ">>$_");
> > >        print FILE "";
> > --------------
> > with this one you might get in memory trouble if any of the files
are
> > VERY big, or you have LOTS of files in the directory. If neither is
> > expected to be huge, then slurping should be fine. You might want to
use
> > a tight loop that just increments a counter and zips thru the file a
> > line at a time rather than slurping in the entire contents. If the
> > counter is one, then add you bogus line.
>
> Double read the source. It does not slurp the files, it only reads the
> first 2 lines.
-------------------

this line:
> > >  for(<*>) {
could possible get in trouble if the directory listing took more memory
than was available... unlikely, but possible.

this line:
> > >    <FILE>;
doesnt really do anything, but could get in trouble if the contents of
the file were enormous because ALL the lines are sucked into memory...
such as a web server log or something liek that. More likely, and
something to consider.

I dont think this actual solution would work anyway, because it checks
for existance of any lines, not the number of lines==1 as the problem
was described.

It would be much safer to do a opendir and readdir loop, and then open
the FH, put it in a while loop with a counter, and if the counter makes
it to 2, get the next file, and if there is only one line, then close,
open, and append a line before moving to the next file.

D



Sent via Deja.com
http://www.deja.com/


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

Date: Thu, 01 Feb 2001 00:56:31 +0000
From: John Tutchings <ccx138@coventry.ac.uk>
Subject: Re: Question on appending to file
Message-Id: <3A78B43F.CD9D5951@coventry.ac.uk>



dtbaker_dejanews@my-deja.com wrote:

> In article <3A77EB92.2A0E00C0@free.fr>,
>   Jerome Abela <Jerome.Abela@free.fr> wrote:
> > dtbaker_dejanews@my-deja.com wrote :
> > > In article <956n4u$608$1@nnrp1.deja.com>,
> > >   igotlooks.com <rbfitzpa@my-deja.com> wrote:
> > > >  for(<*>) {
> > > >    open(FILE,"<$_");
> > > >    <FILE>;
> > > >    if(!defined(<FILE>)) {
> > > >        close(FILE);
> > > >        open(FILE, ">>$_");
> > > >        print FILE "";
> > > --------------
> > Double read the source. It does not slurp the files, it only reads the
> > first 2 lines.
> -------------------
>
> this line:
> > > >  for(<*>) {
> could possible get in trouble if the directory listing took more memory
> than was available... unlikely, but possible.
>

It may try and open "." and ".."


>
> this line:
> > > >    <FILE>;
> doesnt really do anything, but could get in trouble if the contents of
> the file were enormous because ALL the lines are sucked into memory...
> such as a web server log or something liek that. More likely, and
> something to consider.
>

It reads a line from the file handle and throws it away, it may look as if
it does nothing but it is the same as saying..
$junk = <FILE>;
undef($junk);

Try it.

>
> I dont think this actual solution would work anyway, because it checks
> for existance of any lines, not the number of lines==1 as the problem
> was described.
>

It checks for end of file.  If it is end of file it fails, I believe if
(<FILE>) would have done.
If it is end of file after reading once from the file it must only have one
line in it.
Read the code and read a book.





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

Date: Wed, 31 Jan 2001 14:58:58 -0800
From: Bob Schreiner <bob@trg.saic.com>
Subject: question on external functions
Message-Id: <3A7898B2.DE2F6BFA@trg.saic.com>

Can someone give me a simple example of how to call an external function that
prints the arguement sent to it (e.g. "Hello world")?

Thanks,

 ~ Bob


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

Date: Wed, 31 Jan 2001 08:29:36 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: Referencing module functions query.
Message-Id: <3A782150.62D5A892@home.com>

Trevor Phillips wrote:
> 
> I'm trying to figure out how to call a subroutine in a Perl module, 
> where the name of the routine is arbitary and stored as a string in 
> a scalar.

Ack! Symrefs! Don't!
 
> eg; If I have a variable bink which has the value bill ($bink = "bill"),
> such that I want to call subroutine bill using bink in module Fred, 
> how would I do it??
> 
> More to the point, how do I do it elegantly? ^_^

Use hard references. e.g.

#!/usr/local/bin/perl5 -w
use strict;

my $bink = \&Fred::bill;

&$bink();
&$bink('hi!');

package Fred;

sub bill {
    my $quux = shift || 'what?';
    print "Bill says $quux\n";
}

__END__

Output:
Bill says what?
Bill says hi!

If you have a lot of functions to do this with, you can build a hash:

my %function = (
    bill => \&Fred::bill,
    bob  => \&George::bob,
);

&{$function{bill}}('lalalala');

-mjc


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

Date: 31 Jan 2001 09:42:26 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Referencing module functions query.
Message-Id: <958mm2$6dh$7@bob.news.rcn.net>

In comp.lang.perl.misc Trevor Phillips <phillips@central.murdoch.edu.au> wrote:
> I'm trying to figure out how to call a subroutine in a Perl module, where the
> name of the routine is arbitary and stored as a string in a scalar.

> eg; If I have a variable bink which has the value bill ($bink = "bill"), such
> that I want to call subroutine bill using bink in module Fred, how would I do
> it??

> More to the point, how do I do it elegantly? ^_^
> One way I've nutted out is like this:
>   eval "Fred->$bink"
> But that doesn't seem to be very efficient (using eval & all), and gets more
> complex when you want to pass args to $bink...

Use a hash of coderefs, commonly called a "dispatch table."


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

Date: Thu, 01 Feb 2001 00:17:27 GMT
From: chadbour@wwa.com (James Weisberg)
Subject: Re: Seeking timezone conversion advice
Message-Id: <rW1e6.14439$Sl.622114@iad-read.news.verio.net>

In article <TIZd6.80476$Wq1.33936855@nnrp5-w.sbc.net>,
Darren Dunham  <ddunham@redwood.taos.com> wrote:
>James Weisberg <chadbour@wwa.com> wrote:
>>    Anyway, thanks to those who suggested I try setting $ENV{TZ} and
>> use Time::Local. I thought about that originally but I was uncertain
>> as to how reliable that method would be. The SCO Enterprise (yeah,
>> yeah, I know) OS I tried it on makes the change right away so it
>> worked fine. However, I think the two cooperating functions I had
>> described might work much faster without the need for various time
>> system calls.
>
>'time system calls'?  You're not changing anything on the machine other
>than that one ENV variable.  You're certainly not changing the clock.

	You misunderstood me. I realize setting $ENV{TZ} is not a system
call or a clock change.

>It's just that whenever you use localtime (or timelocal) the TZ variable
>is used for the conversion.

	Right, and *those* are system calls! The two functions I have 
proposed made *no* system calls.  

> Basically, the isdst() function I proposed could use
>> another hash which has hardwired the DST dates for several years. 
>
>That information is already in the OS in the zoneinfo files.  Noone
>wants to reenter that information into another area (possibly
>incorrectly, and harder to change in the future if need be).

	Well here you lost me. Where is it stored, for example, when
a given timezone moves in and out of Daylight Savings Time for the
year 2005? What I proposed was a hash entry:

	$DST{2005} = [20050403, 20051030]

	which represents the first Sunday in April and the last Sunday in
October for 2005. Of course, it would be a simple matter to write a
function which computed these two dates for a given year, but obviously
a direct lookup is *much* faster. Consider looking up whether or not
a given date is in DST for a given year for hundreds of thousands of
records. With the above, I can do:

	my($YYYY, $MM, $DD) = unpack("a4a2a2", $date);
	if ($date < $DST{$YYYY}[0] || $date > $DST{$YYYY}[1]) {
		# NOT in Daylight Savings Time for $YYYY
	} 

	Piece of cake eh? And fast! One of the reasons I store dates in
the form YYYYMMDD is to ensure $date2 > $date1 if $date2 appears on
the calendar *after* $date1.  

>>    which says that Spring Foreword occurs on April 1st 2001 (the
>> first Sunday in April) and Fall Backword occurs on October 28th
>> 2001 (the last Sunday in October).  
>>    Then someone could write:
>
>>    isdst($date, $time, $tz);
>
>What is the difference between $date and $time?  You already have that
>function as part of localtime()..

	$date and $time are arguments passed to the tzconvert() function
I proposed. Basically, the idea is that if I am converting between two
timezones where one honors DST and one does not, I need to know if
$date/$time is in the DST range. The little snippet of code I wrote
above would tell me *immediately* that I am not in the DST range
without the need for a single system call. And as I already pointed
out in the first post, if both timezones honor DST or both do not,
then I can directly compute the offset and produce a conversion, 
also without the need for a system call. 

>>    and if $date < $DST{2001}[0] || $date > $DST{2001}[1], then we
>> are not in Daylight Savings Time (regardless of timezone). More work
>> is needed for boundary conditions, but so far I've yet to even need
>> a time system call [isdst() is not even called unless one timezone
>> uses DST and the other does not.] 
>>    However, unless someone wants to comment specifically on these
>> ideas, I might just take the path of least resistance and use the
>> ENV{TZ} method even though I find it "hokey" to ying-yang my TZ.
>
>I think you're thinking that TZ is somehow more heavyweight or more
>important than something like PATH.  Yes it affects the behavior of
>other programs, but it's not a 'time system call'.

	Not thinking that at all. I'm thinking that changing the working
environment of the program running is "hokey". In fact, to make any
conversion, you'd first have to save the original timezone in a 
temporary variable and restore it before the return:

use Time::Local;
# 00:00 Jan 1 2001
my $etz  = $ENV{TZ};    # copy of ENV timezone 
my @start_time = ( 0,0,0,1,0,2001);
$ENV{TZ} = "GMT0BST";   # from timezone
my $time = timelocal(@start_time);
$ENV{TZ} = "EST5EDT";   #   to timezone
print scalar (localtime($time));
$ENV{TZ} = $etz;        # restore ENV timezone 

	Otherwise, you'd leave the working environment of the program in
the EST5EDT timezone, which could have horrible results if the whole
point was to translate from a variable timezone to whatever $ENV{TZ}
is the machine the conversion takes place on. Frankly, if you don't
consider the ying-yang of $ENV{TZ} "hokey", then you must be some
kinda hack programmer (and I don't mean that as a complement).
 

 
	

-- 
World's Greatest Living Poster


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

Date: Thu, 01 Feb 2001 01:20:32 GMT
From: onarasim@my-deja.com
Subject: sorting through a hash of arrays
Message-Id: <95adkn$g75$1@nnrp1.deja.com>

Hi,
  Here is the problem I am facing.
1. I have a text file which has a number of fields, delimited by tabs.
Each of the fields has some data - all can be treated as strings.

Now, I am interested in ensuring that I keep only those records with
unique values for (say) field 1. Uniqueness suggests that I need a
hash - the wrinkle is that I don't just want a list of unique field 1
values, but instead, the complete record for those cases. Do I need
some kind of array reference as the hash value here? Any suggestions on
how I could proceed?

Thanks a lot for any help.



Sent via Deja.com
http://www.deja.com/


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

Date: Thu, 01 Feb 2001 00:26:14 GMT
From: alexander_prigozhin@my-deja.com
Subject: TOOLS Europe 2001
Message-Id: <95aaet$d99$1@nnrp1.deja.com>

TOOLS Europe 2001
   "Components for Mobile Computing"

Technopark Zurich, Switzerland
   March 12- 14, 2001

http://www.tools-conferences.com/europe

TOOLS, the major international conference series devoted to applications
of object technology, component technology and other modern software
approaches, comes to Switzerland for the first time. TOOLS Europe 2001
focuses on Components for Mobile Computing.  It will be held at the
Technopark Zurich from March 12-14.

TOOLS Europe 2001 will continue the commitment to excellence of
earlier TOOLS conferences in Europe, Australia, Asia and the USA
with a stellar program:

- Keynotes by Malcolm Atkinson, C.A.R. Hoare, B. Meyer, W. Pree and
  Bran Selic

- Tutorials by leading experts in UML/OCL, mobile computing, concurrent
  O-O programming, architectural design, O-O for embedded systems,
  Palm and wireless programming with Java, conceptual modeling,
  eXtreme programming, UML, OCL, genericity in O-O programming,
  component-based development, business rules and more.

- Workshops on Object-Oriented Databases, Eiffel in Europe, System
  and Visioning

- Technical sessions by selected industry and academic presenters

- Panels on Mobile Computing and Testing of O-O Software


Full program and online registration available from

http://www.tools-conferences.com/europe

(Early registration rate applies until February 16, 2001)


Sent via Deja.com
http://www.deja.com/


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

Date: Thu, 1 Feb 2001 09:17:32 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Using global var in subroutine
Message-Id: <Rk1e6.8$wU5.3412@vic.nntp.telstra.net>

"Steve Yates" <steve@teamITS.com> wrote in message
news:t7gb299u2futf9@corp.supernews.com...
> "Wyzelli" <wyzelli@yahoo.com> wrote in message
> news:aFnd6.11$gG5.2848@vic.nntp.telstra.net...
> > What message are you getting from $! in the die?
c:/folder//file.txt is
> > probably not a valid path (the double slash).
>
>     Yes, and that's the message from the die.  That's the point...that
> $userCode has no value in this subroutine for some reason.
>

Maybe you need to show more code, including the part where $userCode is
set.  I can't see anything wrong with what you posted.

One idea would be that $userCode is set elsewhere with a lexical scope
that is out of scope by the time you get to this sub.

Wyzelli
--
push@x,$_ for(a..z);push@x,' ';
@z='092018192600131419070417261504171126070002100417'=~/(..)/g;
foreach $y(@z){$_.=$x[$y]}y/jp/JP/;print;




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

Date: Wed, 31 Jan 2001 23:22:03 +0000
From: John Tutchings <ccx138@coventry.ac.uk>
Subject: WebCT (just for intrest)
Message-Id: <3A789E1A.9EF5FBC5@coventry.ac.uk>

Have any of you worked on or maintained WebCT ?



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

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 V10 Issue 187
**************************************


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