[19019] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1214 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 28 21:05:31 2001

Date: Thu, 28 Jun 2001 18:05:09 -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: <993776709-v10-i1214@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 28 Jun 2001     Volume: 10 Number: 1214

Today's topics:
    Re: -e url (Eric Bohlman)
        ANN: Free SCC-CVS Version Control Interface <jussij@zeusedit.com>
    Re: converting shell "sort" command to perl.. <perler@yahoo.com>
    Re: converting shell "sort" command to perl.. <ren@tivoli.com>
    Re: converting shell "sort" command to perl.. <perler@yahoo.com>
    Re: Create unique file in dir? <ren@tivoli.com>
    Re: from linux to WinNT4 Ms Sql <subscriber@novastar.dtdns.net>
    Re: is there a way to look ahead/behind in a foreach (@ <nospam@cfl.rr.com>
    Re: is there a way to look ahead/behind in a foreach (@ <krahnj@acm.org>
    Re: New To Perl--Regex Question <ren@tivoli.com>
    Re: New To Perl--Regex Question <cshannon@data2design.com>
        Opening files on the Mac? (newbie) (Steve)
    Re: Opening files on the Mac? (newbie) (Jay Tilton)
    Re: Perl with MS Access <cshannon@data2design.com>
    Re: PostgreSQL/Perl error <cshannon@data2design.com>
    Re: Processing command line <ren@tivoli.com>
        pull out last line in a text file <Patrick_member@newsguy.com>
    Re: pull out last line in a text file <uri@sysarch.com>
    Re: pull out last line in a text file (Logan Shaw)
    Re: reading the first line off the file <bart.lateur@skynet.be>
    Re: Scanning a file in CGI (Eric Bohlman)
    Re: Split without delimiter? <ren@tivoli.com>
    Re: Split without delimiter? <bart.lateur@skynet.be>
        turbo perl <perler@yahoo.com>
    Re: turbo perl <djberg96@hotmail.com>
    Re: turbo perl <buggs-clpm@splashground.de>
    Re: turbo perl <perler@yahoo.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 29 Jun 2001 00:29:13 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: -e url
Message-Id: <9hgi4p$lkc$2@bob.news.rcn.net>

nobull@mail.com wrote:

> use LWP::Simple;
> if (head "http://www.domain.de/$var.html")

Note that some HTTP servers won't process HEAD requests (especially if the 
URL is for something dynamically generated), so if a HEAD request fails, 
you need to try a GET before assuming that the URL is invalid.



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

Date: Fri, 29 Jun 2001 08:39:07 +1000
From: Jussi Jumppanen <jussij@zeusedit.com>
Subject: ANN: Free SCC-CVS Version Control Interface
Message-Id: <3B3BB20B.7514@zeusedit.com>

Zeus SCC-CVS for Windows Version 1.10
=====================================

The Zeus SCC-CVS is new release of the "free of charge" SCC plug-in
for the Concurrent Versions System (CVS) version control system. The
installer for this package can be downloaded from the following web
page:

   http://www.zeusedit.com/archives/scccvs.html

The package also includes a HTML tutorial that explains how to setup
the Zeus SCC-CVS to work with local or remote CVS projects.

IMPORTANT NOTE!
===============

The Zeus SCC-CVS software package has been specifically
designed to work with the Zeus for Windows programmer's
editor:

   http://www.zeusedit.com

but since the Zeus SCC-CVS is a full implementation of the
Microsoft SCC interface, the software should in work with
any IDE that supports the SCC interface.

NOTE: This version has also only been tested and found to
      work with the Zeus and Codewrite editors.

Jussi Jumppanen
xidicone@iname.com




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

Date: Fri, 29 Jun 2001 00:34:13 +0200
From: Patrick Erler <perler@yahoo.com>
Subject: Re: converting shell "sort" command to perl..
Message-Id: <Xns90CF5CB58B40fuyyehcesyrdx@62.153.159.134>

Uri Guttman <uri@sysarch.com> wrote in
news:x7y9qc8jma.fsf@home.sysarch.com: 

>>>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:
> 
>  >> sort -k 4.9b
>  >> ,4.13n -k 4.5b,4.7M -k 4.2b,4.3n -k4.14b,4.15n -k 4.17b,4.18n -k 
>  >> 4.20b,4.21n 
>  
>   AS> I suppose you are best off using the sort command as is. 
>   Whatever it AS> does, it looks like a rather complex comparison
>   routine that would AS> take some effort to implement and more effort
>   to make fast (hi Uri). AS> Moreover, sort uses temp files to reduce
>   memory load when the file AS> gets big.  Apache logs do that.
> 
> i agree. if it works with the sort util, and it is has complex fields
> like that, stick with what works. the overhead of a fork is likely to
> be nothing compared to a sort of a large log file.
ah, ok, i think you're right... will do so.. :)





-- 
PAT


vcard/LDAP/PGP: http://dresden-online.com/perler/identity.html
PGP fingerprint: DAC6 2FDA 1ED7 AD55  BD1F 5142 3D5F 72BF
Yahoo-ID: perler - http://jpager.yahoo.com/jpager/messenger.html


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

Date: 28 Jun 2001 17:20:04 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: converting shell "sort" command to perl..
Message-Id: <m37kxwtffv.fsf@dhcp9-173.support.tivoli.com>

On Thu, 28 Jun 2001, perler@yahoo.com wrote:

> i have a small shell script which sorts log files for me.. from the
> usenet i got a sort command to do it once, i never tried to
> understand what it does (and i wasn't that interrested in it anyway)
> it just worked...
> 
> now i want to convert the script to perl, no big problem, but this
> command i just don't get converted:
> 
> sort -k 4.9b
> ,4.13n -k 4.5b,4.7M -k 4.2b,4.3n -k4.14b,4.15n -k 4.17b,4.18n -k 
> 4.20b,4.21n 
> 
> what it sorts is a simple apache log like this:
> 213.83.52.132 - - [28/Jun/2001:20:29:43 +0200] "GET / HTTP/1.0" 200 3392 
> "-" "check_http/1.32.2.6 (netsaint-plugins 1.2.9-4)"
> 
> 
> ok, i could call the shell but i really would like to do it in
> perl...

My first reaction was the same as Anno's and Uri's -- if that works
then it's probably not worth changing.

But then it occurred to me that this is probably just to sort by the
timestamp.  Delving into the sort command a bit revealed this to be
true.  It sorts:

  * numerically by the year 
  * monthically by the month
  * numerically by the day
  * numerically by the hour
  * numerically by the minute
  * numerically by the second

It probably also needs to be a stable sort because there are likely to
be multiple entries for the same second and preserving the original
order would probably be the right thing to do.  I assume sort command
uses a stable sort, but Perl prior to version ??? is not (though you
can fix this with an extra comparison).

Anyway, parsing the date into epoch seconds and then sorting is pretty
straight-forward.  Whether there's any advantage to that over leaving
the sort as is depends on additional factors (one of which is the size
of the file as Anno already observed).

-- 
Ren Maddox
ren@tivoli.com


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

Date: Fri, 29 Jun 2001 01:35:31 +0200
From: Patrick Erler <perler@yahoo.com>
Subject: Re: converting shell "sort" command to perl..
Message-Id: <Xns90CF102FFA57Efuyyehcesyrdx@62.153.159.134>

Ren Maddox <ren@tivoli.com> wrote in
news:m37kxwtffv.fsf@dhcp9-173.support.tivoli.com: 

> On Thu, 28 Jun 2001, perler@yahoo.com wrote:
> 
>> sort -k 4.9b
>> ,4.13n -k 4.5b,4.7M -k 4.2b,4.3n -k4.14b,4.15n -k 4.17b,4.18n -k 
>> 4.20b,4.21n 
>> 
>> what it sorts is a simple apache log like this:
>> 213.83.52.132 - - [28/Jun/2001:20:29:43 +0200] "GET / HTTP/1.0" 200
>> 3392 "-" "check_http/1.32.2.6 (netsaint-plugins 1.2.9-4)"
>> ok, i could call the shell but i really would like to do it in perl...
> But then it occurred to me that this is probably just to sort by the
> timestamp.  Delving into the sort command a bit revealed this to be
> true.  It sorts:
> 
>   * numerically by the year 
>   * monthically by the month
>   * numerically by the day
>   * numerically by the hour
>   * numerically by the minute
>   * numerically by the second
> 
> It probably also needs to be a stable sort because there are likely to
> be multiple entries for the same second and preserving the original
> order would probably be the right thing to do.  I assume sort command
> uses a stable sort, but Perl prior to version ??? is not (though you
> can fix this with an extra comparison).
> 
> Anyway, parsing the date into epoch seconds and then sorting is pretty
> straight-forward.  Whether there's any advantage to that over leaving
> the sort as is depends on additional factors (one of which is the size
> of the file as Anno already observed).
the file size is minor.. the sorting runs every hour right now and the 
files are usually not bigger then some 10kbytes...

but the problem /for me/ is what you describes above.. sorting makes my 
head spin.. ;)

i'll give it a try tommorow, i'm pedantic sometimes when it comes to 
choosing "the right" solution for a problem ;)

thanks for your comment...


-- 
PAT


vcard/LDAP/PGP: http://dresden-online.com/perler/identity.html
PGP fingerprint: DAC6 2FDA 1ED7 AD55  BD1F 5142 3D5F 72BF
Yahoo-ID: perler - http://jpager.yahoo.com/jpager/messenger.html


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

Date: 28 Jun 2001 17:24:11 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Create unique file in dir?
Message-Id: <m33d8ktf90.fsf@dhcp9-173.support.tivoli.com>

On Thu, 28 Jun 2001, cberry@cinenet.net wrote:

> Anybody have suggestions on how to create a unique file in a
> directory, possibly obtaining an open filehandle to it in the
> process?  (Obviously, I could open it as a separate step, but doing
> both in one process would be an optimization).  I don't care about
> the details of the name.  Obviously, race conditions between
> separate processes trying to do this must be avoided.  Any
> suggestions?

$ perldoc -q temp
Found in /usr/lib/perl5/5.6.0/pod/perlfaq5.pod
       How do I make a temporary file name?
 ...


is probably a good starting point.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Fri, 29 Jun 2001 01:13:00 +0300
From: "novastar" <subscriber@novastar.dtdns.net>
Subject: Re: from linux to WinNT4 Ms Sql
Message-Id: <9hga4c$kvo$1@usenet.otenet.gr>

Thank you.

"Joonas Timo Taavetti Kekoni" <jkekoni@cc.hut.fi> wrote in message
news:9hdi3h$ju6$1@nntp.hut.fi...
> novastar <subscriber@novastar.dtdns.net> wrote:
> : Can you tell me please what module do I have to use to connect and query
a
> : Microsoft SQL installed on a Windows NT4 box from a linux one ?
>
> Microsoft SQL server is normally queried from perl via ODBC.
> There is however no odbc drivers for MS SQL server outside
> win32. Therefore you need either ODBC-ODBC bridge
> like:
>
> http://www.easysoft.com/products/da_components/oob/main.phtml
>
> Or driver that talks directly SQL server protocol. Bea has
> one for java, but i don't know one for perl.
>
>
>
> --
> _-  Joonas Kekoni       OH2MTF     I                           -_
> _-internet: jkekoni@cc.hut.fi   I       DO NOT EAT.         -_
> _-slowmail: j{mer{ntaival 7a176 I                           -_
> _- 02150Espoo          I      It is a monitor      -_
> _- Finland/Europe      I                           -_




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

Date: Fri, 29 Jun 2001 00:07:07 GMT
From: tuxy <nospam@cfl.rr.com>
Subject: Re: is there a way to look ahead/behind in a foreach (@l)?
Message-Id: <3B3BC8B6.38AD5EE5@cfl.rr.com>

Thanks guys good ideas- my question was more general however, I was
wondering how to look ahead & behind, to say, any value in the array,
maybe $a[$current location + 20] or whatever. I think that from your
replies that foreach () isn't such a hot idea in these cases! Best to
use indices I guess, which I generally avoid.

However, Tony, your reply sent me scurrying for my Camel (not the
smoking variety) too look up @:: and $::. What the heck ARE those
thingies? I've use package names to qualify a var with ::, but I never
saw them used that way. 

Enlighten me please?

-WQ

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


"Tony L. Svanstrom" wrote:
> 
> tuxy <nospam@cfl.rr.com> wrote:
> 
> > I could peek ahead or behind in an old-fashioned loop such as:
> >
> >   for ($i=2; $i<100; $i++)
> >    {print 'yikes!' if ($l[$i]> $l[$i-1]);}
> >
> > is there a way to see other elements of an array in a foreach, as in:
> >
> >   foreach (@l)
> >     {next unless defined $predecessor;
> >      print 'yikes!' if ($_ > $predecessor);}
> 
> Combine them, sort of...
> 
> @::test = (1,2,3,4,5,6,7,8,9);
> foreach (@::test) {$::i++; print "$_ $::i @::test[$::i-1]\n"}
> 
>         /Tony
> --
> the truth is dead, faith is gone, reality killed... ruled by the plastic
> laws of modern life we're pushed towards the hell of personal doubt,
> betrayal, hate, lust and murder... the now has become an illusion, a
> paradise of a dead tomorrow... (c)2000-2001 tony@svanstrom.com


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

Date: Fri, 29 Jun 2001 00:17:25 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: is there a way to look ahead/behind in a foreach (@l)?
Message-Id: <3B3BC919.52F188E3@acm.org>

[please don't top-post]

[please don't quote .sigs]


tuxy wrote:
> 
> Thanks guys good ideas- my question was more general however, I was
> wondering how to look ahead & behind, to say, any value in the array,
> maybe $a[$current location + 20] or whatever. I think that from your
> replies that foreach () isn't such a hot idea in these cases! Best to
> use indices I guess, which I generally avoid.
> 
> However, Tony, your reply sent me scurrying for my Camel (not the
> smoking variety) too look up @:: and $::. What the heck ARE those
> thingies? I've use package names to qualify a var with ::, but I never
> saw them used that way.
> 
> Enlighten me please?

$::i is an abbreviation for $main::i



John
-- 
use Perl;
program
fulfillment


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

Date: 28 Jun 2001 17:42:40 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: New To Perl--Regex Question
Message-Id: <m3puborztr.fsf@dhcp9-173.support.tivoli.com>

On 28 Jun 2001, tommyumuc@aol.com wrote:

> I'm new to Perl, so please forgive this very simple question.  I'm
> trying to figure out what type of regular expression to 'grab'
> several lines of data and push them into an array.  For instance, if
> I have a file that has the following and the pattern I want to find
> is "pattern":
> 
> line 1                   #pattern not found (single line)
> line 2                   #pattern not found (single line)
> line 3  "pattern....     #pattern found     (multiple lines)  
> line 4  ..........."     #the pattern is not on this line, but because
> it
>                           is on the previous line and that line spans
> several
>                           lines, I want all subsequent lines to match
> until
>                           the next pattern for which I am searching is
> found.
> 
> For example, if I'm trying to match the word dog (and include data
> through to the next occurance of where information for dog is not
> found (which would be four lines down, where the 'z' is, in this
> instance):
> 
> 1) xxxxxxxxxxxxxxxxxxxxxxxxxx
> 2) yyyyyyyyyyyyyyyyyyyyyyyyyy
> 3) dog
>    ddddddddd
>    dddddddddd
>    ddddddddddd
> 4) zzzzzzzzzzzzzzzzzzzzzzzzzz
> 
> The data I am trying to match against is separated by line numbers,
> as above, so that should make it easier, but I haven't found a way
> to make it work, as of yet.  Listed below is the code that I have
> created, which almost works.  Any advice anyone could offer would be
> greatly appreciated.  Thank you very much.

Since the data is separated by line numbers, you should process it
that way.  Unfortunately, Perl's $/ variable (input record separator)
cannot hold regexes (have to let AWK win *something*... :) ), so you
have to manually split up the records.

[snipped code preamble]

> open(GOOD,"dps_cluttered.txt") || die "Cannot open new_dps.txt: $!";
> @getdata = <GOOD>;

Since you're already slurping the whole file, let's just split it up
based on those line numbers:

@getdata = split /(?=(?m:^\s*\d+\)))/, join '', <GOOD>;

Now each element of @getdata consists of all the lines corresponding
with a particular number.

> chomp @getdata;
> close ( GOOD );
> 
> foreach $getdata ( @getdata ) {
>    undef $/;

Too late for that to have any effect and you wouldn't have it inside
the loop anyway.

[snipped long if-elsif-else structure that probably needs to be
re-thought and output loop]

-- 
Ren Maddox
ren@tivoli.com


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

Date: Thu, 28 Jun 2001 19:34:52 -0400
From: "Christopher Shannon" <cshannon@data2design.com>
Subject: Re: New To Perl--Regex Question
Message-Id: <9hget5$4ev$1@news.umbc.edu>

Hi!

This is one way to do it.  Also, I suggest you read Perlre, in the perl
documentation.


> For example, if I'm trying to match the word dog (and include data
> through to the next occurance of where information for dog is not
> found (which would be four lines down, where the 'z' is, in this
> instance):
>
> 1) xxxxxxxxxxxxxxxxxxxxxxxxxx
> 2) yyyyyyyyyyyyyyyyyyyyyyyyyy
> 3) dog
>    ddddddddd
>    dddddddddd
>    ddddddddddd
> 4) zzzzzzzzzzzzzzzzzzzzzzzzzz
>

$d = <<'BLAH';
1) xxxxxxxxxxxxxxxxxxxxxxxxxx
2) yyyyyyyyyyyyyyyyyyyyyyyyyy
3) dog
   ddddddddd
   dddddddddd
   ddddddddddd
4) zzzzzzzzzzzzzzzzzzzzzzzzzz
5) xxxxxxxxxxxxxxxxxxxxxxxxxx
6) yyyyyyyyyyyyyyyyyyyyyyyyyy
7) dog
   ddddddddd
   dddddddddd
   ddddddddddd
8) zzzzzzzzzzzzzzzzzzzzzzzzzz

BLAH

$d=~s/(\d+\) dog\n)(.*?)(\d+\))/push @doggy, $2; "$1$2$3"/egs;

for $w (@doggy) {
    print "$w\n#######\n\n";
}

print "Press any key to see your original data";
<STDIN>;

print $d;





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

Date: 28 Jun 2001 16:10:31 -0700
From: mauer@pageweavers.com (Steve)
Subject: Opening files on the Mac? (newbie)
Message-Id: <319bffb5.0106281510.46eace65@posting.google.com>

I have tried every permutation of the following:

require 'StandardFile.pl';  #not sure what this does
open(TEXT,">/Macintosh HD/Applications/PERL/sampledata.txt") || die
"Couldn't open TEXT.\n";

resulting in: "# Couldn't open TEXT."  (file does exist...)

Any input is appreciated.
Steve


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

Date: Thu, 28 Jun 2001 23:57:03 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Opening files on the Mac? (newbie)
Message-Id: <3b3bc399.8665574@news.erols.com>

On 28 Jun 2001 16:10:31 -0700, mauer@pageweavers.com (Steve) wrote:

>I have tried every permutation of the following:
>
>require 'StandardFile.pl';  #not sure what this does
>open(TEXT,">/Macintosh HD/Applications/PERL/sampledata.txt") || die
>"Couldn't open TEXT.\n";
>
>resulting in: "# Couldn't open TEXT."  (file does exist...)

Make it tell you the reason for failure with '$!'.

open(TEXT,">/Macintosh HD/Applications/PERL/sampledata.txt")
  || die "Couldn't open TEXT: $!";
                              ^^
                              ^^


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

Date: Thu, 28 Jun 2001 20:10:05 -0400
From: "Christopher Shannon" <cshannon@data2design.com>
Subject: Re: Perl with MS Access
Message-Id: <9hggv6$8ev$1@news.umbc.edu>

Win32::ODBC or DBD::ODBC on search.cpan.org

"T.H." <tambaa@no.spam.yahoo.com> wrote in message
news:9hfkfm$qo2$1@tilde.csc.ti.com...
> Anyone know of a good web resource with sample Perl scripts on
manipulating
> MS Access databases?
>
> TIA
> T.H.
>
>




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

Date: Thu, 28 Jun 2001 19:15:50 -0400
From: "Christopher Shannon" <cshannon@data2design.com>
Subject: Re: PostgreSQL/Perl error
Message-Id: <9hgdpf$3dt$1@news.umbc.edu>

Lisa,

> Thanks for the input:
> I also get the following error. I can't explain it , ..really.
> Sometime I get the error I posted earlier and other times the
> following error.

Do you mean you got the previous error intermittently?  I would expect that
you would get it consistently if at all.  Regarding the below problems, I
couldn't tell you what they were unless, perhaps, I could see more of the
context in which they occured.  It looks to me like it might be crashing in
mod_perl, in which case you might be facing an Apache configuration problem,
not a Perl problem.

> Had to create DBD::Pg::dr::imp_data_size unexpectedly at
> /source/perl5.005_03/lib/site_perl/5.005/sun4-solaris/DBI.pm line 657.
>
> Use of uninitialized value at
> /source/perl5.005_03/lib/site_perl/5.005/sun4-solaris/DBI.pm line 657.
>
> Had to create DBD::Pg::db::imp_data_size unexpectedly at
> /source/perl5.005_03/lib/site_perl/5.005/sun4-solaris/DBI.pm line 657.
>
> Use of uninitialized value at
> /source/perl5.005_03/lib/site_perl/5.005/sun4-solaris/DBI.pm line 657.
>
> [Thu Jun 28 09:11:14 2001] [error] Undefined subroutine
> &DBD::Pg::db::_login called at
> /source/perl5.005_03/lib/site_perl/5.005/sun4-solaris/DBD/Pg.pm line
> 91.
>
> (in cleanup) Driver has not implemented DESTROY for
> DBI::db=HASH(0x2d2214) at
> /source/perl5.005_03/lib/site_perl/5.005/sun4-solaris/Apache/Registry.pm
> line 144




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

Date: 28 Jun 2001 17:31:01 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Processing command line
Message-Id: <m3u210s0d6.fsf@dhcp9-173.support.tivoli.com>

On Thu, 28 Jun 2001, lhswartw@ichips.intel.com wrote:

> Hi all,
> 
> I'm using GetOpt::Long and want to parse a command switch like:
>>script.pl --host host_1 host_2 host_3 host_n
> 
> Using GetOpt I only get host_1. I can see the other hosts in @ARGV
> but I really need a way to know that they were passed with the
> --host switch.
> 
> Any ideas on how to do this? Keep in mind that the host names can be
> just about anything and are not limited to the host_n format I
> illustrated above.

From "perldoc Getopt::Long":

       Options with multiple values

       Options sometimes take several values. For example, a
       program could use multiple directories to search for
       library files:

           --library lib/stdlib --library lib/extlib
 ...

Another way to get the behavior you want is to just treat the rest of
@ARGV as a list of hosts.  After all, what else could it be with no
way to indicate the end of the list in your desired syntax?  In fact,
you could just treat the --host option as a flag indicating that @ARGV
is a list of hosts.  Then a different option might indicate that @ARGV
is a list of something else.

-- 
Ren Maddox
ren@tivoli.com


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

Date: 28 Jun 2001 16:41:34 -0700
From: Patrick Flaherty <Patrick_member@newsguy.com>
Subject: pull out last line in a text file
Message-Id: <9hgfbe01ehm@drn.newsguy.com>

Hello,

How, in Perl, do I pull out the last line (or lines plural as in tail) of a text
file?

  thanx.

  pat



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

Date: Fri, 29 Jun 2001 00:42:22 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: pull out last line in a text file
Message-Id: <x7sngk86c0.fsf@home.sysarch.com>

>>>>> "PF" == Patrick Flaherty <Patrick_member@newsguy.com> writes:

  PF> How, in Perl, do I pull out the last line (or lines plural as in
  PF> tail) of a text file?

use File::ReadBackwards ;

available on your local CPAN mirror

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html


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

Date: 28 Jun 2001 19:54:57 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: pull out last line in a text file
Message-Id: <9hgjl1$kqs$1@charity.cs.utexas.edu>

In article <9hgfbe01ehm@drn.newsguy.com>,
Patrick Flaherty  <Patrick_member@newsguy.com> wrote:
>How, in Perl, do I pull out the last line (or lines plural as in tail) of a text
>file?

Here's the quick and dirty way:

	# read the file
	@lines = <>;

	$howmany = 2;

	print @lines[-$howmany .. -1];

Hope that helps.

  - Logan
-- 
my  your   his  her   our   their   _its_
I'm you're he's she's we're they're _it's_


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

Date: Thu, 28 Jun 2001 22:17:52 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: reading the first line off the file
Message-Id: <t8bnjtglok4c54kmrrfkkgtlo4ht9anpme@4ax.com>

Matthew Zhang da LBNL wrote:

>>   if ( defined $subject = <FILE> ) {
>>       chomp $subject;
>>       ...
>
>the if line gives me the following error:
>"can't modify defined operator in scalar assignment at automail line 15, near
>"<FILE>"
>Execution of automail aborted due to compilation errors.

Add parens.

	if ( defined($subject = <FILE>)) {


I wish that Perl's precedence rules were a little smarter.

-- 
	Bart.


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

Date: 29 Jun 2001 00:17:39 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Scanning a file in CGI
Message-Id: <9hghf3$lkc$1@bob.news.rcn.net>

Danny Hendrickx <daniel.hendrickx@alcatel.be> wrote:
> This time I took your advice and ran the program without CGI and it
> worked. However, under CGI it doesn't. What I'm seeing is that the
> s1ccou.txt file never gets updated (or only once the first time) and
> that the s1docs.txt never gets appended to.

> Here's the program: 

> #!/usr/local/bin/perl -w

> use strict;

> use CGI qw(:standard);

> my (
>     $TITLE,
>     $HEADER,
>     %arealist,
>     $curcount
>    );

> $TITLE = "SS31 Document Overview";
> $HEADER = "Add a document";

> print header(),start_html($TITLE),h1($HEADER);

> my $action = param("action");
> my $docnr = param("docnr");
> my $doctitle = param("doctitle");
> my $docarea = param("docarea");
> my $doclink = param("doclink");
> my $keyword = param("keyword");

> if (param())
>   {
>    if ($doctitle && $docnr && $docarea && $doclink)
>      {
>       my $doctitle=param("doctitle");
>       my $docnr=param("docnr");
>       my $docarea=param("docarea");

Your sequencing here is a bit strange.  First you assign a bunch of 
variables with param(), *then* you check to see if there are actually any 
parameters, and then you declare a new set of variables and re-assign them 
with param(), whose return values aren't going to have changed.

>       open (I,"<s1ccou.txt")||die "Cannot open counter file for
> reading:$!";
>       $curcount=<I>;
>       $curcount++;
>       close I;

You're using relative file names here.  I suspect that your Web server 
isn't setting your working directory to what you think it is.  Either use 
absolute path names, or chdir() into a known directory first.

>       open (O,">>s1docs.txt")||die "Cannot open docs file for
> adding:$!";
>       print O
> $curcount,"|",$docarea,"|",$doctitle,"|",$docnr,"|",$doclink,"|NO\n";
>       close O;

>       open (O,">s1ccou.txt")||bail("Cannot open counter file for
> writing:$!");
>       print O $curcount;
>       close O;

In actual production use, you'd need to open the counter file for
read/write, lock it, read it, seek to the beginning, truncate it, and then
write it.  As things stand, if two or more people were accessing the
script at the same time, the counter could get trashed (for example, if
another copy of the script were to read the counter file in between the
open() and the close() above, it would be reading from an empty file, with
the result that your counter would either be reset to 1 (if the first copy
finished before the second) or would be one less than it should be (if the
second copy finished first).


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

Date: 28 Jun 2001 17:26:22 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Split without delimiter?
Message-Id: <m3y9qcs0kx.fsf@dhcp9-173.support.tivoli.com>

On Thu, 28 Jun 2001, EvR@compuserve.com wrote:

> I suggest that you use
> 
> $string = "abcdefghijklmnopqrstuvwxyzABCDEFGHI";
> @chunks = $string =~ /.{1,8}/g;
> print join "\n", @chunks;
> 
> The difference between this approach and the others given is that it
> deals with the 'leftover' characters.  That is, if the string length
> is not evenly divisible by 8, the remaining chunk is saved in the
> final element of the array.  The output of the script above is:
[snipped]

Yes, that seems to trip me up every time... :(

-- 
Ren Maddox
ren@tivoli.com


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

Date: Thu, 28 Jun 2001 23:52:17 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Split without delimiter?
Message-Id: <pcgnjt0oh7hfhlvnv8vpnkblp9hv7p45qv@4ax.com>

Johan M. Andersen wrote:

>for($_=shift;$token=substr($_,$offset,8);$offset+=8) {
>	# blah blah blah
>}
>
>Is there a better way to do this?

	@parts = unpack "a8" x ((length()+7)/8), $_;

If you're sure the string is a multiple of 8 bytes, the unpack template
can be reduced to

	@parts = unpack "a8" x (length()/8), $_;

or, if you don't mind a last item of length 0:

	@parts = unpack "a8" x (length()/8+1), $_;

-- 
	Bart.


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

Date: Fri, 29 Jun 2001 01:45:36 +0200
From: Patrick Erler <perler@yahoo.com>
Subject: turbo perl
Message-Id: <Xns90CF11E574D02fuyyehcesyrdx@62.153.159.134>

hello!

ok, the subject's not fair. it rings a bell in everyone who's into 
programming longer then 6, 7 years..

the question i'm going to ask sounds like troll and "flame him", but, after 
i gave a friend here in the house where i live an old free version of 
borlands turbo c (he wants to learn c, not perl..) i remembered the days i 
learned pascal...

i had dos, i had turbo pascal 5.0 and when i didn't know the syntax of a 
command i pressed ctrl-F1 and got it explained (often not detailed enough, 
ok...)

now, when i sit in front of vi or the built-in editor in midnight commander 
to hack a little script in perl, and i realise that i again forgot about 
*put your favorite weakness in here* i launch deja or grab a book - the 
young man, one floor above me, is pressing ctrl-f1. in his dos box. in his 
IDE (we called it just editor in these times) which is 8 years old.

why can't i?!

my 2 pfennigs...

-- 
PAT


vcard/LDAP/PGP: http://dresden-online.com/perler/identity.html
PGP fingerprint: DAC6 2FDA 1ED7 AD55  BD1F 5142 3D5F 72BF
Yahoo-ID: perler - http://jpager.yahoo.com/jpager/messenger.html


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

Date: Fri, 29 Jun 2001 00:02:37 GMT
From: "Daniel Berger" <djberg96@hotmail.com>
Subject: Re: turbo perl
Message-Id: <xAP_6.110$y76.46666@typhoon.mn.mediaone.net>

 > why can't i?!
>
> my 2 pfennigs...
>
> --
> PAT
>
Ah, but that's a feature brought to you by Borland, not the creators of C,
C++ or Pascal (or the language itself).  Perl IDE's have been slow to come
along but they are here and/or on their way.  See Perlbuilder
(www.solutionsoft.com) or Komodo (www.activestate.com) for Perl IDE with
built-in debuggers.  For a pretty good editor that has really good built-in
help (but no debugger) see Visual SlickEdit (www.slickedit.com).  For a
pretty decent "do-all" editor see CodeMagic (www.codemagiccd.com).  These
are generally available on multiple platforms as well.

For really good online documentation that should allow you to avoid picking
up a book much of the time, take a look at the activestate documentation
that comes with their Perl distribution.  There's also a link to it off
their web site somewhere if you don't want their Perl distro, but just want
the docs.  Or you can do what I do when I'm on my Solaris box -- keep a
browswer open at all times to search.cpan.org.

Now stop whining and write some Perl code.

Regards,

Dan







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

Date: Fri, 29 Jun 2001 02:17:03 +0200
From: Buggs <buggs-clpm@splashground.de>
Subject: Re: turbo perl
Message-Id: <9hgh63$ipu$05$1@news.t-online.com>

Patrick Erler wrote:

> i had dos, i had turbo pascal 5.0 and when i didn't know the syntax of a
> command i pressed ctrl-F1 and got it explained (often not detailed enough,
> ok...)
>
> now, when i sit in front of vi or the built-in editor in midnight
> commander to hack a little script in perl, and i realise that i again
> forgot about *put your favorite weakness in here* i launch deja or grab a
> book - the young man, one floor above me, is pressing ctrl-f1. in his dos
> box. in his IDE (we called it just editor in these times) which is 8 years
> old.

s/raider/twix/ && s/deja/google/;
We live in the 21st century you know ...

> why can't i?!

Dunno, why you can't hack your .vimrc
to map ctrl-f1 to perldoc -f print ...


Buggs


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

Date: Fri, 29 Jun 2001 02:21:00 +0200
From: Patrick Erler <perler@yahoo.com>
Subject: Re: turbo perl
Message-Id: <Xns90CF17E644D53fuyyehcesyrdx@62.153.159.134>

"Daniel Berger" <djberg96@hotmail.com> wrote in
news:xAP_6.110$y76.46666@typhoon.mn.mediaone.net: 

> > why can't i?!
>>
>> my 2 pfennigs...
>>
>> --
>> PAT
>>
> Ah, but that's a feature brought to you by Borland, not the creators of
> C, C++ or Pascal (or the language itself).
absolutely..

>  Perl IDE's have been slow
> to come along but they are here

absolutely ;)

> Now stop whining and write some Perl code.
no no no, not so easy...

unfortunately you deleted the most important line in my posting:

"now, when i sit in front of vi or the built-in editor in midnight 
commander to hack a little script in perl..."

the guy one floor above me in front of his /text mode/ turbo-c has a very 
handy online help system at his fingertips. /that's/ what i miss.

no gnome/kde/windows BIG help system, but just a shortcut from my text mode 
editor to the help files. that's what made it extremely easy for me to 
lern, in these days, no flames please, pascal. ;)

i could actually learn the language by trial and error - and that's the 
absolutely best way to learn the basics of a language - and the system 
supported me. 

right now, when i'm not sure about the syntax of a perl function i print 
out variables, read books, read deja...

for me it's no big problem, because i know, in the end i get the problem 
solved with perl, but i imagine the beginner, what could he accomplish in a 
fraction of the time he needs now without a helpful and well thought trough 
IDE.

and i didn't even mention that debugger in turbo-c/pascal ;)

regards,

-- 
PAT


vcard/LDAP/PGP: http://dresden-online.com/perler/identity.html
PGP fingerprint: DAC6 2FDA 1ED7 AD55  BD1F 5142 3D5F 72BF
Yahoo-ID: perler - http://jpager.yahoo.com/jpager/messenger.html


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

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.  

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


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