[17226] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4648 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 18 03:05:33 2000

Date: Wed, 18 Oct 2000 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)
Message-Id: <971852710-v9-i4648@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 18 Oct 2000     Volume: 9 Number: 4648

Today's topics:
    Re: Accessing methods created on the fly <ianb@ot.com.au>
    Re: Anyone try to use perl to handle GB text? <jdb@wcoil.com>
        Backup and email a file. My head is spinning! <john@macleodweb.com>
    Re: Backup and email a file. My head is spinning! <godzilla@stomp.stomp.tokyo>
    Re: Backup and email a file. My head is spinning! <elephant@squirrelgroup.com>
    Re: branch coverage testing (Randal L. Schwartz)
    Re: converting a binary file to ascii <anmcguire@my-deja.com>
    Re: converting a binary file to ascii <lr@hpl.hp.com>
    Re: creating a variable whose name is defined at runtim <juex@my-deja.com>
    Re: getting close, but not there yet! <lr@hpl.hp.com>
    Re: Getting value of a variable in different file <jdb@wcoil.com>
    Re: Newbie - Advise on getting a lock on a file (Jon Bell)
    Re: Perl: Day One, a Stupid Question frannyzoo@hotmail.com
    Re: Perl: Day One, a Stupid Question <godzilla@stomp.stomp.tokyo>
    Re: Perl: Day One, a Stupid Question <mikecook@cigarpool.com>
    Re: Problem assigning keys/values in hashes. <nospam.newton@gmx.li>
        Question: DBI or DF_file? (R.)
        Regex and end of line wierdness <menger@outblaze.com>
    Re: Regex and end of line wierdness <godzilla@stomp.stomp.tokyo>
    Re: Regex and end of line wierdness <elephant@squirrelgroup.com>
        Sort Help Needed (Ralph Freshour)
    Re: Sort Help Needed <uri@sysarch.com>
    Re: Sort Help Needed <godzilla@stomp.stomp.tokyo>
    Re: Sort Help Needed <juex@my-deja.com>
    Re: Sort Help Needed <uri@sysarch.com>
    Re: Strange behaviour with pos($text), m/.../g and for( <kistler@gmx.net>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 18 Oct 2000 15:49:27 +1100
From: Ian Boreham <ianb@ot.com.au>
Subject: Re: Accessing methods created on the fly
Message-Id: <39ED2BD6.76D30AD2@ot.com.au>

michaeljgardner@my-deja.com wrote:

>
> I've tried monkeying around with the @EXPORT and @EXPORT_OK arrays, and
> even PUSHing the names of the subroutines created on the fly into the
> arrays, but each time I get an error saying

These arrays are used when you "use" or "require" the module to determine
which names to import into the main:: namespace, so if you fiddle these
values later, it's not going to help. You would need to explicitly add them
to the global namespace yourself (in the manner suggested in Frank's reply.

Currently you are adding them to the current package only.

Regards,


Ian




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

Date: 18 Oct 2000 04:09:02 GMT
From: "Josiah" <jdb@wcoil.com>
Subject: Re: Anyone try to use perl to handle GB text?
Message-Id: <8sj7ou$qjf$0@206.230.71.67>

> chomp($text);
>
> I don't cut more than the newline symbol and destroy the text
>
> If I use regex:
>
> s/(.*)\n/$1/g

Hmmm, sounds like a problem I've had. Are you sure that $text ends in \n?
It might have some spurious whitespace or a \n\r at the end, in which case
chomp would leave the ending be, but the above regex would remove everything
after the \n character. If you're not sure, then perhapse a
    $text=~tr/\n//d;
would be more for you, as that JUST removes the \n, leaving in place
anything
surrounding it.

hth,

--
$from = <$josiah>;




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

Date: Wed, 18 Oct 2000 00:39:52 -0400
From: "John MacLeod" <john@macleodweb.com>
Subject: Backup and email a file. My head is spinning!
Message-Id: <8sj9110gut@enews3.newsguy.com>

My head is spinning! Could someone please help with this seemingly simple
task?

I want to set up a cron job to...

1. Backup a txt file (formresults.txt).
2. Email the formresults.txt file to an external email address
(client@hisdomain.com) each night at 3 am.

The file is located at...
/usr/www/users/myaccount/client/formresults.txt

Any help would be GREATLY appreciated.

Sincerely,
John MacLeod
john@macleodweb.com






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

Date: Tue, 17 Oct 2000 22:56:08 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Backup and email a file. My head is spinning!
Message-Id: <39ED3B78.E5B9D303@stomp.stomp.tokyo>

John MacLeod wrote:

> My head is spinning! Could someone please help with
> this seemingly simple task?
 
> I want to set up a cron job to...

(snipped) 

> Any help would be GREATLY appreciated.


Best help is self-help. Quit being so lazy
and run an internet search on "crontab" and
you will turn up dozens of sites like this,

http://www.neosoft.com/neosoft/man/crontab.5.html

Just a matter of adding your script to a cron job,
if your systems administrator will allow this.

In what way is setting up a crontab related
to your subject line?


Godzilla!
-- 
Dr. Kiralynne Schilitubi ¦ Cooling Fan Specialist
UofD: University of Duh! ¦ ENIAC Hard Wiring Pro
BumScrew, South of Egypt ¦ HTML Programming Class


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

Date: Wed, 18 Oct 2000 17:42:25 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: Backup and email a file. My head is spinning!
Message-Id: <MPG.1457ff695679f0c1989828@localhost>

John MacLeod wrote ..
>My head is spinning! Could someone please help with this seemingly simple
>task?
>
>I want to set up a cron job to...
>
>1. Backup a txt file (formresults.txt).
>2. Email the formresults.txt file to an external email address
>(client@hisdomain.com) each night at 3 am.
>
>The file is located at...
>/usr/www/users/myaccount/client/formresults.txt
>
>Any help would be GREATLY appreciated.

  man crontab

or did you actually have a Perl question ?

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: 17 Oct 2000 23:21:22 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: branch coverage testing
Message-Id: <m1u2aawty5.fsf@halfdome.holdit.com>

>>>>> "Michael" == Michael Carman <mjcarman@home.com> writes:

Michael> Matt Leinhos wrote:
>> 
>> Could anyone tell me if there is a branch coverage test program/script
>> for perl? I am interesting in testing all the branches of a perl 
>> script I've been working on.

Michael> Not that I'm aware of. I'd like one too, but I have a bad feeling that
Michael> Perl's syntax is a bit too flexible to make such a thing feasible.

That's why you hook into it after the parser, using the debugger
hooks, as Devel::Coverage and Devel::DProf have already done.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Wed, 18 Oct 2000 04:49:30 GMT
From: Andrew N McGuire <anmcguire@my-deja.com>
Subject: Re: converting a binary file to ascii
Message-Id: <8sja4p$15c$1@nnrp1.deja.com>

In article <MPG.14563a55a552ed7298ae3d@nntp.hpl.hp.com>,
  Larry Rosler <lr@hpl.hp.com> wrote:
> In article <Pine.LNX.4.21.0010171239030.26081-
> 100000@hawk.ce.mediaone.net> on Tue, 17 Oct 2000 12:43:51 -0500,
Andrew
> N. McGuire  <anmcguire@ce.mediaone.net> says...
> > On Tue, 17 Oct 2000, Paul Spitalny quoth:
> >
> > PS> I have a binary file, how can I convert it to ascii? I think I
need to
> > PS> read in the file byte by byte but can't figure out how to do it.
Any
> > PS> help appreceated!
> >
> > use PSI::ESP;
> >
> > perldoc -f read
> > perldoc -f pack
> > perldoc -f seek
> > perldoc -f unpack
> >
> > and probably others,
>
> Indeed.  Possibly the most important:
>
>   perldoc -f binmode

Indeed, I have been trying to pretend certain OS'es that distiguish
binary files from text files do not exist.  Darn^H^H^H^HThank you
for the reminder. :-)

anm
--
$ENV{PAGER} = 'perl -wpe0';
system perldoc => '-t', '-F', $0;

=head1 Just Another Perl Hacker


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


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

Date: Tue, 17 Oct 2000 23:25:21 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: converting a binary file to ascii
Message-Id: <MPG.1456e2279e655f5498ae42@nntp.hpl.hp.com>

In article <39ECE20B.437EB4BC@pauls.seanet.com>, 
pauls_spam_no@pauls.seanet.com says...

 ...

> See how the last number on the right column is screwed-up, but
> everything before that looks fine?? What gives?? Here's how I did it,
> perhaps you folks can find the error in my ways (I know, I know, i
> didn't check if the file exists before opening it)
> 
> open(NEW,'<bin_only.dat');
> open(OUT,'>thebin.dat');
> binmode NEW;
> $index = 0;
> while (read(NEW,$in,8))
>  {
>  $index++;
>  $foo = unpack("d",$in);
>  print OUT "$foo\n";
>  }
> close(NEW);
> close(OUT);

The only thing that comes to mind is that you read fewer than 8 bytes 
the last time through the loop.

Check the size of the input file for divisibility by 8, and check the 
number of bytes read to be 8 instead of the simple Boolean test in your 
code.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Tue, 17 Oct 2000 22:40:42 -0700
From: "Jürgen Exner" <juex@my-deja.com>
Subject: Re: creating a variable whose name is defined at runtime?!?
Message-Id: <39ed37e4@news.microsoft.com>

"Ralf Siedow" <replynews@bigfoot.com> wrote in message
news:8rsrfg$iglrf$1@ID-23826.news.cis.dfn.de...
> I want to create a variable whose name I actually don't know.
> lets say $var = "test" contains the name of the variable. How can I create
> the variable $test and how can I set a value or get one from it?

In 99.99% of all cases you don't want to. Use hashes instead, they are less
error prone and far easier to manage (btw: this is a FAQ).
If you have to for some very odd, irregular reason then you may want to have
a look at "eval".

jue




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

Date: Tue, 17 Oct 2000 23:34:56 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: getting close, but not there yet!
Message-Id: <MPG.1456e4669f85579498ae43@nntp.hpl.hp.com>

In article <39ED1908.DCCD7A8C@rochester.rr.com>, 
bwalton@rochester.rr.com says...

 ...

> Paul, I think you will need to review the tiny details of the double
> floating format of both of your machines.  Your NT machine (if it is a
> PC -- I don't know about Alpha's) will use the IEEE standard floating
> point representation. I have no idea what format your Unix machine uses
> -- that depends upon the platform, and could be almost anything.  Some
> platforms support more than one floating point format.  Your format is
> probably very close to IEEE, but not exactly the same.  Generally, you
> can't depend on binary floating point representations to be the same,
> even with endianness fixed.  If you don't go from the documentation, you
> will never know if there is another problem with the transfer you just
> didn't encounter yet.  HTH.

I find it hard to imagine that any machine designed in the past decade 
uses other than IEEE Standard floating-point representations.  Can 
anyone point to such a machine?

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 18 Oct 2000 04:26:27 GMT
From: "Josiah" <jdb@wcoil.com>
Subject: Re: Getting value of a variable in different file
Message-Id: <8sj8pj$sov$0@206.230.71.67>

Andrew Watts <deward@purdue.edu> wrote in message
news:8sj745$eoh$1@mozo.cc.purdue.edu...

<snip>
> I want to use another file for my HTML because of length and the
complexity
> of the code. (It will just make the code a lot nicer to read.) Then read
the
> file and output its contents to the client.  But I need to be able to
insert
> these values in the middle of the output stream to the client.  My thought
> was to put keys in the HTML file and then parse the input stream, look for
> the key, and switch the key with the value.  Assuming the key is of the
> following form: $input{'fieldValue1'}.  The code may look something like
> this:
<snip>

I would HIGHLY recomend the standard HTML::Template module. Consider:

__HTML__

<html>
<head><title>My Test</title>
<body>
<h1>My HTML Test</h1>
<p>filedValue1: <strong><tmpl_var name="fieldValue1"></strong></p>
</body>
</html>

__CODE__

use HTML::Template;

my $t = HTML::Template->new(filename => 'mytemplate.ht');

$t->param(    fildValue1  => $input{'fieldValue1'}    );

print "Content-type: text/html\n\n", $t->output;

__END__

In approx 3 lines of Perl code we loaded the template, replaced the
variable in the template with our value, and printed the right headers
and the compiled template to STDIO, assuming its going to the browser.

Much cleaner looking that all those sloppy regexes, eh? And the
HTML is much easier to use.

HTML::Template provides some very useful template constructs for
most common template tasks. Very simple to use and integrate. I
agree, there are larger tasks where other template systems would
suite you better, but I have found that for most HTML-substitution with
Perl, HTML::Template works VERY well.

hth,

--
$from = <$josiah>;




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

Date: Wed, 18 Oct 2000 06:19:22 GMT
From: jtbell@presby.edu (Jon Bell)
Subject: Re: Newbie - Advise on getting a lock on a file
Message-Id: <G2M48A.8FG@presby.edu>

In article <8site1$2vu$1@bertrand.ccs.carleton.ca>,
Robert Young <rjyoung@chat.carleton.ca> wrote:
> [...] I figured that since multiple instances or threads of this
>script could be running at once (ie multiple people hitting submit at once,)
>that I should get the script to create a temporary lock file, and deletes it
>when it finishes writing to the main file.

Is there some reason why you can't use the 'flock' function that is built
into Perl?  If you don't know about 'flock', give the command 'perldoc -f
flock' at your command prompt if you have Perl installed on your
computer; otherwise look through the online docs at http://www.perl.com/ .

-- 
Jon Bell <jtbell@presby.edu>                        Presbyterian College
Dept. of Physics and Computer Science        Clinton, South Carolina USA
[ Questions about newsgroups?  Visit http://www.geocities.com/nnqweb/  ]
[                or ask in news:news.newusers.questions                ]


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

Date: Wed, 18 Oct 2000 04:15:45 GMT
From: frannyzoo@hotmail.com
Subject: Re: Perl: Day One, a Stupid Question
Message-Id: <8sj85e$vot$1@nnrp1.deja.com>

Thanks guys...very helpful group here.  I tried the command line with
the total package c:\perl\bin\perl -v and voila...instead of just perl -
v as initially suggested by this free online course at:

http://www.free-ed.net/fr03/lfc/course%20030207_01/index.html

I'm sure it's just one of those things ya gotta know to know..the first
of what I'm sure will be millions of such circumstances as I move from
medium novice html hack to "perl programming genius"..I mean hell, I
don't even get the jokes yet.

and speaking of ya gotta know...is there any way to slow perl scripts
when they do run?  The perl -v just flies by and it's gone, e.g.

thanks again for the help.

scot


In article <39ECB688.E2390702@vpservices.com>,
  Jeff Zucker <jeff@vpservices.com> wrote:
> frannyzoo@hotmail.com wrote:
> >
>
> The answer is on page 17 of _The Way of the Pilgrim...> time, try
this:
>
> 1. Select Start menu - Run
> 2. Type "command" (without the quotes), press enter
> 3. Type "c:\perl\bin\perl -v" (without the quotes), press enter
>
> If you installed Perl from activestate (which you should have) and
kept
> the default directory structure, that should work.  If not, change the
> directory path in #3 to whatever you selected as the alternate
directory
> to install perl in.
>
> --
> Jeff
>


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


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

Date: Tue, 17 Oct 2000 22:31:17 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Perl: Day One, a Stupid Question
Message-Id: <39ED35A5.E366C837@stomp.stomp.tokyo>

frannyzoo@hotmail.com wrote:

> ...is there any way to slow perl scripts when 
> they do run?  The perl -v  just flies by and
> it's gone

If you are working from a DOS prompt, add
a page switch at the end of your command
entry line,

your command garbage /p

Use of a page switch /p will display one screen
full at at time with a prompt to strike any key
when ready. If this doesn't work with your Perl
install, remove all traces of Perl from your
machine and never install Perl again; it isn't
fit to have on your system.

Personally, I don't believe Win 32 Perl is fit
to be installed any DOS/Win machine and, Perl 
5.6 isn't fit to be installed on an Etch-A-Sketch.


Godzilla!
-- 
Dr. Kiralynne Schilitubi ¦ Cooling Fan Specialist
UofD: University of Duh! ¦ ENIAC Hard Wiring Pro
BumScrew, South of Egypt ¦ HTML Programming Class


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

Date: Tue, 17 Oct 2000 22:56:51 -0700
From: "Michael Cook" <mikecook@cigarpool.com>
Subject: Re: Perl: Day One, a Stupid Question
Message-Id: <eZaH5.1162$h77.582114@news.uswest.net>

In your control panel, set your Console settings to enlarge the buffer, then
you can scroll back,
    Michael
--
== CigarPool ==
http://www.cigarpool.com

<frannyzoo@hotmail.com> wrote in message news:8sj85e$vot$1@nnrp1.deja.com...
> Thanks guys...very helpful group here.  I tried the command line with
> the total package c:\perl\bin\perl -v and voila...instead of just perl -
> v as initially suggested by this free online course at:
>
> http://www.free-ed.net/fr03/lfc/course%20030207_01/index.html
>
> I'm sure it's just one of those things ya gotta know to know..the first
> of what I'm sure will be millions of such circumstances as I move from
> medium novice html hack to "perl programming genius"..I mean hell, I
> don't even get the jokes yet.
>
> and speaking of ya gotta know...is there any way to slow perl scripts
> when they do run?  The perl -v just flies by and it's gone, e.g.
>
> thanks again for the help.
>
> scot
>
>
> In article <39ECB688.E2390702@vpservices.com>,
>   Jeff Zucker <jeff@vpservices.com> wrote:
> > frannyzoo@hotmail.com wrote:
> > >
> >
> > The answer is on page 17 of _The Way of the Pilgrim...> time, try
> this:
> >
> > 1. Select Start menu - Run
> > 2. Type "command" (without the quotes), press enter
> > 3. Type "c:\perl\bin\perl -v" (without the quotes), press enter
> >
> > If you installed Perl from activestate (which you should have) and
> kept
> > the default directory structure, that should work.  If not, change the
> > directory path in #3 to whatever you selected as the alternate
> directory
> > to install perl in.
> >
> > --
> > Jeff
> >
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.




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

Date: Wed, 18 Oct 2000 06:31:56 +0200
From: "Philip 'Yes, that's my address' Newton" <nospam.newton@gmx.li>
Subject: Re: Problem assigning keys/values in hashes.
Message-Id: <p09qus076b3njbo05fq38f6ghrpeb6qqdc@4ax.com>

On Sun, 15 Oct 2000 18:14:15 -0700, Jeff Zucker <jeff@vpservices.com> wrote:

> 13_hellfish@my-deja.com wrote:
> > 
> > get_form_data(\%form);
> > ...
> > sub get_form_data {
> >         my $form = @_;
> 
> You are passing in a hashref, then reading an array into a scalar. 
> Change "@_" to "shift" or "$_[0]".

Or: my($form) = @_;

Cheers,
Philip


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

Date: Wed, 18 Oct 2000 05:07:45 GMT
From: maiwang@home.com (R.)
Subject: Question: DBI or DF_file?
Message-Id: <39ed2324.2569907@news.cgma1.ab.wave.home.com>

So, I've heard my options are DB_file, ADBM_file and database interfacing.
So far the plan is to have perl create and manage my DB.  The whole thing
will run on winbloze and will have a browser interface accessible on a LAN.

I've heard that DB_file and ADBM_file are a very bad thing with concurrent
sessions, which is likely to happen in this situation.  Corect me if I'm
wrong.

-What would happen with the abovementioned setup? If more than one human
attempts to access the same HTML page and therefore fires up perl to do a
search for them through the DB, then does this result in concurrent scripts
or return an error?
-Can I use a DB created by Access 7 and access from perl?  I gather this
would solve the concurrent session problem.

At 14, I programmed a BBS from scratch, and hacked ancient computer
hardware, but like holy cow I'm having some problems learning perl.  Seems
that every time I start off in a direction, I discover I have to first
learn about and install a module or some obscure MS product.  Can't just
program, like the old days.



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

Date: 18 Oct 2000 05:54:36 GMT
From: Matthew Enger <menger@outblaze.com>
Subject: Regex and end of line wierdness
Message-Id: <8sjdus$5ca$1@m5.att.net.hk>

Hello,
	I am trying to match an IP address using the following:

$ip = "202.77.181.194\n";

print CheckIP($ip);


sub CheckIP {

    my $ip = $_[0];

    if ($ip =~ /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/) {
        return 1;
    }
    else {
        return 0;
    }

}

	I have noticed that the value in $ip is getting through and this is returning 0. Should this be happening?

	from,
		Matthew Enger
		menger@outblaze.com


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

Date: Tue, 17 Oct 2000 23:21:13 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Regex and end of line wierdness
Message-Id: <39ED4159.EF6FDEF9@stomp.stomp.tokyo>

Matthew Enger wrote:


> I am trying to match an IP address using the following:

(snipped)
 
> I have noticed that the value in $ip is getting through
> and this is returning 0. Should this be happening?


Honestly and truly?


Godzilla!
-- 
Dr. Kiralynne Schilitubi ¦ Cooling Fan Specialist
UofD: University of Duh! ¦ ENIAC Hard Wiring Pro
BumScrew, South of Egypt ¦ HTML Programming Class


TEST SCRIPT:
____________


#!/usr/local/bin/perl

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

$ip = "202.77.181.194\n";

print CheckIP($ip);


sub CheckIP {

    my $ip = $_[0];

    if ($ip =~ /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/) {
        return 1;
    }
    else {
        return 0;
    }

}

exit;


PRINTED RESULTS:
_________________

1


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

Date: Wed, 18 Oct 2000 17:44:56 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: Regex and end of line wierdness
Message-Id: <MPG.145800082821a97b989829@localhost>

Matthew Enger wrote ..
>	I am trying to match an IP address using the following:
>
>$ip = "202.77.181.194\n";
>
>print CheckIP($ip);
>
>
>sub CheckIP {
>
>    my $ip = $_[0];
>
>    if ($ip =~ /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/) {
>        return 1;
>    }
>    else {
>        return 0;
>    }
>
>}
>
>  I have noticed that the value in $ip is getting through and this is
>returning 0. Should this be happening?

your code 'returns' 1 for me

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: 18 Oct 2000 04:58:04 GMT
From: ralph@primemail.com (Ralph Freshour)
Subject: Sort Help Needed
Message-Id: <39ed2f35.21531235@news.concentric.net>

I am having some trouble getting 2 sorts on some data.

I have a report that, in part, lools like this:

warrenh    10/17/2000 warren    hal
udontquit  10/17/2000 todd      gar
tim.glaze  10/17/2000 tim       gla
teamesteem 10/17/2000 andy      bee
ellenm     10/17/2000 ellen     mur
stetson    10/17/2000 jeffry    ste
scoping    10/17/2000 judy      bar
customcoat 10/17/2000 carl      pen
crusaderra 10/17/2000 j.e.      mac


What I am trying to do is to sort on the first col first, then sort on
the second col - but it is not working.

When I use the sortOnUsername only, that works.
When I use the sortOnDate only, that works - but when I try to use
them one after the other, then I only get the date sort and not the
users.

Can someone point me in the right direction please?

Here is a snippet of my perl code:

&sortOnUsername;
@array = reverse(&sortOnDate);
$~ = "HEADER";
write;
for ($i = 0; $i < @array; $i++)
    {
      @temp = split('~',$array[$i]);
      $~ = "BODY";
      write;
    }
print "\n\n";

sub sortOnUsername
{
  @array =
  map{$_->[0]}
  sort{$a->[1] cmp $b->[1]}
  map{[$_,(split('~'))[0]]}
  @array;
}

sub sortOnDate
{
  @array =
  map{$_->[0]}
  sort{$a->[1] cmp $b->[1]}
  map{[$_,(split('~'))[1]]}
  @array;
}



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

Date: Wed, 18 Oct 2000 05:25:38 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Sort Help Needed
Message-Id: <x7n1g2sotq.fsf@home.sysarch.com>

>>>>> "RF" == Ralph Freshour <ralph@primemail.com> writes:

  RF> warrenh    10/17/2000 warren    hal
  RF> udontquit  10/17/2000 todd      gar
  RF> tim.glaze  10/17/2000 tim       gla
  RF> teamesteem 10/17/2000 andy      bee
  RF> ellenm     10/17/2000 ellen     mur
  RF> stetson    10/17/2000 jeffry    ste
  RF> scoping    10/17/2000 judy      bar
  RF> customcoat 10/17/2000 carl      pen
  RF> crusaderra 10/17/2000 j.e.      mac


  RF> What I am trying to do is to sort on the first col first, then sort on
  RF> the second col - but it is not working.

  RF> When I use the sortOnUsername only, that works.
  RF> When I use the sortOnDate only, that works - but when I try to use
  RF> them one after the other, then I only get the date sort and not the
  RF> users.


you don't sort with twocolums by sort on one and then the other. you do
one sort pass with multiple key comparisons.

you seem to have a grasp of the ST so i will leave the coding to
you. but you need to extract both columns into one array and then
compare the primary key (column 1) and then if that comparison is equal,
then compare the second key.

the compare code would look like:

	$a->[0] cmp $b->[0]
		||
	$a->[1] cmp $b->[1]

but your dates don't sort properly as strings. either convert them to
year/month/date or do multiple compares. your code doesn't seem to
handle this issue.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Tue, 17 Oct 2000 22:45:19 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Sort Help Needed
Message-Id: <39ED38EF.4D1FE595@stomp.stomp.tokyo>

Ralph Freshour wrote:
 
> I am having some trouble getting 2 sorts on some data.
 
> I have a report that, in part, lools like this:
 
> warrenh    10/17/2000 warren    hal
> udontquit  10/17/2000 todd      gar
> tim.glaze  10/17/2000 tim       gla
> teamesteem 10/17/2000 andy      bee
> ellenm     10/17/2000 ellen     mur
> stetson    10/17/2000 jeffry    ste
> scoping    10/17/2000 judy      bar
> customcoat 10/17/2000 carl      pen
> crusaderra 10/17/2000 j.e.      mac
 
> What I am trying to do is to sort on the first col 
> first, then sort on the second col - but it is not
> working.
 
> When I use the sortOnUsername only, that works.
> When I use the sortOnDate only, that works 


"...that works..."

Really?

This is impossible. You cannot sort on dates.
Your dates are all the same. Even if you had
included another block of data, nine lines,
with 10/18/2000 as a date for each line, what
criteria would you use to sort by date with
all dates in each block, exactly the same?

$a <=> $a

Logical, yes?

Godzilla!
-- 
Dr. Kiralynne Schilitubi ¦ Cooling Fan Specialist
UofD: University of Duh! ¦ ENIAC Hard Wiring Pro
BumScrew, South of Egypt ¦ HTML Programming Class


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

Date: Tue, 17 Oct 2000 22:51:12 -0700
From: "Jürgen Exner" <juex@my-deja.com>
Subject: Re: Sort Help Needed
Message-Id: <39ed3a5a@news.microsoft.com>

"Uri Guttman" <uri@sysarch.com> wrote in message
news:x7n1g2sotq.fsf@home.sysarch.com...
> >>>>> "RF" == Ralph Freshour <ralph@primemail.com> writes:
>   RF> What I am trying to do is to sort on the first col first, then sort
on
>   RF> the second col - but it is not working.
>
>   RF> When I use the sortOnUsername only, that works.
>   RF> When I use the sortOnDate only, that works - but when I try to use
>   RF> them one after the other, then I only get the date sort and not the
>   RF> users.
> you don't sort with twocolums by sort on one and then the other. you do
> one sort pass with multiple key comparisons.

Actually sorting by the secondary sort relation first and then sorting the
result by the primary sort relation is a proven concept and is commonly used
provided the sort procedure is stable.
Unfortunately perl before version 5.6 uses a non-stable sorting algorithm,
therefore the idea of the OP failed (and of course it is a rather slow
solution because you sort twice).

jue




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

Date: Wed, 18 Oct 2000 06:04:02 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Sort Help Needed
Message-Id: <x7k8b6sn1q.fsf@home.sysarch.com>

>>>>> "JE" == Jürgen Exner <juex@my-deja.com> writes:

  JE> "Uri Guttman" <uri@sysarch.com> wrote in message
  JE> news:x7n1g2sotq.fsf@home.sysarch.com...
  >> >>>>> "RF" == Ralph Freshour <ralph@primemail.com> writes:
  RF> What I am trying to do is to sort on the first col first, then sort
  JE> on
  RF> the second col - but it is not working.
  >> 
  RF> When I use the sortOnUsername only, that works.
  RF> When I use the sortOnDate only, that works - but when I try to use
  RF> them one after the other, then I only get the date sort and not the
  RF> users.
  >> you don't sort with twocolums by sort on one and then the other. you do
  >> one sort pass with multiple key comparisons.

  JE> Actually sorting by the secondary sort relation first and then
  JE> sorting the result by the primary sort relation is a proven
  JE> concept and is commonly used provided the sort procedure is
  JE> stable.  Unfortunately perl before version 5.6 uses a non-stable
  JE> sorting algorithm, therefore the idea of the OP failed (and of
  JE> course it is a rather slow solution because you sort twice).

good point. and assuming a stable sort is not a good idea. in any case
the OP is not going to know what a stable sort is or how to use it for
his problem. the multiky compare is what he wants. 

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Wed, 18 Oct 2000 07:16:06 +0200
From: Per Kistler <kistler@gmx.net>
Subject: Re: Strange behaviour with pos($text), m/.../g and for(...)
Message-Id: <39ED3216.6B556027@gmx.net>

Volker Moell wrote:

> Ok, I see. But what I still didn't understand: Why is there a different
> behaviour of the three loops (for, foreach and while) in Perl5.6?

>     -volker

I don't know, but I also did not test it, because you did not give the 
exact code for what you tested (,concerning the looping structurers).
But anyhow, I would opt for clean code, so that possible implementation
changes of perl do not effect the outcome. 

Per.

-- 
Per Kistler, Zuerich, Switzerland
------------------------------------------------------------------------


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

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


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