[26225] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8410 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 12 21:05:20 2005

Date: Mon, 12 Sep 2005 18:05:03 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 12 Sep 2005     Volume: 10 Number: 8410

Today's topics:
    Re: Can a Perl Programmer Pick up PHP quickly? nospam@geniegate.com
    Re: Perldoc security issues <spam-block-@-SEE-MY-SIG.com>
    Re: sorting data - hash vs. list <Fred@fred.net>
    Re: sorting data - hash vs. list <Fred@fred.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 13 Sep 2005 00:05:16 GMT
From: nospam@geniegate.com
Subject: Re: Can a Perl Programmer Pick up PHP quickly?
Message-Id: <Lucy11265629183880x8e3b08@air.tunestar.net>

In: <Xns96CF57E75B6AFcastleamber@130.133.1.4>, John Bokma <john@castleamber.com> wrote:
>nospam@geniegate.com wrote:
> 
>> Used to be you'd call a sub like this &subroutine() which is how I
>> learned it. 
>
>Then you didn't learn enough. You still set register globals to on?

No. My point is, a lot of the perl docs from days gone by document
perl subs as having a '&'. Now they don't. 

>> The whole 'more than one way to do it' is nice, but it does make perl
>> harder to learn. 
>
>Nonsense. PHP is not easier compared to Perl. If you do serious things 
>in PHP you have to learn a lot. The thing is, most people use PHP for 
>small toy thingies.

To design _software_ you need to learn a lot. 

To learn a language and JUST the language, PHP is easier. Sounds like
you're talking about software design. 

I suppose it's rather like any human language, learning english
doesn't mean it's easy to describe the components and interactions 
of a complex system.  

>It's not. I am an experienced Perl coder, and it's not a simple matter 
>to do PHP. To process a form and put a few things in a database, yes. To 
>write a serious big application no.

One would hope not. Again, designing software regardless of the language
is difficult. I think this is perhaps the real issue.

>> Seems to me, PHP5 is looking up toward 'java'. Has interfaces and all
>> that jazz. (still no inner classes though) 
>
>It's not even close to Java of 1995.

Yea, I'd agree. PHP hasn't gotten that slow yet! :-)

>> Naturally, a language with fewer features is going to be easier to
>> learn. (and probably parse much faster too)
>
>If there was an easy to learn programming language it would have been in 
>use for over 50 years by now. So why isn't there such a language? 
>Remember Java? Easier and "smarter" then C++. No more memory leaks 
>(sure), write once, run everywhere (sure). And have a peek at Java now.

Probably because easy languages, as you point out are really not that good.

BASIC has been around for quite some time, as has REXX. Sure, they're easy
(well, if you believe there are easy languages, they're easy) but they're 
very difficult to do any real work in, which is why you don't often see
REXX being used to write video games. 
 
Jamie
-- 
http://www.geniegate.com                    Custom web programming
guhzo_42@lnubb.pbz (rot13)                User Management Solutions


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

Date: Tue, 13 Sep 2005 01:12:50 +0100
From: James Taylor <spam-block-@-SEE-MY-SIG.com>
Subject: Re: Perldoc security issues
Message-Id: <ant130050e61fNdQ@riscpc.jtnet>

In article <Xns96CF585C89187castleamber@130.133.1.4>,
John Bokma <john@castleamber.com> wrote:
> 
> James Taylor <spam-block-@-SEE-MY-SIG.com> wrote:
> > 
> > Of course, there are shell related security issues too. Those
> > that come to mind are semicolons, pipes, and i/o redirectors.
> > I therefore remove most punctuation characters from the user
> > input before passing it to the shell with a tr:
> > 
> >     $query =~ tr/- _A-Za-z0-9:"'//cd;
> 
> Technically you should write down each and every thing you are
> 100% sure that is allowed and reject everything that doesn't
> fall into this set.

Well, ideally I should just make it perfect, of course.
However, as time is limited and I'm a practical kind of guy,
I'm looking for a simple, minimally sufficient solution.

> With general regexps and friends you either overlook
> things or break things.

Yes, I agree that it would be inappropriate to try to parse and
validate full regex syntax, and quite disproportionate to the
size of the task at hand. Pragmatic compromise is the way to go.

> Never fix input, like you do above.

Never? What's the right way to tidy user input in this situation?
Obviously, as I'm not getting paid by the hour, I'd like a
lightweight solution; something I can knock up over lunch in a
few lines of code, not an over-engineered solution involving
multiple chunks of OPC.

> > I have left colons so people can look up modules, and quote marks
> > so people can quote phrases to look up in the FAQ.
> 
> But don't do that with a regexp. Use a parser.

Why use a sledgehammer when a nutcracker will do?

-- 
James Taylor, London, UK                              PGP key: 3FBE1BF9
To protect against spam, the address in the "From:" header is not valid.
In any case, you should reply to the group so that everyone can benefit.
If you must send me a private email, use james at oakseed demon co uk.



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

Date: Mon, 12 Sep 2005 18:19:13 -0500
From: "Fred@fred.net" <Fred@fred.net>
Subject: Re: sorting data - hash vs. list
Message-Id: <943ci15v4bgiof1gob4hrsihtf3m3ehege@4ax.com>

On Sun, 11 Sep 2005 18:38:06 -0400, "Matt Garrish" <matthew.garrish@sympatico.ca> wrote:

>
><Fred@fred.net> wrote in message 
>news:qf79i19v7kqklccnr86pqr56ck5rc6loio@4ax.com...
>>
>> I have posted here before and been flamed to death, so I guess I'm ready 
>> if it happens again. OTH -- I'd be
>> interested in any helpful critisims on my file delete sub. Plus the main 
>> question on how to sort that dang file.
>> Thanks,
>>
>
>I can imagine you get flamed, considering your post (adding the isbn of the 
>book is called overkill). Anyway, I'm not one to read through reams of other 
>people's code to nitpick, so I'll only suggest that you google on the term 
>"Schwartzian Transform". The results should explain how trivial the task of 
>sorting any data structure with perl can be. For example:
>
>#### Code
>
>use strict;
>use warnings;
>use Time::Local;
>
>my @data;
>
>while (my $line = <DATA>) {
>   my @parts = split(/\|/, $line);
>   my $date = timelocal(1, 1, 1, split('/', $parts[9]));
>   unshift @parts, $date;
>   push @data, \@parts;
>}
>
>foreach my $aref (sort { $a->[0] <=> $b->[0] } @data) {
>   print join('|', @{ $aref }[1..$#{$aref}]);
>}
>
>__DATA__
>|C|170|901|2|0000000000008|4|000008|5|09/05/05|6|
>|C|170|901|2|0000000000003|4|000008|5|09/06/06|6|
>|C|170|901|2|0000000000001|4|000008|5|09/05/06|6|
>|C|170|901|2|0000000000028|4|000008|5|09/06/05|6|
>
>
>
>
>#### Outputs
>
>|C|170|901|2|0000000000008|4|000008|5|09/05/05|6|
>|C|170|901|2|0000000000028|4|000008|5|09/06/05|6|
>|C|170|901|2|0000000000001|4|000008|5|09/05/06|6|
>|C|170|901|2|0000000000003|4|000008|5|09/06/06|6| 
>


Thank you for the example. I was able to work out a solution. It was like I could not see the forest for the trees. Of course, prepend the epoch sconds to the front of the list and sort the zero subscript.
Thank you again,

Fred


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

Date: Mon, 12 Sep 2005 18:32:46 -0500
From: "Fred@fred.net" <Fred@fred.net>
Subject: Re: sorting data - hash vs. list
Message-Id: <ub3ci1tmhbb7pl2s46304uneo3c3oe5uo4@4ax.com>

On Sun, 11 Sep 2005 22:30:59 GMT, "A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote:

>"Fred@fred.net" <Fred@fred.net> wrote in
>news:qf79i19v7kqklccnr86pqr56ck5rc6loio@4ax.com: 
>
>>|C|170|901|2|0000000000008|4|000008|5|09/05/05|6|BART'S HVYDTY
>>|PROPHYLACTIC|14|3.99|15|00006| 
>
>...
>
>> I need to sort, you guessed it, the date field |5|. 
>
>If the date field were formatted YYYYMMDD, you would not have to do any 
>extra work for sorting.
>
>At this point, the interpretation of 09/05/05 is very ambiguous. Which 
>of the following formats is it in?
>
>YYMMDD
>YYDDMM
>DDYYMM
>DDMMYY
>MMYYDD
>MMDDYY
MMDDYY
>
>> Regarding "recipe" 3.2 & 3.3 where you use timelocal() to convert back
>> and forth between epoch seconds and what a human thinks of time as and
>> that's no problem.
>
>That would probably not be necessary, but we would like to know the 
>format of your date field.
MMDDYY
>
>> wrote localtime().) My Problem: I have split each record into an array
>> only to realize I have a varying length record due to product
>> description, so a substr won't help. And at that rate I'd have to
>> "swap" all the subscripts at once to keep the dates with the records
>> they go with.
>
>I am really not sure what you are talking about here.
Me neither. I wasn't thinking clearly. I was thinking of cutting up a string ... a string that should always be a specified length, where character
postiion in the string is the key element to identifying and manipluating the data. Like a format file and a data file pair.
>
>> Back to the hash approach. I'd have to read the entire 18 Meg file
>> into memory to sort it. (Unless this concern exposes the limits of my
>> technical expertise in perl and programming at large in any case. And
>> that is a troubling prospect but one for which I can find no remedy.
>> So assuming I did that, could I then sort the filled hash and get the
>> results I am looking for from the Unix command `sort -d"|" -f5`  ? 
>
>If reading the whole file into memory bothers you, why not just use the 
>sort utility (good old DOS and XP have a sort utility as well)?
Trying to stick with perl.
> 
>> I don't have any code to post 
>
>I see a whole buncha code below.
It was what I thought might be a modest contribution.
>
>> But just so you'll know I am not a complete rookie I'll post some
>> recent work, 
>
>Which seems to be completely irrelevant to the issue at hand.
It is in the very specific context, yet in other more broadly scoped contexts it is apropos.
>
>I am a little baffled.
>
><irrelevant code snipped>
>
>> I have posted here before and been flamed to death, so I guess I'm
>> ready if it happens again. OTH -- I'd be interested in any helpful
>> critisims on my file delete sub. Plus the main question on how to sort
>> that dang file. Thanks,
>
>Well, the following is not a flame.
>
>Have you read the posting guidelines for this group? They contain 
>invaluable information on how to help yourself and help others help you.
Thanks, but no. I find them so restrictive. Why we can't we all just talk about perl. Without having to be so  rigid. 
I always wanted a: comp.lang.perl.discussion
>
>One of the tips in the guidelines is to post code. But, please, not just 
>any old code that is lying around: Post code that is relevant to your 
>problem so we can see what you need help with.
I had no code at that the point.
>
>Otherwise, this becomes a "write my code for me" service, and we are not 
>very interested in that.
Me neither. I know what you mean tho. OTH sometimes to illustrate a point, (a binary search) some posting of code is very welcome.
Indeed people mine this group for just such snippets as may increase thier knowledge of perl, and therefore thier expertise with it.
>
>On the other hand, searching the Google archives for this group may have 
>uncovered some useful threads.
>
>You might find
>
>http://search.cpan.org/~uri/Sort-Maker-0.04/Sort/Maker.pm
>http://search.cpan.org/~creamyg/Sort-External-0.10/lib/Sort/External.pm
>
>useful.
I don't like using modules that don't ship with Active State Perl.... if you don't have network/internet your screwed with ppm.

>
>Anyway, here is a naive sort sub which will require you to slurp the 
>file into an array of lines first. The code is completely tested for 
>lack of data to test it with (see the posting guidelines on this also).
>
>#!/usr/bin/perl
>
>print sort by_date <STDIN>;
>
># Assumes that the date is formatted MM/DD/YY
># No years before 2000
>
>sub by_date {
>   my($a_date, $b_date);
>   if($a =~ m!\|(\d\d)/(\d\d)/(\d\d)\|!) {
>      $a_date = "$3$1$2";
>   }
>   if($b =~ m!\|(\d\d)/(\d\d)/(\d\d)\|!) {
>      $b_date = "$3$1$2";
>   }
>   return $a_date cmp $b_date;
>}
>
>__END__
>
>
>
>
>Sinan
Thank you.


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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