[11391] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4992 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 26 16:17:38 1999

Date: Fri, 26 Feb 99 13:09:31 -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           Fri, 26 Feb 1999     Volume: 8 Number: 4992

Today's topics:
        Perl newbie--Backup routine with Perl??? <ralph@ivebeenhacked.com>
    Re: Perl newbie--Backup routine with Perl??? <jglascoe@giss.nasa.gov>
    Re: Perl newbie--Backup routine with Perl??? <elaine@cts.wustl.edu>
    Re: Perl newbie--Backup routine with Perl??? <ralph@ivebeenhacked.com>
    Re: Perl newbie--Backup routine with Perl??? (I R A Aggie)
    Re: Perl newbie--Backup routine with Perl??? <elaine@cts.wustl.edu>
    Re: Perl newbie--Backup routine with Perl??? (Steve Linberg)
    Re: Perl posts to newsgroups? <shawn@sorcerysoftware.com>
    Re: Perl posts to newsgroups? (Nicholas Carey)
    Re: Perl posts to newsgroups? (Greg Ward)
        Perl problem... efutch@nyct.net
        PERL PROGRAMMER (Adam Fishman)
        Perl Question: Newbie <pgangala@i2.com>
    Re: Perl Question: Newbie <jglascoe@giss.nasa.gov>
        Perl Script on UNIX loading data into a MS-SQL NT Serve <daniel_figueroa@hp.com>
        Perl script to bypass 401 for authorization (Curtiss Hammock)
        perl script <b.j.vanbergenhenegouwen@pharm.uu.nl>
        perl server error with sendmail andy_freeman@my-dejanews.com
        perl sort problem <Yibai.He@paradise.net.nz>
    Re: perl sort problem (Abigail)
    Re: perl sort problem <Arnold_Mueller@csi.com>
    Re: perl sort problem <theglauber@my-dejanews.com>
    Re: perl sort problem (Andrew M. Langmead)
        Perl to Copy File <mmelton@together.net>
    Re: Perl to Copy File <gellyfish@btinternet.com>
    Re: Perl to Copy File <jeffp@crusoe.net>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Wed, 24 Feb 1999 09:07:55 -0600
From: "Ralph Parcheebi" <ralph@ivebeenhacked.com>
Subject: Perl newbie--Backup routine with Perl???
Message-Id: <7b14vl$5cm$1@news4.wt.net>

I have no programming experience, but as I am studying (and passing tests)
for my MCSE I have realized that some coding experience would be quite
helpful.

Perl is the lang. that I will start with.

I've got all the online documentation and ActivePerl for W32.  I've also
done a variety of 'hello world' tests to learn about scalars and arrays.

QUESTION:
* As my first real project, is Perl useful for backing up data on a personal
computer?   I know I can write a batch file that will get various files, but
can I do this strictly with Perl?  NOT have Perl run XCOPY or any DOS
commands?
* Also, in the 'real world' would any of you professionals use Perl for such
a task?  Are there things I can do in backing up with Perl that are easier
or better than DOS or something else?

I'm not asking for anyone to write it for me, just give me a couple of the
commands that I can dig into to write it myself.

Thank you very much!
--r.p.




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

Date: Wed, 24 Feb 1999 12:01:47 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: Ralph Parcheebi <ralph@ivebeenhacked.com>
Subject: Re: Perl newbie--Backup routine with Perl???
Message-Id: <36D4307B.26742349@giss.nasa.gov>

[courtesy copy of post sent to Ralph]

Ralph Parcheebi wrote:
> 
> I have no programming experience, but as I am studying (and passing tests)
> for my MCSE I have realized that some coding experience would be quite
> helpful.
> 
> Perl is the lang. that I will start with.

brave man  ;)

No, seriously, Perl was my second language.  FORTRAN was my first.
FORTRAN taught me nothing.  Perl taught me *lots* like lexical scoping,
OOP, functional programming basics (first class functions, map/grep),
references...  Perl's biggest asset though, is that it's a real world
programming language.  whatever that means  ;)

> QUESTION:
<snip platform specific questions. I don't know.>

I dunno.  I'll let someone else answer these.  Let's assume momentarily
that you can do anything you'd ever want to do with Perl.

Now, IMO, your first task should be to go out and buy a good Perl book,
any O'Reilly book you feel comfy with.  I couldn't imagine learning
Perl, much less programming, through the man pages (online docs are
mainly for reference).  It kinda sucks that there's no good online
(read "free") Perl books.  But hey! these O'Reilly books are awesome!


> 
> I'm not asking for anyone to write it for me, just give me a couple of the
> commands that I can dig into to write it myself.
> 
> Thank you very much!
> --r.p.

--
	"'We promise, yes I promise!' said Gollum.  'I will serve
	 the master of the Precious.  Good master, good Smeagol,
	 *gollum*, *gollum*!'  Suddenly he began to weep and bite
	 at his ankle again."

	-- J.R.R.T.


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

Date: Wed, 24 Feb 1999 12:09:56 -0500
From: Elaine Ashton <elaine@cts.wustl.edu>
Subject: Re: Perl newbie--Backup routine with Perl???
Message-Id: <36D43264.5CC9AE83@cts.wustl.edu>

Ralph Parcheebi wrote:
> QUESTION:
> * As my first real project, is Perl useful for backing up data on a personal
> computer?   I know I can write a batch file that will get various files, but
> can I do this strictly with Perl?  NOT have Perl run XCOPY or any DOS
> commands?

Perl has many internal features, but for backups you will need to have
Perl execute the system specific command. 

> * Also, in the 'real world' would any of you professionals use Perl for such
> a task?  Are there things I can do in backing up with Perl that are easier
> or better than DOS or something else?

Well, that depends on your definition of 'real world'. In most corporate
situations it is preferred or more common to see commercial software for
such mission critical tasks such as backups, however, I still prefer the
domain-wide Perl script based backup solution that was used at the
university where I used to work as it was very robust and never failed.
So, yes, I would use Perl in a heartbeat as oppposed to something like
Legato. What you ultimately use will depend on your situation and what
is the most prudent choice. If you are only responsible for your
workstation then go ahead and use Perl with glee though IIRC you will
need some sort of backup software (i.e. commercial) for windoze.

Enjoy.

e.


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

Date: Wed, 24 Feb 1999 12:07:09 -0600
From: "Ralph Parcheebi" <ralph@ivebeenhacked.com>
Subject: Re: Perl newbie--Backup routine with Perl???
Message-Id: <7b1f4i$a69$1@news4.wt.net>

Dear Elaine,

Thank you for the answers!

Will I gain any real advantage to running a Perl script for backup over
running a DOS batch file?  I'll probably write it anyway, just for the
practice, but right now I am using a .bat file for my workstation--will I
find enough flexibility in Perl to prefer it for this task?  My thinking in
light of your answers, is that I will be able to more easily specify the
scattered files that I want to back-up with Perl than with DOS.  Sound
right?

--r.p.

Elaine Ashton wrote in message <36D43264.5CC9AE83@cts.wustl.edu>...
>Ralph Parcheebi wrote:
>> QUESTION:
>> * As my first real project, is Perl useful for backing up data on a
personal
>> computer?   I know I can write a batch file that will get various files,
but
>> can I do this strictly with Perl?  NOT have Perl run XCOPY or any DOS
>> commands?
>
>Perl has many internal features, but for backups you will need to have
>Perl execute the system specific command.
>
>> * Also, in the 'real world' would any of you professionals use Perl for
such
>




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

Date: 24 Feb 1999 18:47:55 GMT
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Perl newbie--Backup routine with Perl???
Message-Id: <slrn7d8ifm.bu5.fl_aggie@enso.coaps.fsu.edu>

On Wed, 24 Feb 1999 12:07:09 -0600, Ralph Parcheebi
<ralph@ivebeenhacked.com> wrote:

+ Will I gain any real advantage to running a Perl script for backup over
+ running a DOS batch file?  I'll probably write it anyway, just for the
+ practice, but right now I am using a .bat file for my workstation--will I
+ find enough flexibility in Perl to prefer it for this task?  My thinking in

Yes. I never got into dos batching so I don't know to what degree this
is possible, but in perl you can add error-handling and reporting routines
to make your program more robust and less prone to failure. I have
several FTP programs that have gone thru several iterations of testing,
debugging, and bullet-proofing. They're almost, but not quite, intelligent.

+ light of your answers, is that I will be able to more easily specify the
+ scattered files that I want to back-up with Perl than with DOS.  Sound
+ right?

File::Find is your friend. :)

James


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

Date: Wed, 24 Feb 1999 14:18:10 -0500
From: Elaine Ashton <elaine@cts.wustl.edu>
Subject: Re: Perl newbie--Backup routine with Perl???
Message-Id: <36D45072.1B877E39@cts.wustl.edu>

Ralph Parcheebi wrote:
> Will I gain any real advantage to running a Perl script for backup over
> running a DOS batch file?  I'll probably write it anyway, just for the
> practice, but right now I am using a .bat file for my workstation--will I
> find enough flexibility in Perl to prefer it for this task?  My thinking in
> light of your answers, is that I will be able to more easily specify the
> scattered files that I want to back-up with Perl than with DOS.  Sound
> right?

It's hard to say if there is any 'real advantage' as I am much more
entrenched in the UNIX world than the NT world but both will work just
fine. I think you will find Perl more of a toolkit as opposed to DOS and
will be able to do almost anything you wish. I have never found DOS to
be anything but frustrating :). Perl++ DOS-- 

Enjoy.

e.


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

Date: Wed, 24 Feb 1999 15:10:19 -0500
From: linberg@literacy.upenn.edu (Steve Linberg)
Subject: Re: Perl newbie--Backup routine with Perl???
Message-Id: <linberg-2402991510190001@ltl1.literacy.upenn.edu>

In article <7b14vl$5cm$1@news4.wt.net>, "Ralph Parcheebi"
<ralph@ivebeenhacked.com> wrote:

> * Also, in the 'real world' would any of you professionals use Perl for such
> a task?  Are there things I can do in backing up with Perl that are easier
> or better than DOS or something else?

I have a simple backup script in Perl that I use daily over and above the
system-wide backups - it basically just calls tar with a long list of
files and directories I need backed up, renames the archive to a
date-based format, and moves it into a backup directory.  Very handy and
simple, since I don't have to think about naming things - I just bang in
the command and it builds my nicely-named archive and files it away.

-- 
Steve Linberg, Systems Programmer &c.
National Center on Adult Literacy, University of Pennsylvania
email: <linberg@literacy.upenn.edu>
WWW: <http://www.literacyonline.org>


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

Date: Tue, 23 Feb 1999 21:59:44 -0500
From: shawn raymond <shawn@sorcerysoftware.com>
Subject: Re: Perl posts to newsgroups?
Message-Id: <36D36B20.71B55C6F@sorcerysoftware.com>

red? white? what's up? I see that this question may seem to be a touchy one. Do
you want validate what I am trying to do? Should I submit code to you and Tom for
approval? I am willing. Are you willing to show me where I need to make changes?

Shawn
greatmich.com

Jonathan Stowe wrote:

> On 19 Feb 1999 19:42:32 -0700 Tom Christiansen wrote:
> >  [courtesy cc of this posting sent to cited author via email]
> >
> > In comp.lang.perl.misc, shawn raymond <shawn@sorcerysoftware.com> writes:
> > :I know how to send mail thru Perl but can I send mail to newsgroups
> > :What would the code be?
> >
> > Well, I happen to do this very thing every hour, but I'm wearing a
> > white hat.  Are you?
> >
>
> He may or may not be but it appears that he is wearing a red uniform.
>
> /J\
> --
> Jonathan Stowe <jns@btinternet.com>
> Some of your questions answered:
> <URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
> Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>





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

Date: Wed, 24 Feb 1999 03:43:13 GMT
From: ncarey@harlequin.com (Nicholas Carey)
Subject: Re: Perl posts to newsgroups?
Message-Id: <36d374a7.93159806@newshost.harlequin.com>

On Tue, 23 Feb 1999 21:59:44 -0500, shawn raymond
<shawn@sorcerysoftware.com> wrote:

> red? white? what's up? I see that this question may seem to be a touchy
> one. Do you want validate what I am trying to do? Should I submit code
> to you and Tom for approval? I am willing. Are you willing to show me
> where I need to make changes?

Shawn, Shawn, Shawn...It's not the code that matters. the question is:
why do you feel a need to post to USENET (or to email for that matter)
via a perl program? You wouldn't possibly be considering construction
that engine of the devil, a spam engine, would you?

> Jonathan Stowe wrote:
> 
> > On 19 Feb 1999 19:42:32 -0700 Tom Christiansen wrote:
> > >  [courtesy cc of this posting sent to cited author via email]
> > >
> > > In comp.lang.perl.misc, shawn raymond <shawn@sorcerysoftware.com> writes:
> > > :I know how to send mail thru Perl but can I send mail to newsgroups
> > > :What would the code be?
> > >
> > > Well, I happen to do this very thing every hour, but I'm wearing a
> > > white hat.  Are you?
> > >
> >
> > He may or may not be but it appears that he is wearing a red uniform.



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

Date: 24 Feb 1999 18:58:19 GMT
From: gward@cnri.reston.va.us (Greg Ward)
Subject: Re: Perl posts to newsgroups?
Message-Id: <7b1i4b$4k7$4@news0-alterdial.uu.net>

On Tue, 23 Feb 1999 21:59:44 -0500, shawn raymond
<shawn@sorcerysoftware.com> wrote:

> red? white? what's up? I see that this question may seem to be a touchy
> one. Do you want validate what I am trying to do? Should I submit code
> to you and Tom for approval? I am willing. Are you willing to show me
> where I need to make changes?

White hat = good guy.  Spammers are evil, therefore wear black hats.
Red uniform = Ensign Expendable.  Any character in *Star Trek* who wears
a red uniform will be devoured, crunched, shot, flamed, or otherwise
killed within minutes of beaming down to any planet, no matter how
benign it appears.  The analogy to what happens to anyone posting a
message that *could* be interpreted as "I want to learn how to spam" is
unavoidable...

Hope this explains a little bit of the local culture... (and gee, I sure
hope I'm interpreting the previous posters' sly references correctly!)

        Greg
-- 
Greg Ward - software developer                    gward@cnri.reston.va.us
Corporation for National Research Initiatives    
1895 Preston White Drive                      voice: +1-703-620-8990 x287
Reston, Virginia, USA  20191-5434               fax: +1-703-620-0913


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

Date: Thu, 25 Feb 1999 22:53:26 GMT
From: efutch@nyct.net
Subject: Perl problem...
Message-Id: <7b4k91$ok5$1@nnrp1.dejanews.com>

I was wondering if anyone could help out with any information. I have a
pretty simple daemon written in Perl, whose code is mostly out of the book
Programming Perl (Nutshell).  There's nothing I can think of in the script
that causes my problem and I was wondering if it's really my script or Perl
itself.  I'm running Perl version 5.005_02 on FreeBSD 2.2.8.

perl -D crashes (signal 11) showing the following information:

EXECUTING...

perl in malloc(): warning: recursive call.
Out of memory!
perl in free(): warning: recursive call.
perl in free(): warning: recursive call.
perl in free(): warning: recursive call.
perl in free(): warning: recursive call.
perl in malloc(): warning: recursive call.
Out of memory!
perl in free(): warning: recursive call.
perl in free(): warning: recursive call.
perl in free(): warning: recursive call.
perl in free(): warning: recursive call.
perl in free(): warning: recursive call.
perl in free(): warning: recursive call.
perl in free(): warning: recursive call.
perl in free(): warning: recursive call.
perl in free(): warning: recursive call.
perl in free(): warning: recursive call.
perl in free(): warning: recursive call.
perl in free(): warning: recursive call.
perl in free(): warning: recursive call.
perl in free(): warning: recursive call.
perl in free(): warning: recursive call.
perl in free(): warning: recursive call.
perl in free(): warning: recursive call.
perl in free(): warning: recursive call.
perl in free(): warning: recursive call.
perl in free(): warning: recursive call.
perl in free(): warning: recursive call.
perl in malloc(): warning: recursive call.
Out of memory!

--
Eric Futch              New York Connect.Net, Ltd.
efutch@nyct.net         Technical Support Staff
http://www.nyct.net     (212) 293-2620
"Giving New York The Internet Access It Deserves"

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


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

Date: Sun, 21 Feb 1999 14:11:20 -0800
From: adam@netstores.com (Adam Fishman)
Subject: PERL PROGRAMMER
Message-Id: <adam-2102991411200001@coho.fishbone.com>

PERL PROGRAMMER/Technical Administrator

A Commercial Internet Service Provider providing Internet
Electronic-Commerce Websites for companies around the country is accepting
applications for the position of PERL PROGRAMMER/Technical Administrator.
Applicants must be self-motivated, talented and have at least 3 years
experience in computer programming.

Programming experience in C/Unix, CGI scripting, SHELL, AWK, SED and PERL.
Duties will include documentation, programming, and debugging. Flexible
hours. Part-Time. 

Please send a resume and samples of programming work to:

FCI.NET 
1462 W. 8th Ave. 
Eugene, OR 97402
FAX: 541-345-1257
OR 
EMAIL jobs@fci.net


   Experience/Skills:
   * Scripting (Perl/Shell.)
   * Software Debugging
   * BSDi UNIX, Linux, FreeBSD or Sun operating systems
   * system backups/maintenance scripts
   * ability to troubleshoot and solve problems creatively
   * self-motivated with a positive attitude
   * Reliable at completing projects in a timely manner
   * Knowledge of internetworking (e.g. TCP/IP, Routing, etc.)


  Not Required, But Helpful:
   * UNIX system administration
   * UNIX security
   * Web Application Development
   * Business Application Development
   * database programming/SQL


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

Date: Wed, 24 Feb 1999 13:14:16 -0600
From: Prem Gangalakunta <pgangala@i2.com>
Subject: Perl Question: Newbie
Message-Id: <36D44F88.8CA3867@i2.com>

Hello

In the following code, whatz the easiest way to make sure each element
in date_labels array is unique? i.e.no repeated date_labels.
(function 'exists' can be used only on hashes right?)

Thanks,
Prem

##################
while ($line = <DATAFILE>){
        chop($line);
        @fields = split /\s+/, $line;
 ...
        if ($#fields >= $idx_mem_size)
                {
                $HoH{$fields[$idx_os]} {$fields[$idx_date]} = $fields[$idx_duration];
                $date_labels[$no_days] = "$fields[$idx_date]";
                $no_days++;
                }
        }
 ...





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

Date: Wed, 24 Feb 1999 14:23:43 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: Prem Gangalakunta <pgangala@i2.com>
Subject: Re: Perl Question: Newbie
Message-Id: <36D451BF.C96965ED@giss.nasa.gov>

[courtesy copy of post sent to Prem]

Prem Gangalakunta wrote:
> 
> In the following code, whatz the easiest way to make sure each element
> in date_labels array is unique? i.e.no repeated date_labels.
> (function 'exists' can be used only on hashes right?)
> 
> ##################
> while ($line = <DATAFILE>){
>         chop($line);
>         @fields = split /\s+/, $line;
> ...
>         if ($#fields >= $idx_mem_size)
>                 {
>                 $HoH{$fields[$idx_os]} {$fields[$idx_date]} = $fields[$idx_duration];
>                 $date_labels[$no_days] = "$fields[$idx_date]";
					   ^^^^^^^^^^^^^^^^^^^^
spurious quotes.

how about introducing a new hash:

$date_label = $fields[$idx_date];
unless (exists $date_labels_seen{$date_label})
{
	push @date_labels, $date_label;
	$date_labels_seen{$date_label} = 1;
}

>                 $no_days++;

"push" is probably better than keeping track of the
list index yourself.  (I don't see you [re]setting
"no_days" to 0 each time through the while loop).

>                 }
>         }
> ...

	Jay Glascoe


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

Date: Thu, 25 Feb 1999 22:58:17 -0800
From: "Dan Figueroa" <daniel_figueroa@hp.com>
Subject: Perl Script on UNIX loading data into a MS-SQL NT Server
Message-Id: <7b5goq$1ui$1@ocean.cup.hp.com>

Today I'm loading data from our NT servers into a SQL server using a PERL
WIN32 module WIN32::ODBC.  What I have is UNIX servers that I need to load
similar data into the same MS-SQL server. How can I script perl to do a SQL
INSERT into the SQL database on NT?

Thanks,
daniel_figueroa@hp.com




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

Date: Mon, 22 Feb 1999 20:00:43 GMT
From: curtiss@desertisle.com (Curtiss Hammock)
Subject: Perl script to bypass 401 for authorization
Message-Id: <36d1b55e.11868269@nntp4.mindspring.com>

On my company's website, which runs on an Apache server through
Mindspring, we have a directory of Client's Only pages, and each is
password protected with an .htaccess file. We also have a page with a
form where the client inputs his user ID. This gets sent to a Perl CGI
script which, depending on the user ID sent, redirects the browser  to
the appropriate web page (we don't want a bunch of links so that the
clients can see each others' names). This gets the 401 back from the
server and the web browser pops up a user ID/password dialog.

What we *want* to do, if it's possible, is send the user ID and
password to a Perl CGI script which passes them on to the server,
bypassing the 401 altogether and dumping the user on the right page.

I've looked high and low on the web, and learned a lot about how basic
authentication works, but I have been unable to find out if I can do
this or not. Any help or pointers would be most appreciated.

Curtiss


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

Date: Wed, 24 Feb 1999 10:27:24 +0100
From: "berg" <b.j.vanbergenhenegouwen@pharm.uu.nl>
Subject: perl script
Message-Id: <7b0gjg$fua$1@news.accu.uu.nl>

Can anyone supply me, or point me into the direction of, a perl script (it
should be for win32 perl) that works similair as the PubCrawler.pl script.
except i dont want to have updates of PubMed records, but i want to align my
"uknown" sequence against genbank and genbank updates. This script should
'BLAST' my sequence daily against these databanks, until it finds a hit and
then report the hit back to me in a html-format.

is there such a script????

if there is..could someone mail it to me or point me into the direction of
its wereabouts?


thanxs

J





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

Date: Thu, 25 Feb 1999 16:07:39 GMT
From: andy_freeman@my-dejanews.com
Subject: perl server error with sendmail
Message-Id: <7b3sg3$1ja$1@nnrp1.dejanews.com>

when using sendmail with -t option, if an invalid email address is entered, ie
aaaa or bbbbb@c. I get a server error. With a valid email address, sendmail
works fine. Anyone have any ideas?

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


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

Date: Tue, 23 Feb 1999 23:14:55 +1300
From: Yibai He <Yibai.He@paradise.net.nz>
Subject: perl sort problem
Message-Id: <36D27F9F.D61FE9AC@paradise.net.nz>

Hi,

Does anyone know how to sort a file by a particular column? I need write
a program to process a log file, in which has a Unit_number column. But
how can I sort this file array by the Unit number? The log file like:

Start_time    End_time    Message    Unit_Number    Status ... ...
  xxx                xxxx        xxxx
1                    xxx
  xxx                xxxx        xxxx
2                    xxx
  xxx                xxxx        xxxx
3                    xxx
  xxx                xxxx        xxxx
1                    xxx

I start the file as:
my $filehd= new FileHandler("filename");
@fileArray=<$filehd>.
 .....
#Now I need sort the @fileArray by the Unit_Number, ANY IDEA???


Thanks Lot!
Yibai






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

Date: 23 Feb 1999 16:36:48 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: perl sort problem
Message-Id: <7aulf0$20b$4@client2.news.psi.net>

Yibai He (Yibai.He@paradise.net.nz) wrote on MMII September MCMXCIII in
<URL:news:36D27F9F.D61FE9AC@paradise.net.nz>:
--
-- Does anyone know how to sort a file by a particular column?


There's a CPAN module for that.



Abigail
-- 
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'


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

Date: Tue, 23 Feb 1999 15:59:02 +0100
From: "Arnold M|ller" <Arnold_Mueller@csi.com>
Subject: Re: perl sort problem
Message-Id: <Oi$pwyzX#GA.358@nih2naac.prod2.compuserve.com>

Read about 'sort' in the perlfunc - manual. It's very well explained there.
My tip: build your own comparrison operator (see manual about this) which
extracts the Unit_number via regular-expression, like:
if ($a=~/^\d+, \d+, \d+, (\d+)/) {
    $AUnitNo=$1;
    if ($b=~/^\d+, \d+, \d+, (\d+)/) {
        $BUnitNo=$1;
        return $AUnitNo <=> $BUnitNo;
    }
}

Hope it helps.

>Does anyone know how to sort a file by a particular column? I need write
>a program to process a log file, in which has a Unit_number column. But
>how can I sort this file array by the Unit number? The log file like:
>
>Start_time    End_time    Message    Unit_Number    Status ... ...
>  xxx                xxxx        xxxx
>I start the file as:
>my $filehd= new FileHandler("filename");
>@fileArray=<$filehd>.
>.....
>#Now I need sort the @fileArray by the Unit_Number, ANY IDEA???





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

Date: Wed, 24 Feb 1999 12:45:21 GMT
From: The Glauber <theglauber@my-dejanews.com>
Subject: Re: perl sort problem
Message-Id: <7b0s90$g4i$1@nnrp1.dejanews.com>

In article <36D27F9F.D61FE9AC@paradise.net.nz>,
  Yibai He <Yibai.He@paradise.net.nz> wrote:
> Hi,
>
> Does anyone know how to sort a file by a particular column? I need write
> a program to process a log file, in which has a Unit_number column. But
> how can I sort this file array by the Unit number? The log file like:
>
> Start_time    End_time    Message    Unit_Number    Status ... ...
>   xxx                xxxx        xxxx
> 1                    xxx
>   xxx                xxxx        xxxx
> 2                    xxx
>   xxx                xxxx        xxxx
> 3                    xxx
>   xxx                xxxx        xxxx
> 1                    xxx
>
> I start the file as:
> my $filehd= new FileHandler("filename");
> @fileArray=<$filehd>.
> .....
> #Now I need sort the @fileArray by the Unit_Number, ANY IDEA???


Yes, look up the documentation for the sort function perldoc -f sort You can
specify a subroutine to do your special sort. I could give more details, but
it's all there in the documentation.

Glauber


> Thanks Lot!
> Yibai
>
>

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


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

Date: Wed, 24 Feb 1999 14:59:37 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: perl sort problem
Message-Id: <F7nyzD.7G9@world.std.com>

"Arnold M|ller" <Arnold_Mueller@csi.com> writes:

>Read about 'sort' in the perlfunc - manual. It's very well explained there.
>My tip: build your own comparrison operator (see manual about this) which
>extracts the Unit_number via regular-expression, like:
>if ($a=~/^\d+, \d+, \d+, (\d+)/) {
>    $AUnitNo=$1;
>    if ($b=~/^\d+, \d+, \d+, (\d+)/) {
>        $BUnitNo=$1;
>        return $AUnitNo <=> $BUnitNo;
>    }
>}

Doing this much processing in a sort subroutine tends to make things
really slow. Each element is passed multiple times, so the larger the
list the greater the rate of decrease of speed.

You tend to be much better off with the suggestion in the FAQ: perform
some sort of computation to create an easily comparable piece of data,
saving it with some sort of connection to the original data, and when
sorting, perform the comparision on the easily sortable piece.

<URL:http://www.perl.com/CPAN/doc/manual/html/pod/perlfaq4.html#How_do_I_sort_an_array_by_anyth>


while(<>) {
  /^\d+, \d+, \d+, (\d+)/;
  $compare{$_} = $1;
  push @data, $_
}

@sorted = sort { $compare{$a} <=> $compare{$b} } @data;

Of course, in can be made a bit more compact with the Schwartizian
Transform, also described in the same FAQ entry, and the Sort::Fields
module <URL:http://reference.perl.com/module.cgi?Sort::Fields> that
was mentioned earlier is also appropriate for the original posters
problem.


-- 
Andrew Langmead


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

Date: Mon, 22 Feb 1999 15:11:10 -0500
From: "Matt Melton" <mmelton@together.net>
Subject: Perl to Copy File
Message-Id: <36d1b76e.0@news.together.net>

Does anyone know of a simple perl script (if it must use a lib, preferably
cgi-lib as opposed to cgi.pm) that when executed would created a copy of a
certain file in a predetermined directory (It would be able to overwrite the
file every time its executed)

Thanks,
Matt




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

Date: 23 Feb 1999 23:16:21 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Perl to Copy File
Message-Id: <7avcs5$li$1@gellyfish.btinternet.com>

On Mon, 22 Feb 1999 18:08:37 -0500 evil Japh wrote:
> 
> Why make a Perl program?  This is to be run off the web, then?  If so,
> File::Copy is a useful module for copying files.  It can be found on the
> CPAN.
> 

Actually File::Copy comes with all recent Perl distributions.

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Mon, 22 Feb 1999 18:08:37 -0500
From: evil Japh <jeffp@crusoe.net>
Subject: Re: Perl to Copy File
Message-Id: <Pine.GSO.3.96.990222180649.19973B-100000@crusoe.crusoe.net>

> Does anyone know of a simple perl script (if it must use a lib, preferably
> cgi-lib as opposed to cgi.pm) that when executed would created a copy of a
> certain file in a predetermined directory (It would be able to overwrite the
> file every time its executed)

Firstly, there is NO excuse NOT to use CGI.pm.  It is far superior to
cgi-lib.pl.

Secondly, this sounds like a simple command-line question.

In Unix:
	% cp file1 /path/to/dir
In DOS:
	C:\> copy file1 \path\to\dir

etc.

Why make a Perl program?  This is to be run off the web, then?  If so,
File::Copy is a useful module for copying files.  It can be found on the
CPAN.

-- 
Jeff Pinyan (jeffp@crusoe.net)
www.crusoe.net/~jeffp

Crusoe Communications, Inc.
973-882-1022
www.crusoe.net



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

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

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