[11611] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5211 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 24 00:07:33 1999

Date: Tue, 23 Mar 99 21:00:19 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 23 Mar 1999     Volume: 8 Number: 5211

Today's topics:
    Re: << string definer (Timothy Larson)
    Re: << string definer <uri@home.sysarch.com>
        [AJM] CGI.pm Cookie question (Murphy)
    Re: [AJM] CGI.pm Cookie question (Ronald J Kimball)
    Re: ANNOUNCE: Boston.pm Social Meeting, Thurs Mar 25 <elaine@cts.wustl.edu>
    Re: choping off whitespace (Steve Lamb)
    Re: cookie help (Alan Barclay)
    Re: cookie value is an array (Ronald J Kimball)
    Re: Crypt problems <matt@cartnetwork.com.spammenot>
    Re: Encryption Problem <webmaster@unicorn-soft.com>
        File Length And Truncating <davidrn@pobox.com>
    Re: flock() && win95  #HELP! (Randy Kobes)
        Gtk::Glade <dermot.musgrove@virgin.net>
    Re: How to watch socket connections? <naren@injersey.com>
    Re: Keeping place in a file (Ronald J Kimball)
    Re: My file keeps getting clobbered! (Ronald J Kimball)
    Re: newbie question (Tad McClellan)
    Re: Newbie Trying to install DateManip module on NT4.0 (Bob Trieger)
    Re: Perl Detecting Browser Version (Ethan H. Poole)
        re-sorting a sorted list (and sorting by date) nkaiser@my-dejanews.com
    Re: re-sorting a sorted list (and sorting by date) (Ronald J Kimball)
    Re: re-sorting a sorted list (and sorting by date) (Sam Holden)
    Re: rookie: "if" unexpected results (Tad McClellan)
    Re: String chopping dennis_marti@yahoo.com
        what is wrong w/ this sorting code? nkaiser@my-dejanews.com
        Win32 file size limitations? <a-jaredw@microsoft.com>
    Re: Win32 file size limitations? <elaine@cts.wustl.edu>
    Re: Win32 file size limitations? <elaine@cts.wustl.edu>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: 24 Mar 1999 02:37:10 GMT
From: larsot2@krypton.mankato.msus.edu (Timothy Larson)
Subject: Re: << string definer
Message-Id: <7d9j4m$h12$1@nitrogen.mankato.msus.edu>

In article <7d8blh$dv8$1@nitrogen.mankato.msus.edu>,
Timothy Larson <larsot2@krypton.mankato.msus.edu> wrote:
>In _Teach Yourself Perl in 21 Days_ I found a neat use of << to define
>multiline strings.  I tried it with Perl 5.004 on linux and it doesn't
>work.  OK, the book is an old one, so I was thinking maybe this use of
><< has been dropped.  Does anyone know?  I haven't found a mention of it
>so far.  I just thought it would be a convenient way to make my comment
>block into a string that could be shown to the user if something goes
>wrong.

OK, I realize I should have posted an example.  I thought maybe my whole
comment block was too big, so I shorted it up.  Here's the beginning of
my script

#!/usr/local/bin/perl -- -*-perl-*-

use Time::localtime;
use Time::Local;

$s = <<END
This is my string.
END
print "$s\n";

Pretty simple one, huh?  Well, here are the error messages.

syntax error at /home/tim/public_html/test.pl line 9, near "print"
  (Might be a runaway multi-line << string starting on line 6)
Execution of /home/tim/public_html/test.pl aborted due to compilation errors.
[Tue Mar 23 20:27:56 1999] [error] [client 207.177.29.91] Premature end of script headers: /home/tim/public_html/test.pl

So, any ideas why this simple thing should not work?

thanks,
Tim

PS  IIRC, the problem is always some error with the next line to be executed,
but I didn't get the "possible runaway" error until I shortened it up like
this.





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

Date: 23 Mar 1999 22:17:12 -0500
From: Uri Guttman <uri@home.sysarch.com>
Subject: Re: << string definer
Message-Id: <x74snbbmpz.fsf@home.sysarch.com>

>>>>> "TL" == Timothy Larson <larsot2@krypton.mankato.msus.edu> writes:

  TL> OK, I realize I should have posted an example.  I thought maybe my
  TL> whole comment block was too big, so I shorted it up.  Here's the
  TL> beginning of my script


  TL> $s = <<END
  TL> This is my string.
  TL> END

a question for you which might you solve the problem yourself:

is the above code a legal statement in perl?


if you can't solve the problem from that question, here are some others:

what is wrong with this statement?

$s = 'foo'


what makes a perl expression into a statement?


and finally,

where is its statement terminator?


hth,

uri


-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: Wed, 24 Mar 1999 06:14:27 GMT
From: jt45@tir.com (Murphy)
Subject: [AJM] CGI.pm Cookie question
Message-Id: <36fb826b.5468810@news.supernews.com>

I'm converting some JavaScript code to Perl, and it involves setting
cookies.  So I'm using CGI.pm and the following code doesn't do 
squat.  In fact it actually messes me up. 

Here's the code.
-------------
$cookie1=cookie(-name=>'name',-value=>$fname);
$cookie2=cookie(-name=>'nic',-value=>$nic);
print header(-cookie=>[$cookie1,$cookie2]);
-------------
Now according to the book, the above should store the cookie, but it
doesn't.   In fact, when I do this the following line of code does NOT
do what it's supposed to do:

Here it is:
--------------
print redirect('http://main/mainmenu.html');

Any help would be appreciated.




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

Date: Tue, 23 Mar 1999 23:42:45 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: [AJM] CGI.pm Cookie question
Message-Id: <1dp56et.xlr9ljlw5zn2N@[207.60.170.219]>

Murphy <jt45@tir.com> wrote:

> Here's the code.
> -------------
> $cookie1=cookie(-name=>'name',-value=>$fname);
> $cookie2=cookie(-name=>'nic',-value=>$nic);
> print header(-cookie=>[$cookie1,$cookie2]);
> -------------
> Now according to the book, the above should store the cookie, but it
> doesn't.   In fact, when I do this the following line of code does NOT
> do what it's supposed to do:
> 
> Here it is:
> --------------
> print redirect('http://main/mainmenu.html');

You're trying to print two sets of headers.  That won't work.  As the
documentation for CGI.pm's redirect() method states:

    GENERATING A REDIRECTION INSTRUCTION

       print $query->redirect('http://somewhere.else/in/movie/land');

    redirects the browser elsewhere.  If you use redirection like this,
    you should not print out a header as well.
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


The documentation is less explicit about this, but you can use the same
named parameters to redirect() that you can to header():


  print redirect(-uri=>'http://main/mainmenu.html',
                 -cookie=>[$cookie1,$cookie2]);


HTH!


-- 
 _ / '  _      /       - aka -
( /)//)//)(//)/(   Ronald J Kimball      rjk@linguist.dartmouth.edu
    /                                http://www.tiac.net/users/chipmunk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Tue, 23 Mar 1999 23:02:39 -0500
From: Elaine Ashton <elaine@cts.wustl.edu>
Subject: Re: ANNOUNCE: Boston.pm Social Meeting, Thurs Mar 25
Message-Id: <36F863DF.90C9BBE5@cts.wustl.edu>

Ronald J Kimball wrote:

> In addition to the usual socializing, there will be a brainstorming
> session on ideas for the Boston Perl Mongers party at next month's
> O'Reilly Perl Tutorials.

This should be quite fun to ponder and plot but I am still left
wondering where ORAs support for the Monger YAPC conference is. Where is
the quid pro quo? Addison-Wesley is supporting YAPC. 

You know, I also had this wacky idea today to turn my rusting 16yo volvo
wagon into the "Perl Mobile" in time for YAPC...so..if you were a perl
mobile what would you look like? This could be a fun group thing to
paint it....:)

> Feel free to bring food or drink to share.  (But don't feel obligated!)

Indeed, I've not been grocery shopping for a month, though the
HappyFunDog still gets gourmet food :) 

>           "Let them wear hats!"

How many are you up to now ron? :)

e.


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

Date: 23 Mar 1999 20:00:20 +0800
From: morpheus@no-spam.calweb.com (Steve Lamb)
Subject: Re: choping off whitespace
Message-Id: <slrn7fgoqk.5i6.morpheus@teleute.rpglink.com>

On Mon, 22 Mar 1999 20:18:07 -0800, Larry Rosler <lr@hpl.hp.com> wrote:
>That works, and is almost right.  But why answer with a guess?  For such 
>a Frequently Asked Question, the definitive answer in in the Perl FAQ.  

    Because I didn't have my perl book handy so I wasn't absolutely sure on
the syntax as I don't use s/// all that often and, secondly, I don't read
the FAQ so I answered anyway.  :)

-- 
             Steve C. Lamb             | Opinions expressed by me are not my
    http://www.calweb.com/~morpheus    | employer's.  They hired me for my
             ICQ: 5107343              | skills and labor, not my opinions!
---------------------------------------+-------------------------------------


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

Date: 24 Mar 1999 03:33:48 GMT
From: gorilla@elaine.drink.com (Alan Barclay)
Subject: Re: cookie help
Message-Id: <922246423.920892@elaine.drink.com>

In article <7d8tjh$nnp$1@client2.news.psi.net>,
Abigail <abigail@fnx.com> wrote:
>Take 70 kg of butter and mix that with 70 kg of sugar and a cup of vanilla
>extract. Chop the $user into small parts and mix it in with the butter
>and sugar. Add 24 dozens of eggs. Mix till you have a uniform, airy
>substance. Quickly add 70 kg of flour and mix till no flour is visible.
>Add a pinch of salt.
>
>Have you oven preheated to 225 degrees. Oil or flour a baking tray.
>Make small to medium (1-2 cm across) balls of dough, and flatten them
>on the tray. Bake for 15 minutes.
>
>Do not serve to vegetarians.

On the available evidence, I'd say that users are vegetables, and thefore
these cookies are acceptable to vegetarians.


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

Date: Tue, 23 Mar 1999 23:42:46 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: cookie value is an array
Message-Id: <1dp579s.1crayzr1fkzpa8N@[207.60.170.219]>

<elvis@NOTGRACELANDclark.net> wrote:

> @arrayname = param ;
>     
> then try to write it to a cookie
> $cookie1 = cookie(
> -name           => 'MYCOOKIE',
> -value          => \@arrayname,
> -expires        => '+1h',
> ) ;
> print "Set-Cookie: $cookie1\n" ;
> 
> when I view the cookie contens in the webbrowser when the cookie is sent I
> only see
> 
> blah blah cookie to be set with name and value of
> 
> MYCOOKIE=age&income
> 
> if that was a hash I see
> 
> MYCOOKIE=age&value&income&value
> 
> Any ideas on what I am doing wrong?


CGI.pm:

    FETCHING THE NAMES OF ALL THE PARAMETERS PASSED TO YOUR SCRIPT:

        @names = $query->param

    If the script was invoked with a parameter list (e.g.
    "name1=value1&name2=value2&name3=value3"), the param() method will
    return the parameter names as a list.  If the script was invoked as
    an <ISINDEX> script, there will be a single parameter named
    'keywords'.


As documented, in a list context $query->param() returns only the
parameter names.  You have to use that list of names to build the hash
of names and values.


-- 
 _ / '  _      /       - aka -
( /)//)//)(//)/(   Ronald J Kimball      rjk@linguist.dartmouth.edu
    /                                http://www.tiac.net/users/chipmunk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Wed, 24 Mar 1999 02:01:17 GMT
From: "MMK" <matt@cartnetwork.com.spammenot>
Subject: Re: Crypt problems
Message-Id: <NHXJ2.7716$G26.685@tundra.ops.attcanada.net>

I use the following code and it works for me.  I just pasted this out of the
actual script.  I use the first two digits of the password as the salt....

else  {
        $new_salt = substr($newpass,0,2);
        $crypt = crypt($newpass,$new_salt);
        open(PASSO,">/usr/home/cartnet/site_confs/$node/HTPASS")
                or die "Password file error [>].\n";
        print PASSO "admin:$crypt";
        close(PASSO);
        &tell_status("<b>Password changed successfully.</b>");
}

Regards.

M

<jfreger@my-dejanews.com> wrote in message
news:7d6k8r$hmn$1@nnrp1.dejanews.com...
> When I try to use this method on a linux box, and then try to login to the
> htaccess protected directory (via a web browser) I get "access denied"
> because the passwords don't match. I've tried this using the salt provided
> below. Could that be the problem?
>





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

Date: Tue, 23 Mar 1999 21:06:28 -0600
From: "Tobias C. Wilhelm" <webmaster@unicorn-soft.com>
Subject: Re: Encryption Problem
Message-Id: <36F856B4.2AEA4CEE@unicorn-soft.com>

Because the Department of Commerce prohibits export of 128-bit
encryption software, and getting a licence takes between 1 and 3
months... :(

TCW
---
Jonathan Stowe wrote:
> 
> On Tue, 23 Mar 1999 03:08:33 -0600, "Tobias C. Wilhelm"
> <webmaster@unicorn-soft.com> wrote:
> 
> >I'm in the middle of setting up a store front for one of our customers
> >and it turns out that they can not use PGP since their offices are
> >located overseas.
> 
> Why does that stop them from using PGP ?
> 
> >                                   Is there any other options, such as 40-bit encryption
> >that work nicely in a CGI script and are easy to be decrypted using NC
> >or IE ???
> 
> I would ask on a crypto or CGI group - this isnt really a Perl
> Question.
> 
> /J\

-- 
****************************************
*          Tobias C. Wilhelm           *
*         CEO / Vice President         *
*      webmaster@unicorn-soft.com      *
****************************************
*  Unicorn Software Development Inc.   *
*                                      *
*          Visit Our Website           *
*     http://www.unicorn-soft.com      *
****************************************


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

Date: Tue, 23 Mar 1999 22:59:13 -0500
From: "David J Whalen-Robinson" <davidrn@pobox.com>
Subject: File Length And Truncating
Message-Id: <7d9o0u$l7q$1@winter.news.rcn.net>

I want to truncate a file to a shorter length WHILE it is open.
I think there is a way to do this but I forget how.
Does anybody know how to do this.
I totally understand seek and tell.
I know how to copy the file to a new file and leave off the part
I don't want at the end, but I want to just tell the OS to
"take back" the file size.

The file doesn't have to be open, but I would like to avoid having to
copy the whole file just to take the end off.

David
davidrn@pobox.com




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

Date: 24 Mar 1999 03:55:49 GMT
From: randy@theory.uwinnipeg.ca (Randy Kobes)
Subject: Re: flock() && win95  #HELP!
Message-Id: <slrn7fgp5k.28f.randy@theory.uwinnipeg.ca>

On Tue, 23 Mar 1999 17:23:51 -0600, John Cosby <lopex@Ibdhi.com> wrote:
>I'm new to perl and may be mussing it up, but am I correct in assuming
>that flock() is not available to win95 coders? I tried it in my code and
>tried the ex. in PerlFAQ5 and the error was fatal.  I'm thinking about
>renaming the file between * and *.lock to show a locked state. Has
>anyone tried this, and if so, how well did it work for you?

Hi,
   That's true that flock is unavailable on Windows 95/98.
You might want to try the LockFile::Simple module, available
under http://www.perl.com/CPAN/authors/id/RAM/, which does
locking similar to what you describe.

-- 
		Best regards,
		Randy Kobes

Physics Department		Phone: 	   (204) 786-9399
University of Winnipeg		Fax: 	   (204) 774-4134
Winnipeg, Manitoba R3B 2E9	e-mail:	   randy@theory.uwinnipeg.ca
Canada				http://theory.uwinnipeg.ca/


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

Date: Wed, 24 Mar 1999 04:32:21 +0000
From: Dermot Musgrove <dermot.musgrove@virgin.net>
Subject: Gtk::Glade
Message-Id: <36F86AD5.54B58CFA@virgin.net>

Hi, I am in the process of writing a module that uses
Perl::Gtk and XML::Parser to parse a Glade Gtk-Interface 
xml file and build the interface.

Has anyone been here before?

Regards, Dermot



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

Date: Tue, 23 Mar 1999 09:56:06 -0500
From: Narendra Ravi <naren@injersey.com>
To: Michael_Cameron@REMOVETHIS.technologist.com
Subject: Re: How to watch socket connections?
Message-Id: <36F7AB86.63091EFA@injersey.com>



I wrote:
> 
> Hi,
> 
> I'd appreciate any help in the following scenario.
> 
> Scenario: A TCP client
> 
> The client has some socket connections (typically 4) and a STDIN,
> STDOUT. I would like to be able to watch the socket connections
> and reconnect if the server I connect to closes a socket connection.
> 
> The usual behavior of the program is that after reading in a command
> on STDIN, I send the command to a socket (the command determines which
> socket). Then I read the socket until the end of the command response
> has been received. But sometimes, the response takes a few minutes,
> and that socket connection can be killed.
> 
> If this happens, I would like to close the concerned connection and
> try to re-establish the connection with the server.
> 
> How would I do this in Perl? My earlier solution involved C++ with a
> proprietary event-management library and a proprietary sessions level
> protocol. I'm trying to rewrite this in Perl to make it easier to
> maintain.
> 
> Please reply-to if this is not of general interest, or post otherwise.
> 
> Thank you,
> 
> -- Narendra Ravi               (naren@injersey.com)

I have solved one of the problems of watching socket connections.
However, there are other issues I still have to figure out. These
issues affect the solution, therefore may not be Perl how-to issues.

If anyone is interested, I would be happy to post a scaled down version
of the solution. However, I would then like a critique of the solution,
and possible ways of improving it.

Please email and if there is interest ( > 4 people interested), then
I will post.

Michael, thank you for the pointers.

-- Narendra Ravi               (naren@injersey.com)


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

Date: Tue, 23 Mar 1999 23:42:52 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Keeping place in a file
Message-Id: <1dp57jx.185c450dovhulN@[207.60.170.219]>

Gala Grant <gala@sonic.net> wrote:

> My question
> is, is there a way to return to the same place within the file after I test
> for the anchor tag?  I know about using seek to rewind the file to where I
> need to go, but how would I know exactly where I had been.  Actually, I
> would need to be right after the last thing I checked.

seek()'s partner is tell(), which tells you the current file position.

Refer to perlfunc for more info.


-- 
 _ / '  _      /       - aka -
( /)//)//)(//)/(   Ronald J Kimball      rjk@linguist.dartmouth.edu
    /                                http://www.tiac.net/users/chipmunk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Tue, 23 Mar 1999 23:42:59 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: My file keeps getting clobbered!
Message-Id: <1dp57oo.71jcg1begzemN@[207.60.170.219]>

<sstarre@my-dejanews.com> wrote:

> The mysterious part to me is that in the examples I've found, it uses a
> mysterious call to flock like:
> 
>   $r=flock(F, LOCK_EX);
> 
> instead of
> 
> $r=flock(F, $LOCK_EX);
> 
> I get an error when I try the first method.

use Fcntl qw(:flock);

The locking constants aren't exported by default; you have to ask for
them explicitly.

-- 
 _ / '  _      /       - aka -
( /)//)//)(//)/(   Ronald J Kimball      rjk@linguist.dartmouth.edu
    /                                http://www.tiac.net/users/chipmunk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Tue, 23 Mar 1999 16:35:58 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: newbie question
Message-Id: <uf19d7.i32.ln@magna.metronet.com>

Chen Li (erpeng@cs.auc.dk) wrote:

: How to append a line to a file? 


   By reading the FAQ, like everyone else does.


   Perl FAQ, part 5:

      "How do I change one line in a file/
       delete a line in a file/
       insert a line in the middle of a file/
       append to the beginning of a file?"


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Wed, 24 Mar 1999 03:47:59 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: Newbie Trying to install DateManip module on NT4.0
Message-Id: <7d9neq$b4a$2@oak.prod.itd.earthlink.net>

In article <7d91il$9nn$1@camel15.mindspring.com>, "yututiiyiyi" <yyigiyi@ghjgkg.com> wrote:
>Hello,
>            I am trying to install an available date manipulation module on
>my NT 4.0 system. Here are the steps I followed.
>
>1) Downloaded the file from CPAN:     DateManip_version.tar.gz
>2) Tried uncompressing it...using WinZip 7.0.
>     Winzip does notuncompress this file,
>
>.....struck at step 3.

You must have a real old version of Winzip. I have used Winzip to uncompress 
gzipped and tarred files for years.

Bob Trieger
sowmaster@juicepigs.com       



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

Date: Tue, 23 Mar 1999 21:37:13 -0500
From: ehpoole@ingress.com (Ethan H. Poole)
Subject: Re: Perl Detecting Browser Version
Message-Id: <VK3J58Zd#GA.143@rejz.ij.net>

[Posted and Emailed]  In article <36F830F9.84143BFA@corp.sgi.com>, 
davewal@corp.sgi.com says...
>
>Is there a way that PERL could detect the version of a users browser in
>a cgi script?
>If so, how?
>
>Or is this only capable with javascript?

This would be more appropriate as a CGI question in a CGI newsgroup...

but to answer the question: Yes, there is a way that Perl could detect the 
version of a user's browser, but it will never be particularly reliable, so 
don't do it.

-- 
Ethan H. Poole              | Website Design and Hosting,
                            | CGI Programming (Perl & C)..
========Personal=========== | ============================
* ehpoole @ ingress . com * | --Interact2Day, Inc.--
                            | http://www.interact2day.com/



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

Date: Wed, 24 Mar 1999 02:00:33 GMT
From: nkaiser@my-dejanews.com
Subject: re-sorting a sorted list (and sorting by date)
Message-Id: <7d9gvs$q7$1@nnrp1.dejanews.com>

I have an array made up of the following strings:
<date>,<number>

I need to first sort the array by number. This is not a problem, I got that
working (see example below). Then, I need to sort the array by date (but still
ordered by number). Similar to an "order by number,date" in SQL.
Here's what I have so far:

foreach $item (@unsortedarray) {
    $item=~/.+,(.+)/g;
    push @idx, $1;
  }
@sortedbynumber = @unsortedarray[ sort { $idx[$a] < $idx[$b] } 0 .. $#idx ];

Now, my question is, how do I sort @sortedbynumber by date (still keeping this
order).
Also, is there an easy way to sort dates?  They are just strings in standard
Unix format, ie 'Tue Mar 23 19:59:16 CST 1999'

Thanks for your help.

NK

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Tue, 23 Mar 1999 23:43:01 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: re-sorting a sorted list (and sorting by date)
Message-Id: <1dp57zw.1k0rk5m1cvixfwN@[207.60.170.219]>

<nkaiser@my-dejanews.com> wrote:

> I need to first sort the array by number. This is not a problem, I got that
> working (see example below). Then, I need to sort the array by date (but still
> ordered by number). Similar to an "order by number,date" in SQL.
> Here's what I have so far:
> 
> foreach $item (@unsortedarray) {
>     $item=~/.+,(.+)/g;
>     push @idx, $1;
>   }
> @sortedbynumber = @unsortedarray[ sort { $idx[$a] < $idx[$b] } 0 .. $#idx ];

That is not a valid sort function.  Sort functions must return -1, 0, or
1, indicating whether the $a is prior, $b is prior, or they have the
same priority.

sort { $idx[$a] <=> $idx[$b] } 0 .. $#idx


> Now, my question is, how do I sort @sortedbynumber by date (still keeping this
> order).

You actually want to do this in one sort, comparing the primary keys
first, and the secondary keys only if the primary keys match.

Something like the following:

sort { $date[$a] <=> $date[$b] ||
       $idx[$a] <=> $idx[$b]      } 0 .. $#idx


> Also, is there an easy way to sort dates?  They are just strings in standard
> Unix format, ie 'Tue Mar 23 19:59:16 CST 1999'


Convert the dates to numbers with the most significant unit first:

YYYYMMDDhhmmss
19990323195916


Then you can just do a simple numeric comparison.


-- 
#!/usr/bin/sh -- chipmunk (aka Ronald J Kimball)
      perl -e'for(sort keys%main::){print if $$_ eq 1}
            ' -s  -- -' Just' -' another ' -'Perl ' -'hacker 
' http://www.tiac.net/users/chipmunk/ [rjk@linguist.dartmouth.edu]


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

Date: 24 Mar 1999 04:57:11 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: re-sorting a sorted list (and sorting by date)
Message-Id: <slrn7fgs57.brn.sholden@pgrad.cs.usyd.edu.au>

Ronald J Kimball <rjk@linguist.dartmouth.edu> wrote:
><nkaiser@my-dejanews.com> wrote:
>
>> I need to first sort the array by number. This is not a problem, I got that
>> working (see example below). Then, I need to sort the array by date (but still
>> ordered by number). Similar to an "order by number,date" in SQL.
>> Here's what I have so far:
>> 
>> foreach $item (@unsortedarray) {
>>     $item=~/.+,(.+)/g;
>>     push @idx, $1;
>>   }
>> @sortedbynumber = @unsortedarray[ sort { $idx[$a] < $idx[$b] } 0 .. $#idx ];
>
>That is not a valid sort function.  Sort functions must return -1, 0, or
>1, indicating whether the $a is prior, $b is prior, or they have the
>same priority.
>
>sort { $idx[$a] <=> $idx[$b] } 0 .. $#idx

'perldoc -f sort' claims :

Sorts the LIST and returns the sorted list value.  If SUBNAME or BLOCK
is omitted, C<sort()>s in standard string comparison order.  If SUBNAME is
specified, it gives the name of a subroutine that returns an integer
less than, equal to, or greater than C<0>, depending on how the elements
of the array are to be ordered. 

The values do not have to be -1,0,1, they just have to be +ve, 0 or -ve.

But I guess I'm just being very picky...

-- 
Sam

So I did some research. On the Web, of course. Big mistake...
	--Larry Wall


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

Date: Tue, 23 Mar 1999 15:25:03 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: rookie: "if" unexpected results
Message-Id: <vat8d7.s12.ln@magna.metronet.com>

chadw7799@my-dejanews.com wrote:

: The following snippit is supposed to print only if the two item match. 
: Instead the innermost if statement prints every time it compares. 


   Because zero equals zero.


: What am I
: missing?


   You are using the numeric compare operator to compare strings.

   So perl converts your strings to numbers (likely zero),
   and then compares them.


   You should be using the -w switch on *all* of your perl
   programs.

   Perl's operators are described in the 'perlop.pod' document:

 ------------------------------
Binary "==" returns true if the left argument is numerically equal to
the right argument.

 ...

Binary "eq" returns true if the left argument is stringwise equal to
the right argument.
 ------------------------------


:       if ("$email" == "$e_m") {
            ^      ^    ^    ^
            ^      ^    ^    ^ those are unnecessary and misleading


   if ($email eq $e_m) {


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Wed, 24 Mar 1999 04:03:06 GMT
From: dennis_marti@yahoo.com
Subject: Re: String chopping
Message-Id: <7d9o5m$6or$1@nnrp1.dejanews.com>

In article <36F6B9DA.2303F27B@giss.nasa.gov>,
  jglascoe@giss.nasa.gov wrote:
> while (chomp(my $line = <FILE>)) {
>     my ($id, $delim, $rest) = ($line =~ m/^(\d+)(.)\s*(.*)$/);
>     # do something with "id", $delim", "$rest".
>
> I assume every line begins with a numeric id (no leading spaces).
> I'm also assuming the "string" part extends to the end of the line
> and has no embedded newlines.

You're also assuming that every line in the file ends with
a newline (or whatever $/ is set to). If the last line doesn't,
it won't get processed.

Dennis

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Wed, 24 Mar 1999 02:27:58 GMT
From: nkaiser@my-dejanews.com
Subject: what is wrong w/ this sorting code?
Message-Id: <7d9ij5$25d$1@nnrp1.dejanews.com>

I just realized the first sort in my earlier post isn't working:

I have an array made up of the following strings:
<string>,<number>

I'm trying to sort this array by the <number>

Here's what I have, which doesn't seem to work:
@unsortedarray=('x,5' , 'x,6' , 'x,6' , 'x,7' , 'x,9' , 'x,8' , 'x,8');

foreach $item (@unsortedarray) {
    $item=~/.+,(\d+)/g;
    push @idx, $1;
    print "DEBUG: $1,";
}
# the above DEBUG line correctly prints out 5,6,6,7,9,8,8

@sortedarray = @unsortedarray[ sort { $idx[$a] < $idx[$b] } 0 .. $#idx ];

foreach $item (@sortedarray) {
  print "DEBUG: $item\n";
}

This debug line INCORRECTLY prints "8,8,9,7,6,6,5"

So it is basically just returning the array in the opposite order.

I want it to print 5,6,6,7,8,8,9

Can someone tell me what I'm doing wrong??
Thanks alot,

Neal

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Tue, 23 Mar 1999 19:48:10 -0800
From: "Jared Westlund" <a-jaredw@microsoft.com>
Subject: Win32 file size limitations?
Message-Id: <eicFmkad#GA.78@upnetnews02.moswest.msn.net>

I'm using ActivePerl's Win32 port v.5.005 on an NTsvr machine.  I'm fairly
new to Perl, and I'm having a problem with file size limitations.

Here's what I'm doing:

- a batch file loops through a list of files...
- for each file, it executes my Perl script with the file parameter from the
batch and three other filenames.  <file1> <file2> <...>
- the script reads each line of <file1>, and depending on various criteria,
it outputs the line to file2,3, or 4.
- each time the script is run, it opens files 2-4 for appending.
- however, the script stops writing at about 9.5 gig -- it still continues
to execute, but it doesn't write to the output files.

The input files total 60 gigs collectively, and so should the output files
upon completion.  However, the output never exceeds 9.x gigs.

Is there a known filesize limitation within Perl for Win32?  Any help would
be appreciated.

Thanks!,

Jared




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

Date: Tue, 23 Mar 1999 23:07:29 -0500
From: Elaine Ashton <elaine@cts.wustl.edu>
Subject: Re: Win32 file size limitations?
Message-Id: <36F86501.F669825@cts.wustl.edu>

Jared Westlund wrote:

> - however, the script stops writing at about 9.5 gig -- it still continues
> to execute, but it doesn't write to the output files.

It could be any number of things....a 9GB is awfully awfully
big...smells like a memory problem though. Have you checked the
microsoft knowledgebase or the win32 FAQ? Have you checked the resources
on the system when it gets to this point? Have you tried breaking up the
input file and appending the existing files past this size?  just a few
places to look...

e.


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

Date: Tue, 23 Mar 1999 23:41:55 -0500
From: Elaine Ashton <elaine@cts.wustl.edu>
Subject: Re: Win32 file size limitations?
Message-Id: <36F86D13.284C2B49@cts.wustl.edu>

So I was curious, knowing the Solaris filesystem limitations but not NT
I went hunting for NTFS file size limits on the ms kb and (darn that is
soooo slow) found this, which may be a likely culprit
http://support.microsoft.com/servicedesks/technet/ or see section 8.11
in the FAQ "8.11. Reading from and writing to files mysteriously fails.
What's wrong?" ...I could not find anything indicating a file size
limitation for NTFS on the MS KB ...FAT I think is 4GB as you couldn't
make partitions any bigger IIRC. If there is such a thing it would be a
good addition to the FAQ even though it really isn't a Perl problem.

e.


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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 5211
**************************************

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